[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 | |
[email protected] | 7eef394 | 2013-08-14 02:53:49 | [diff] [blame] | 7 | #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
[email protected] | c80b8ee | 2011-12-03 04:26:52 | [diff] [blame] | 8 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser.h" |
| 13 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 14 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame^] | 15 | #include "extensions/browser/process_manager.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, |
[email protected] | 7eef394 | 2013-08-14 02:53:49 | [diff] [blame] | 23 | UnavailableBindingsNeverRegistered) { |
| 24 | // Test will request the 'storage' permission. |
| 25 | PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 26 | ASSERT_TRUE(RunExtensionTest( |
| 27 | "bindings/unavailable_bindings_never_registered")) << message_; |
| 28 | } |
| 29 | |
| 30 | IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 31 | ExceptionInHandlerShouldNotCrash) { |
[email protected] | c80b8ee | 2011-12-03 04:26:52 | [diff] [blame] | 32 | ASSERT_TRUE(RunExtensionSubtest( |
| 33 | "bindings/exception_in_handler_should_not_crash", |
| 34 | "page.html")) << message_; |
| 35 | } |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 36 | |
| 37 | // Tests that an error raised during an async function still fires |
[email protected] | 754ea8b7 | 2013-01-08 15:10:31 | [diff] [blame] | 38 | // the callback, but sets chrome.runtime.lastError. |
[email protected] | fc03448 | 2013-08-09 20:25:14 | [diff] [blame] | 39 | // FIXME should be in ExtensionBindingsApiTest. |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 40 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, LastError) { |
| 41 | ASSERT_TRUE(LoadExtension( |
| 42 | test_data_dir_.AppendASCII("browsertest").AppendASCII("last_error"))); |
| 43 | |
| 44 | // Get the ExtensionHost that is hosting our background page. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame^] | 45 | extensions::ProcessManager* manager = |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 46 | extensions::ExtensionSystem::Get(browser()->profile())->process_manager(); |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 47 | extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 48 | |
| 49 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 50 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 51 | host->render_view_host(), "testLastError()", &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 52 | EXPECT_TRUE(result); |
| 53 | } |
[email protected] | 52eafbd | 2013-04-03 04:43:19 | [diff] [blame] | 54 | |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 55 | // Regression test that we don't delete our own bindings with about:blank |
| 56 | // iframes. |
| 57 | IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, AboutBlankIframe) { |
| 58 | ResultCatcher catcher; |
| 59 | ExtensionTestMessageListener listener("load", true); |
| 60 | |
| 61 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bindings") |
| 62 | .AppendASCII("about_blank_iframe"))); |
| 63 | |
| 64 | ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 65 | |
| 66 | const Extension* extension = LoadExtension( |
| 67 | test_data_dir_.AppendASCII("bindings") |
| 68 | .AppendASCII("internal_apis_not_on_chrome_object")); |
| 69 | ASSERT_TRUE(extension); |
| 70 | listener.Reply(extension->id()); |
| 71 | |
| 72 | ASSERT_TRUE(catcher.GetNextResult()) << message_; |
| 73 | } |
| 74 | |
| 75 | IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, |
| 76 | InternalAPIsNotOnChromeObject) { |
[email protected] | 52eafbd | 2013-04-03 04:43:19 | [diff] [blame] | 77 | ASSERT_TRUE(RunExtensionSubtest( |
| 78 | "bindings/internal_apis_not_on_chrome_object", |
| 79 | "page.html")) << message_; |
| 80 | } |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 81 | |
[email protected] | fc03448 | 2013-08-09 20:25:14 | [diff] [blame] | 82 | // Tests that we don't override events when bindings are re-injected. |
| 83 | // Regression test for http://crbug.com/269149. |
| 84 | IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, EventOverriding) { |
| 85 | ASSERT_TRUE(RunExtensionTest("bindings/event_overriding")) << message_; |
| 86 | } |
| 87 | |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 88 | } // namespace |
| 89 | } // namespace extensions |