1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Contains holistic tests of the bindings infrastructure
7 #include "chrome/browser/extensions/api/permissions/permissions_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/net/url_request_mock_util.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/test/browser_test_utils.h"
13 #include "extensions/browser/extension_host.h"
14 #include "extensions/browser/process_manager.h"
15 #include "extensions/test/extension_test_message_listener.h"
16 #include "extensions/test/result_catcher.h"
18 namespace extensions
{
21 class ExtensionBindingsApiTest
: public ExtensionApiTest
{
23 void SetUpOnMainThread() override
{
24 content::BrowserThread::PostTask(
25 content::BrowserThread::IO
, FROM_HERE
,
26 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled
, true));
30 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest
,
31 UnavailableBindingsNeverRegistered
) {
32 // Test will request the 'storage' permission.
33 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
34 ASSERT_TRUE(RunExtensionTest(
35 "bindings/unavailable_bindings_never_registered")) << message_
;
38 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest
,
39 ExceptionInHandlerShouldNotCrash
) {
40 ASSERT_TRUE(RunExtensionSubtest(
41 "bindings/exception_in_handler_should_not_crash",
42 "page.html")) << message_
;
45 // Tests that an error raised during an async function still fires
46 // the callback, but sets chrome.runtime.lastError.
47 // FIXME should be in ExtensionBindingsApiTest.
48 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest
, LastError
) {
49 ASSERT_TRUE(LoadExtension(
50 test_data_dir_
.AppendASCII("browsertest").AppendASCII("last_error")));
52 // Get the ExtensionHost that is hosting our background page.
53 extensions::ProcessManager
* manager
=
54 extensions::ProcessManager::Get(browser()->profile());
55 extensions::ExtensionHost
* host
= FindHostWithPath(manager
, "/bg.html", 1);
58 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
59 host
->render_view_host(), "testLastError()", &result
));
63 // Regression test that we don't delete our own bindings with about:blank
65 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest
, AboutBlankIframe
) {
66 ResultCatcher catcher
;
67 ExtensionTestMessageListener
listener("load", true);
69 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("bindings")
70 .AppendASCII("about_blank_iframe")));
72 ASSERT_TRUE(listener
.WaitUntilSatisfied());
74 const Extension
* extension
= LoadExtension(
75 test_data_dir_
.AppendASCII("bindings")
76 .AppendASCII("internal_apis_not_on_chrome_object"));
77 ASSERT_TRUE(extension
);
78 listener
.Reply(extension
->id());
80 ASSERT_TRUE(catcher
.GetNextResult()) << message_
;
83 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest
,
84 InternalAPIsNotOnChromeObject
) {
85 ASSERT_TRUE(RunExtensionSubtest(
86 "bindings/internal_apis_not_on_chrome_object",
87 "page.html")) << message_
;
90 // Tests that we don't override events when bindings are re-injected.
91 // Regression test for http://crbug.com/269149.
92 // Regression test for http://crbug.com/436593.
93 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest
, EventOverriding
) {
94 ASSERT_TRUE(RunExtensionTest("bindings/event_overriding")) << message_
;
97 // Tests the effectiveness of the 'nocompile' feature file property.
98 // Regression test for http://crbug.com/356133.
99 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest
, Nocompile
) {
100 ASSERT_TRUE(RunExtensionSubtest("bindings/nocompile", "page.html"))
104 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest
, ApiEnums
) {
105 ASSERT_TRUE(RunExtensionTest("bindings/api_enums")) << message_
;
108 // Regression test for http://crbug.com/504011 - proper access checks on
109 // getModuleSystem().
110 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest
, ModuleSystem
) {
111 ASSERT_TRUE(RunExtensionTest("bindings/module_system")) << message_
;
115 } // namespace extensions