[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c80b8ee | 2011-12-03 04:26:52 | [diff] [blame] | 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 | |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_host.h" |
| 10 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame^] | 12 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser.h" |
| 14 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 15 | #include "content/public/test/browser_test_utils.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 16 | |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame^] | 17 | namespace extensions { |
| 18 | namespace { |
| 19 | |
| 20 | class ExtensionBindingsApiTest : public ExtensionApiTest {}; |
| 21 | |
| 22 | IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, |
| 23 | ExceptionInHandlerShouldNotCrash) { |
[email protected] | c80b8ee | 2011-12-03 04:26:52 | [diff] [blame] | 24 | ASSERT_TRUE(RunExtensionSubtest( |
| 25 | "bindings/exception_in_handler_should_not_crash", |
| 26 | "page.html")) << message_; |
| 27 | } |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 28 | |
| 29 | // Tests that an error raised during an async function still fires |
[email protected] | 754ea8b7 | 2013-01-08 15:10:31 | [diff] [blame] | 30 | // the callback, but sets chrome.runtime.lastError. |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 31 | IN_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] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 37 | extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 38 | extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 39 | |
| 40 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 41 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 42 | host->render_view_host(), "testLastError()", &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 43 | EXPECT_TRUE(result); |
| 44 | } |
[email protected] | 52eafbd | 2013-04-03 04:43:19 | [diff] [blame] | 45 | |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame^] | 46 | // Regression test that we don't delete our own bindings with about:blank |
| 47 | // iframes. |
| 48 | IN_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 | |
| 66 | IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, |
| 67 | InternalAPIsNotOnChromeObject) { |
[email protected] | 52eafbd | 2013-04-03 04:43:19 | [diff] [blame] | 68 | ASSERT_TRUE(RunExtensionSubtest( |
| 69 | "bindings/internal_apis_not_on_chrome_object", |
| 70 | "page.html")) << message_; |
| 71 | } |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame^] | 72 | |
| 73 | } // namespace |
| 74 | } // namespace extensions |