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. 4 5 // Contains holistic tests of the bindings infrastructure 6 7 #include "chrome/browser/extensions/extension_apitest.h" 8 9 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_process_manager.h" 11 #include "chrome/browser/extensions/extension_system.h" 12 #include "chrome/browser/extensions/extension_test_message_listener.h" 13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/test/base/ui_test_utils.h" 15 #include "content/public/test/browser_test_utils.h" 16 17 namespace extensions { 18 namespace { 19 20 class ExtensionBindingsApiTest : public ExtensionApiTest {}; 21 22 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, 23 ExceptionInHandlerShouldNotCrash) { 24 ASSERT_TRUE(RunExtensionSubtest( 25 "bindings/exception_in_handler_should_not_crash", 26 "page.html")) << message_; 27 } 28 29 // Tests that an error raised during an async function still fires 30 // the callback, but sets chrome.runtime.lastError. 31 // FIXME should be in ExtensionBindingsApiTest. 32 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) { 33 ASSERT_TRUE(LoadExtension( 34 test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error"))); 35 36 // Get the ExtensionHost that is hosting our background page. 37 ExtensionProcessManager* manager = 38 extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); 39 extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1); 40 41 bool result = false; 42 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 43 host->render_view_host(), "testLastError()", &result)); 44 EXPECT_TRUE(result); 45 } 46 47 // Regression test that we don't delete our own bindings with about:blank 48 // iframes. 49 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, AboutBlankIframe) { 50 ResultCatcher catcher; 51 ExtensionTestMessageListener listener("load", true); 52 53 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bindings") 54 .AppendASCII("about_blank_iframe"))); 55 56 ASSERT_TRUE(listener.WaitUntilSatisfied()); 57 58 const Extension* extension = LoadExtension( 59 test_data_dir_.AppendASCII("bindings") 60 .AppendASCII("internal_apis_not_on_chrome_object")); 61 ASSERT_TRUE(extension); 62 listener.Reply(extension->id()); 63 64 ASSERT_TRUE(catcher.GetNextResult()) << message_; 65 } 66 67 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, 68 InternalAPIsNotOnChromeObject) { 69 ASSERT_TRUE(RunExtensionSubtest( 70 "bindings/internal_apis_not_on_chrome_object", 71 "page.html")) << message_; 72 } 73 74 // Tests that we don't override events when bindings are re-injected. 75 // Regression test for http://crbug.com/269149. 76 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, EventOverriding) { 77 ASSERT_TRUE(RunExtensionTest("bindings/event_overriding")) << message_; 78 } 79 80 } // namespace 81 } // namespace extensions 82