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