blob: 2d904a2add722c0d56c99181607189bb6a4ec00d [file] [log] [blame]
[email protected]fad73672012-06-15 23:26:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c80b8ee2011-12-03 04:26:522// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Contains holistic tests of the bindings infrastructure
6
7#include "chrome/browser/extensions/extension_apitest.h"
8
[email protected]fad73672012-06-15 23:26:069#include "chrome/browser/extensions/extension_host.h"
10#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]be93bba02012-10-24 16:44:0311#include "chrome/browser/extensions/extension_system.h"
[email protected]adafe5b2013-08-09 10:35:0412#include "chrome/browser/extensions/extension_test_message_listener.h"
[email protected]fad73672012-06-15 23:26:0613#include "chrome/browser/ui/browser.h"
14#include "chrome/test/base/ui_test_utils.h"
[email protected]7d478cb2012-07-24 17:19:4215#include "content/public/test/browser_test_utils.h"
[email protected]fad73672012-06-15 23:26:0616
[email protected]adafe5b2013-08-09 10:35:0417namespace extensions {
18namespace {
19
20class ExtensionBindingsApiTest : public ExtensionApiTest {};
21
22IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
23 ExceptionInHandlerShouldNotCrash) {
[email protected]c80b8ee2011-12-03 04:26:5224 ASSERT_TRUE(RunExtensionSubtest(
25 "bindings/exception_in_handler_should_not_crash",
26 "page.html")) << message_;
27}
[email protected]fad73672012-06-15 23:26:0628
29// Tests that an error raised during an async function still fires
[email protected]754ea8b72013-01-08 15:10:3130// the callback, but sets chrome.runtime.lastError.
[email protected]fad73672012-06-15 23:26:0631IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) {
32 ASSERT_TRUE(LoadExtension(
33 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error")));
34
35 // Get the ExtensionHost that is hosting our background page.
36 ExtensionProcessManager* manager =
[email protected]be93bba02012-10-24 16:44:0337 extensions::ExtensionSystem::Get(browser()->profile())->process_manager();
[email protected]3a1dc572012-07-31 22:25:1338 extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1);
[email protected]fad73672012-06-15 23:26:0639
40 bool result = false;
[email protected]b6987e02013-01-04 18:30:4341 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
42 host->render_view_host(), "testLastError()", &result));
[email protected]fad73672012-06-15 23:26:0643 EXPECT_TRUE(result);
44}
[email protected]52eafbd2013-04-03 04:43:1945
[email protected]adafe5b2013-08-09 10:35:0446// Regression test that we don't delete our own bindings with about:blank
47// iframes.
48IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, AboutBlankIframe) {
49 ResultCatcher catcher;
50 ExtensionTestMessageListener listener("load", true);
51
52 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bindings")
53 .AppendASCII("about_blank_iframe")));
54
55 ASSERT_TRUE(listener.WaitUntilSatisfied());
56
57 const Extension* extension = LoadExtension(
58 test_data_dir_.AppendASCII("bindings")
59 .AppendASCII("internal_apis_not_on_chrome_object"));
60 ASSERT_TRUE(extension);
61 listener.Reply(extension->id());
62
63 ASSERT_TRUE(catcher.GetNextResult()) << message_;
64}
65
66IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest,
67 InternalAPIsNotOnChromeObject) {
[email protected]52eafbd2013-04-03 04:43:1968 ASSERT_TRUE(RunExtensionSubtest(
69 "bindings/internal_apis_not_on_chrome_object",
70 "page.html")) << message_;
71}
[email protected]adafe5b2013-08-09 10:35:0472
73} // namespace
74} // namespace extensions