[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 | |
Gabriel Charette | 078e366 | 2017-08-28 22:59:04 | [diff] [blame] | 7 | #include "base/run_loop.h" |
Devlin Cronin | a3fe3d60 | 2017-11-22 04:47:43 | [diff] [blame] | 8 | #include "base/test/scoped_feature_list.h" |
[email protected] | 7eef394 | 2013-08-14 02:53:49 | [diff] [blame] | 9 | #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
[email protected] | c80b8ee | 2011-12-03 04:26:52 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_apitest.h" |
jochen | 7923c2a | 2015-07-14 10:04:45 | [diff] [blame] | 11 | #include "chrome/browser/net/url_request_mock_util.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser.h" |
rdevlin.cronin | 83a4b3a | 2015-10-28 21:43:58 | [diff] [blame] | 13 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
asargent | 79b64c3 | 2016-08-04 17:17:14 | [diff] [blame] | 14 | #include "chrome/common/chrome_switches.h" |
rdevlin.cronin | 83a4b3a | 2015-10-28 21:43:58 | [diff] [blame] | 15 | #include "chrome/test/base/ui_test_utils.h" |
jochen | 7923c2a | 2015-07-14 10:04:45 | [diff] [blame] | 16 | #include "content/public/browser/browser_thread.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 17 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 18 | #include "extensions/browser/extension_host.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 19 | #include "extensions/browser/process_manager.h" |
Devlin Cronin | a3fe3d60 | 2017-11-22 04:47:43 | [diff] [blame] | 20 | #include "extensions/common/extension_features.h" |
lfg | 910f2f9 | 2014-09-19 05:31:09 | [diff] [blame] | 21 | #include "extensions/test/extension_test_message_listener.h" |
yoz | e8dc2f1 | 2014-09-09 23:16:32 | [diff] [blame] | 22 | #include "extensions/test/result_catcher.h" |
rdevlin.cronin | e6e2002 | 2017-06-13 18:23:40 | [diff] [blame] | 23 | #include "net/dns/mock_host_resolver.h" |
rdevlin.cronin | 83a4b3a | 2015-10-28 21:43:58 | [diff] [blame] | 24 | #include "net/test/embedded_test_server/embedded_test_server.h" |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 25 | |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 26 | namespace extensions { |
| 27 | namespace { |
| 28 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 29 | enum BindingsType { NATIVE_BINDINGS, JAVASCRIPT_BINDINGS }; |
| 30 | |
| 31 | class ExtensionBindingsApiTest |
| 32 | : public ExtensionApiTest, |
| 33 | public ::testing::WithParamInterface<BindingsType> { |
jochen | 7923c2a | 2015-07-14 10:04:45 | [diff] [blame] | 34 | public: |
Devlin Cronin | a3fe3d60 | 2017-11-22 04:47:43 | [diff] [blame] | 35 | ExtensionBindingsApiTest() {} |
| 36 | ~ExtensionBindingsApiTest() override {} |
| 37 | |
| 38 | void SetUp() override { |
| 39 | if (GetParam() == NATIVE_BINDINGS) { |
| 40 | scoped_feature_list_.InitAndEnableFeature(features::kNativeCrxBindings); |
| 41 | } else { |
| 42 | DCHECK_EQ(JAVASCRIPT_BINDINGS, GetParam()); |
| 43 | scoped_feature_list_.InitAndDisableFeature(features::kNativeCrxBindings); |
| 44 | } |
| 45 | ExtensionApiTest::SetUp(); |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 46 | } |
| 47 | |
jochen | 7923c2a | 2015-07-14 10:04:45 | [diff] [blame] | 48 | void SetUpOnMainThread() override { |
rdevlin.cronin | 17160cc6 | 2016-11-23 05:33:08 | [diff] [blame] | 49 | ExtensionApiTest::SetUpOnMainThread(); |
rdevlin.cronin | e6e2002 | 2017-06-13 18:23:40 | [diff] [blame] | 50 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 51 | ASSERT_TRUE(StartEmbeddedTestServer()); |
jochen | 7923c2a | 2015-07-14 10:04:45 | [diff] [blame] | 52 | } |
Devlin Cronin | a3fe3d60 | 2017-11-22 04:47:43 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | base::test::ScopedFeatureList scoped_feature_list_; |
| 56 | |
| 57 | DISALLOW_COPY_AND_ASSIGN(ExtensionBindingsApiTest); |
jochen | 7923c2a | 2015-07-14 10:04:45 | [diff] [blame] | 58 | }; |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 59 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 60 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, |
[email protected] | 7eef394 | 2013-08-14 02:53:49 | [diff] [blame] | 61 | UnavailableBindingsNeverRegistered) { |
| 62 | // Test will request the 'storage' permission. |
| 63 | PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 64 | ASSERT_TRUE(RunExtensionTest( |
| 65 | "bindings/unavailable_bindings_never_registered")) << message_; |
| 66 | } |
| 67 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 68 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 69 | ExceptionInHandlerShouldNotCrash) { |
[email protected] | c80b8ee | 2011-12-03 04:26:52 | [diff] [blame] | 70 | ASSERT_TRUE(RunExtensionSubtest( |
| 71 | "bindings/exception_in_handler_should_not_crash", |
| 72 | "page.html")) << message_; |
| 73 | } |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 74 | |
| 75 | // Tests that an error raised during an async function still fires |
[email protected] | 754ea8b7 | 2013-01-08 15:10:31 | [diff] [blame] | 76 | // the callback, but sets chrome.runtime.lastError. |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 77 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, LastError) { |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 78 | ASSERT_TRUE(LoadExtension( |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 79 | test_data_dir_.AppendASCII("bindings").AppendASCII("last_error"))); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 80 | |
| 81 | // Get the ExtensionHost that is hosting our background page. |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 82 | extensions::ProcessManager* manager = |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 83 | extensions::ProcessManager::Get(browser()->profile()); |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 84 | extensions::ExtensionHost* host = FindHostWithPath(manager, "/bg.html", 1); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 85 | |
| 86 | bool result = false; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 87 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 88 | host->render_view_host(), "testLastError()", &result)); |
[email protected] | fad7367 | 2012-06-15 23:26:06 | [diff] [blame] | 89 | EXPECT_TRUE(result); |
| 90 | } |
[email protected] | 52eafbd | 2013-04-03 04:43:19 | [diff] [blame] | 91 | |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 92 | // Regression test that we don't delete our own bindings with about:blank |
| 93 | // iframes. |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 94 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, AboutBlankIframe) { |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 95 | ResultCatcher catcher; |
| 96 | ExtensionTestMessageListener listener("load", true); |
| 97 | |
| 98 | ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bindings") |
| 99 | .AppendASCII("about_blank_iframe"))); |
| 100 | |
| 101 | ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 102 | |
| 103 | const Extension* extension = LoadExtension( |
| 104 | test_data_dir_.AppendASCII("bindings") |
| 105 | .AppendASCII("internal_apis_not_on_chrome_object")); |
| 106 | ASSERT_TRUE(extension); |
| 107 | listener.Reply(extension->id()); |
| 108 | |
| 109 | ASSERT_TRUE(catcher.GetNextResult()) << message_; |
| 110 | } |
| 111 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 112 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 113 | InternalAPIsNotOnChromeObject) { |
[email protected] | 52eafbd | 2013-04-03 04:43:19 | [diff] [blame] | 114 | ASSERT_TRUE(RunExtensionSubtest( |
| 115 | "bindings/internal_apis_not_on_chrome_object", |
| 116 | "page.html")) << message_; |
| 117 | } |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 118 | |
[email protected] | fc03448 | 2013-08-09 20:25:14 | [diff] [blame] | 119 | // Tests that we don't override events when bindings are re-injected. |
| 120 | // Regression test for http://crbug.com/269149. |
rpaquay | 96bf3b7d | 2014-11-26 00:19:08 | [diff] [blame] | 121 | // Regression test for http://crbug.com/436593. |
Henrik Grunell | 6b7d9db | 2017-06-14 10:27:20 | [diff] [blame] | 122 | // Flaky on Mac. http://crbug.com/733064. |
Giovanni Ortuño Urquidi | 7ce21545 | 2017-06-14 03:34:08 | [diff] [blame] | 123 | #if defined(OS_MACOSX) |
| 124 | #define MAYBE_EventOverriding DISABLED_EventOverriding |
| 125 | #else |
| 126 | #define MAYBE_EventOverriding EventOverriding |
| 127 | #endif |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 128 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, MAYBE_EventOverriding) { |
[email protected] | fc03448 | 2013-08-09 20:25:14 | [diff] [blame] | 129 | ASSERT_TRUE(RunExtensionTest("bindings/event_overriding")) << message_; |
rdevlin.cronin | d734f68 | 2017-06-13 21:23:11 | [diff] [blame] | 130 | // The extension test removes a window and, during window removal, sends the |
| 131 | // success message. Make sure we flush all pending tasks. |
| 132 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc03448 | 2013-08-09 20:25:14 | [diff] [blame] | 133 | } |
| 134 | |
kalman | 1bd5b18 | 2015-01-13 19:01:18 | [diff] [blame] | 135 | // Tests the effectiveness of the 'nocompile' feature file property. |
| 136 | // Regression test for http://crbug.com/356133. |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 137 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, Nocompile) { |
kalman | 1bd5b18 | 2015-01-13 19:01:18 | [diff] [blame] | 138 | ASSERT_TRUE(RunExtensionSubtest("bindings/nocompile", "page.html")) |
| 139 | << message_; |
| 140 | } |
| 141 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 142 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, ApiEnums) { |
rdevlin.cronin | 2ba3c88d | 2015-03-03 01:18:22 | [diff] [blame] | 143 | ASSERT_TRUE(RunExtensionTest("bindings/api_enums")) << message_; |
| 144 | }; |
| 145 | |
jochen | 7923c2a | 2015-07-14 10:04:45 | [diff] [blame] | 146 | // Regression test for http://crbug.com/504011 - proper access checks on |
| 147 | // getModuleSystem(). |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 148 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, ModuleSystem) { |
jochen | 7923c2a | 2015-07-14 10:04:45 | [diff] [blame] | 149 | ASSERT_TRUE(RunExtensionTest("bindings/module_system")) << message_; |
| 150 | } |
| 151 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 152 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, NoExportOverriding) { |
rdevlin.cronin | 83a4b3a | 2015-10-28 21:43:58 | [diff] [blame] | 153 | // We need to create runtime bindings in the web page. An extension that's |
| 154 | // externally connectable will do that for us. |
| 155 | ASSERT_TRUE(LoadExtension( |
| 156 | test_data_dir_.AppendASCII("bindings") |
| 157 | .AppendASCII("externally_connectable_everywhere"))); |
| 158 | |
| 159 | ui_test_utils::NavigateToURL( |
| 160 | browser(), |
| 161 | embedded_test_server()->GetURL( |
| 162 | "/extensions/api_test/bindings/override_exports.html")); |
| 163 | |
| 164 | // See chrome/test/data/extensions/api_test/bindings/override_exports.html. |
| 165 | std::string result; |
| 166 | EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 167 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 168 | "window.domAutomationController.send(" |
| 169 | "document.getElementById('status').textContent.trim());", |
| 170 | &result)); |
| 171 | EXPECT_EQ("success", result); |
| 172 | } |
| 173 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 174 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, NoGinDefineOverriding) { |
rdevlin.cronin | 415b73b | 2015-11-13 01:14:47 | [diff] [blame] | 175 | // We need to create runtime bindings in the web page. An extension that's |
| 176 | // externally connectable will do that for us. |
| 177 | ASSERT_TRUE(LoadExtension( |
| 178 | test_data_dir_.AppendASCII("bindings") |
| 179 | .AppendASCII("externally_connectable_everywhere"))); |
| 180 | |
| 181 | ui_test_utils::NavigateToURL( |
| 182 | browser(), |
| 183 | embedded_test_server()->GetURL( |
| 184 | "/extensions/api_test/bindings/override_gin_define.html")); |
| 185 | ASSERT_FALSE( |
| 186 | browser()->tab_strip_model()->GetActiveWebContents()->IsCrashed()); |
| 187 | |
| 188 | // See chrome/test/data/extensions/api_test/bindings/override_gin_define.html. |
| 189 | std::string result; |
| 190 | EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 191 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 192 | "window.domAutomationController.send(" |
| 193 | "document.getElementById('status').textContent.trim());", |
| 194 | &result)); |
| 195 | EXPECT_EQ("success", result); |
| 196 | } |
| 197 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 198 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, HandlerFunctionTypeChecking) { |
rdevlin.cronin | a5ecbc8 | 2015-10-29 23:41:29 | [diff] [blame] | 199 | ui_test_utils::NavigateToURL( |
| 200 | browser(), |
| 201 | embedded_test_server()->GetURL( |
| 202 | "/extensions/api_test/bindings/handler_function_type_checking.html")); |
| 203 | content::WebContents* web_contents = |
| 204 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 205 | EXPECT_FALSE(web_contents->IsCrashed()); |
| 206 | // See handler_function_type_checking.html. |
| 207 | std::string result; |
| 208 | EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 209 | web_contents, |
| 210 | "window.domAutomationController.send(" |
| 211 | "document.getElementById('status').textContent.trim());", |
| 212 | &result)); |
| 213 | EXPECT_EQ("success", result); |
| 214 | } |
| 215 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 216 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, |
rdevlin.cronin | 75b803b | 2016-03-02 00:13:47 | [diff] [blame] | 217 | MoreNativeFunctionInterceptionTests) { |
rdevlin.cronin | 75b803b | 2016-03-02 00:13:47 | [diff] [blame] | 218 | // We need to create runtime bindings in the web page. An extension that's |
| 219 | // externally connectable will do that for us. |
| 220 | ASSERT_TRUE( |
| 221 | LoadExtension(test_data_dir_.AppendASCII("bindings") |
| 222 | .AppendASCII("externally_connectable_everywhere"))); |
| 223 | |
| 224 | ui_test_utils::NavigateToURL( |
| 225 | browser(), |
| 226 | embedded_test_server()->GetURL( |
| 227 | "/extensions/api_test/bindings/function_interceptions.html")); |
| 228 | content::WebContents* web_contents = |
| 229 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 230 | EXPECT_FALSE(web_contents->IsCrashed()); |
| 231 | // See function_interceptions.html. |
| 232 | std::string result; |
| 233 | EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 234 | web_contents, "window.domAutomationController.send(window.testStatus);", |
| 235 | &result)); |
| 236 | EXPECT_EQ("success", result); |
| 237 | } |
| 238 | |
asargent | 79b64c3 | 2016-08-04 17:17:14 | [diff] [blame] | 239 | class FramesExtensionBindingsApiTest : public ExtensionBindingsApiTest { |
| 240 | public: |
| 241 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 242 | ExtensionBindingsApiTest::SetUpCommandLine(command_line); |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 243 | command_line->AppendSwitch(::switches::kDisablePopupBlocking); |
asargent | 79b64c3 | 2016-08-04 17:17:14 | [diff] [blame] | 244 | } |
| 245 | }; |
| 246 | |
| 247 | // This tests that web pages with iframes or child windows pointing at |
| 248 | // chrome-extenison:// urls, both web_accessible and nonexistent pages, don't |
| 249 | // get improper extensions bindings injected while they briefly still point at |
| 250 | // about:blank and are still scriptable by their parent. |
| 251 | // |
| 252 | // The general idea is to load up 2 extensions, one which listens for external |
| 253 | // messages ("receiver") and one which we'll try first faking messages from in |
| 254 | // the web page's iframe, as well as actually send a message from later |
| 255 | // ("sender"). |
Dave Tapuska | 61ed7fbb | 2017-09-05 21:42:08 | [diff] [blame] | 256 | IN_PROC_BROWSER_TEST_P(FramesExtensionBindingsApiTest, FramesBeforeNavigation) { |
asargent | 79b64c3 | 2016-08-04 17:17:14 | [diff] [blame] | 257 | // Load the sender and receiver extensions, and make sure they are ready. |
| 258 | ExtensionTestMessageListener sender_ready("sender_ready", true); |
| 259 | const Extension* sender = LoadExtension( |
| 260 | test_data_dir_.AppendASCII("bindings").AppendASCII("message_sender")); |
| 261 | ASSERT_NE(nullptr, sender); |
| 262 | ASSERT_TRUE(sender_ready.WaitUntilSatisfied()); |
| 263 | |
| 264 | ExtensionTestMessageListener receiver_ready("receiver_ready", false); |
| 265 | const Extension* receiver = |
| 266 | LoadExtension(test_data_dir_.AppendASCII("bindings") |
| 267 | .AppendASCII("external_message_listener")); |
| 268 | ASSERT_NE(nullptr, receiver); |
| 269 | ASSERT_TRUE(receiver_ready.WaitUntilSatisfied()); |
| 270 | |
| 271 | // Load the web page which tries to impersonate the sender extension via |
| 272 | // scripting iframes/child windows before they finish navigating to pages |
| 273 | // within the sender extension. |
asargent | 79b64c3 | 2016-08-04 17:17:14 | [diff] [blame] | 274 | ui_test_utils::NavigateToURL( |
| 275 | browser(), |
| 276 | embedded_test_server()->GetURL( |
| 277 | "/extensions/api_test/bindings/frames_before_navigation.html")); |
| 278 | |
| 279 | bool page_success = false; |
| 280 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 281 | browser()->tab_strip_model()->GetWebContentsAt(0), "getResult()", |
| 282 | &page_success)); |
| 283 | EXPECT_TRUE(page_success); |
| 284 | |
| 285 | // Reply to |sender|, causing it to send a message over to |receiver|, and |
| 286 | // then ask |receiver| for the total message count. It should be 1 since |
| 287 | // |receiver| should not have received any impersonated messages. |
| 288 | sender_ready.Reply(receiver->id()); |
| 289 | int message_count = 0; |
| 290 | ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| 291 | ProcessManager::Get(profile()) |
| 292 | ->GetBackgroundHostForExtension(receiver->id()) |
| 293 | ->host_contents(), |
| 294 | "getMessageCountAfterReceivingRealSenderMessage()", &message_count)); |
| 295 | EXPECT_EQ(1, message_count); |
| 296 | } |
| 297 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 298 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, TestFreezingChrome) { |
rdevlin.cronin | 741da00 | 2017-04-24 20:27:41 | [diff] [blame] | 299 | ui_test_utils::NavigateToURL( |
| 300 | browser(), embedded_test_server()->GetURL( |
| 301 | "/extensions/api_test/bindings/freeze.html")); |
| 302 | content::WebContents* web_contents = |
| 303 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 304 | ASSERT_FALSE(web_contents->IsCrashed()); |
| 305 | } |
| 306 | |
rdevlin.cronin | e6e2002 | 2017-06-13 18:23:40 | [diff] [blame] | 307 | // Tests interaction with event filter parsing. |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 308 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, TestEventFilterParsing) { |
rdevlin.cronin | e6e2002 | 2017-06-13 18:23:40 | [diff] [blame] | 309 | ExtensionTestMessageListener listener("ready", false); |
| 310 | ASSERT_TRUE( |
| 311 | LoadExtension(test_data_dir_.AppendASCII("bindings/event_filter"))); |
| 312 | ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 313 | |
| 314 | ResultCatcher catcher; |
| 315 | ui_test_utils::NavigateToURL( |
| 316 | browser(), embedded_test_server()->GetURL("example.com", "/title1.html")); |
| 317 | ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 318 | } |
| 319 | |
rdevlin.cronin | 350824d4 | 2017-06-16 14:47:35 | [diff] [blame] | 320 | // crbug.com/733337 |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 321 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, ValidationInterception) { |
rdevlin.cronin | 350824d4 | 2017-06-16 14:47:35 | [diff] [blame] | 322 | // We need to create runtime bindings in the web page. An extension that's |
| 323 | // externally connectable will do that for us. |
| 324 | ASSERT_TRUE( |
| 325 | LoadExtension(test_data_dir_.AppendASCII("bindings") |
| 326 | .AppendASCII("externally_connectable_everywhere"))); |
| 327 | |
| 328 | content::WebContents* web_contents = |
| 329 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 330 | ui_test_utils::NavigateToURL( |
| 331 | browser(), |
| 332 | embedded_test_server()->GetURL( |
| 333 | "/extensions/api_test/bindings/validation_interception.html")); |
| 334 | content::WaitForLoadStop(web_contents); |
| 335 | ASSERT_FALSE(web_contents->IsCrashed()); |
| 336 | bool caught = false; |
| 337 | ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 338 | web_contents, "domAutomationController.send(caught)", &caught)); |
| 339 | EXPECT_TRUE(caught); |
| 340 | } |
| 341 | |
Devlin Cronin | 5cf20f0 | 2017-10-10 14:25:04 | [diff] [blame] | 342 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, UncaughtExceptionLogging) { |
| 343 | ASSERT_TRUE(RunExtensionTest("bindings/uncaught_exception_logging")) |
| 344 | << message_; |
| 345 | } |
| 346 | |
Alex Moshchuk | e63b9e9 | 2017-10-14 00:27:22 | [diff] [blame] | 347 | // Verify that when a web frame embeds an extension subframe, and that subframe |
| 348 | // is the only active portion of the extension, the subframe gets proper JS |
| 349 | // bindings. See https://crbug.com/760341. |
| 350 | IN_PROC_BROWSER_TEST_P(ExtensionBindingsApiTest, |
| 351 | ExtensionSubframeGetsBindings) { |
| 352 | // Load an extension that does not have a background page or popup, so it |
| 353 | // won't be activated just yet. |
| 354 | const extensions::Extension* extension = |
| 355 | LoadExtension(test_data_dir_.AppendASCII("bindings") |
| 356 | .AppendASCII("extension_subframe_gets_bindings")); |
| 357 | ASSERT_TRUE(extension); |
| 358 | |
| 359 | // Navigate current tab to a web URL with a subframe. |
| 360 | content::WebContents* web_contents = |
| 361 | browser()->tab_strip_model()->GetActiveWebContents(); |
| 362 | ui_test_utils::NavigateToURL(browser(), |
| 363 | embedded_test_server()->GetURL("/iframe.html")); |
| 364 | |
| 365 | // Navigate the subframe to the extension URL, which should activate the |
| 366 | // extension. |
| 367 | GURL extension_url(extension->GetResourceURL("page.html")); |
| 368 | ResultCatcher catcher; |
| 369 | content::NavigateIframeToURL(web_contents, "test", extension_url); |
| 370 | ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 371 | } |
| 372 | |
Devlin Cronin | c3a1e507 | 2017-08-17 17:02:49 | [diff] [blame] | 373 | // Run core bindings API tests with both native and JS-based bindings. This |
| 374 | // ensures we have some minimum level of coverage while in the experimental |
| 375 | // phase, when native bindings may be enabled on trunk but not at 100% stable. |
| 376 | INSTANTIATE_TEST_CASE_P(Native, |
| 377 | ExtensionBindingsApiTest, |
| 378 | ::testing::Values(NATIVE_BINDINGS)); |
| 379 | INSTANTIATE_TEST_CASE_P(JavaScript, |
| 380 | ExtensionBindingsApiTest, |
| 381 | ::testing::Values(JAVASCRIPT_BINDINGS)); |
| 382 | |
| 383 | INSTANTIATE_TEST_CASE_P(Native, |
| 384 | FramesExtensionBindingsApiTest, |
| 385 | ::testing::Values(NATIVE_BINDINGS)); |
| 386 | INSTANTIATE_TEST_CASE_P(JavaScript, |
| 387 | FramesExtensionBindingsApiTest, |
| 388 | ::testing::Values(JAVASCRIPT_BINDINGS)); |
| 389 | |
[email protected] | adafe5b | 2013-08-09 10:35:04 | [diff] [blame] | 390 | } // namespace |
| 391 | } // namespace extensions |