diff options
author | rdevlin.cronin <rdevlin.cronin@chromium.org> | 2015-06-23 11:27:40 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-23 18:28:27 +0000 |
commit | 77433551299d75383e172b026bc322dcd09976cb (patch) | |
tree | 70a713b12cbcd3678abf90a0d434e9c6ecae61c1 | |
parent | 830c612a2cbaac5bc3fdc07879ccc34fc5a6ae9d (diff) | |
download | chromium_src-77433551299d75383e172b026bc322dcd09976cb.zip chromium_src-77433551299d75383e172b026bc322dcd09976cb.tar.gz chromium_src-77433551299d75383e172b026bc322dcd09976cb.tar.bz2 |
[Extensions] Add a test that for scripting iframes on tab load complete
Add a test that confirms you can script iframes of a tab upon receiving the
'complete' tabs.onUpdated event. It was debated whether or not script injection
into iframes should work even on tabs.onUpdated 'loading' (which is roughly
'document_start'), but decided that tabs.executeScript will inject only into
those frames that are visible at the time executeScript is called, not the time
the script is executed. This is partially for simplicity, and partially for
security with activeTab.
Review URL: https://codereview.chromium.org/1192363008
Cr-Commit-Position: refs/heads/master@{#335710}
5 files changed, 58 insertions, 0 deletions
diff --git a/chrome/browser/extensions/execute_script_apitest.cc b/chrome/browser/extensions/execute_script_apitest.cc index 063736c..38d5e97 100644 --- a/chrome/browser/extensions/execute_script_apitest.cc +++ b/chrome/browser/extensions/execute_script_apitest.cc @@ -111,3 +111,9 @@ IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, UserGesture) { ASSERT_TRUE(StartEmbeddedTestServer()); ASSERT_TRUE(RunExtensionTest("executescript/user_gesture")) << message_; } + +IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, InjectIntoSubframesOnLoad) { + SetupDelayedHostResolver(); + ASSERT_TRUE(StartEmbeddedTestServer()); + ASSERT_TRUE(RunExtensionTest("executescript/subframes_on_load")) << message_; +} diff --git a/chrome/test/data/extensions/api_test/executescript/subframes_on_load/inner.html b/chrome/test/data/extensions/api_test/executescript/subframes_on_load/inner.html new file mode 100644 index 0000000..21932a9 --- /dev/null +++ b/chrome/test/data/extensions/api_test/executescript/subframes_on_load/inner.html @@ -0,0 +1 @@ +<html>Hello world!</html> diff --git a/chrome/test/data/extensions/api_test/executescript/subframes_on_load/manifest.json b/chrome/test/data/extensions/api_test/executescript/subframes_on_load/manifest.json new file mode 100644 index 0000000..eef6d9d --- /dev/null +++ b/chrome/test/data/extensions/api_test/executescript/subframes_on_load/manifest.json @@ -0,0 +1,10 @@ +{ + "version": "1.0.0.0", + "manifest_version": 2, + "name": "Subframes on load", + "description": "Test that calling executeScript on a tab that has completed its load injects into subframes.", + "background": { + "scripts": ["test.js"] + }, + "permissions": ["tabs", "http://a.com/"] +} diff --git a/chrome/test/data/extensions/api_test/executescript/subframes_on_load/outer.html b/chrome/test/data/extensions/api_test/executescript/subframes_on_load/outer.html new file mode 100644 index 0000000..d67738d --- /dev/null +++ b/chrome/test/data/extensions/api_test/executescript/subframes_on_load/outer.html @@ -0,0 +1,6 @@ +<html> +<body> + outer document contents + <iframe src="inner.html"> +</body> +</html> diff --git a/chrome/test/data/extensions/api_test/executescript/subframes_on_load/test.js b/chrome/test/data/extensions/api_test/executescript/subframes_on_load/test.js new file mode 100644 index 0000000..4480f1a --- /dev/null +++ b/chrome/test/data/extensions/api_test/executescript/subframes_on_load/test.js @@ -0,0 +1,35 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { + // If we want to inject into subframes using execute script, we need to wait + // for the tab to finish loading. Otherwise, the frames that would be injected + // into don't exist. + if (changeInfo.status != 'complete') + return; + + chrome.test.runTests([ + function() { + var injectFrameCode = 'chrome.runtime.sendMessage("ping");'; + var pings = 0; + chrome.runtime.onMessage.addListener( + function(request, sender, sendResponse) { + chrome.test.assertEq(request, "ping"); + // Wait for two pings - the main frame and the iframe. + if (++pings == 2) + chrome.test.succeed(); + }); + chrome.tabs.executeScript( + tabId, + {code: injectFrameCode, allFrames: true, runAt: 'document_idle'}); + } + ]); +}); + +chrome.test.getConfig(function(config) { + var url = ('http://a.com:PORT/extensions/api_test/executescript/' + + 'subframes_on_load/outer.html').replace(/PORT/, + config.testServer.port); + chrome.tabs.create({url: url}); +}); |