diff options
| author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 00:16:07 +0000 |
|---|---|---|
| committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-08 00:16:07 +0000 |
| commit | b78280062e63e296dc91d1386d42946091048849 (patch) | |
| tree | 9a0438168af33822e727f097e7a238f25e5a6908 | |
| parent | 60898e4b7e2869526aaca0219ea3821d1c737e4c (diff) | |
| download | chromium_src-b78280062e63e296dc91d1386d42946091048849.zip chromium_src-b78280062e63e296dc91d1386d42946091048849.tar.gz chromium_src-b78280062e63e296dc91d1386d42946091048849.tar.bz2 | |
Merge 73250 - Fix bug that caused content scripts to be applied to host
permissions.
Also, consolidate all content script api tests.
BUG=71325
Review URL: http://codereview.chromium.org/6312051
TBR=aa@chromium.org
Review URL: http://codereview.chromium.org/6312202
git-svn-id: svn://svn.chromium.org/chrome/branches/648/src@74058 0039d316-1c4b-4281-b951-d872f2087c98
12 files changed, 117 insertions, 73 deletions
diff --git a/chrome/browser/extensions/content_script_all_frames_apitest.cc b/chrome/browser/extensions/content_script_all_frames_apitest.cc deleted file mode 100644 index b465c42..0000000 --- a/chrome/browser/extensions/content_script_all_frames_apitest.cc +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2009 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. - -#include "chrome/browser/extensions/extension_apitest.h" - -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) { - ASSERT_TRUE(StartTestServer()); - ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_; -} - -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionIframe) { - ASSERT_TRUE(StartTestServer()); - ASSERT_TRUE(RunExtensionTest("content_scripts/extension_iframe")) << message_; -} diff --git a/chrome/browser/extensions/content_script_apitest.cc b/chrome/browser/extensions/content_script_apitest.cc new file mode 100644 index 0000000..01232eb --- /dev/null +++ b/chrome/browser/extensions/content_script_apitest.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2009 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. + +#include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/common/extensions/extension.h" +#include "chrome/test/ui_test_utils.h" +#include "net/base/mock_host_resolver.h" + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) { + ASSERT_TRUE(StartTestServer()); + ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_; +} + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionIframe) { + ASSERT_TRUE(StartTestServer()); + ASSERT_TRUE(RunExtensionTest("content_scripts/extension_iframe")) << message_; +} + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionProcess) { + ASSERT_TRUE(StartTestServer()); + ASSERT_TRUE( + RunExtensionTest("content_scripts/extension_process")) << message_; +} + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptFragmentNavigation) { + ASSERT_TRUE(StartTestServer()); + const char* extension_name = "content_scripts/fragment"; + ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; +} + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptIsolatedWorlds) { + // This extension runs various bits of script and tests that they all run in + // the same isolated world. + ASSERT_TRUE(StartTestServer()); + ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world1")) << message_; + + // Now load a different extension, inject into same page, verify worlds aren't + // shared. + ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world2")) << message_; +} + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptIgnoreHostPermissions) { + ASSERT_TRUE(StartTestServer()); + host_resolver()->AddRule("a.com", "127.0.0.1"); + host_resolver()->AddRule("b.com", "127.0.0.1"); + ASSERT_TRUE(RunExtensionTest( + "content_scripts/dont_match_host_permissions")) << message_; +} diff --git a/chrome/browser/extensions/content_script_extension_process_apitest.cc b/chrome/browser/extensions/content_script_extension_process_apitest.cc deleted file mode 100644 index dc8b143..0000000 --- a/chrome/browser/extensions/content_script_extension_process_apitest.cc +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2009 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. - -#include "chrome/browser/extensions/extension_apitest.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/test/ui_test_utils.h" - -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionProcess) { - ASSERT_TRUE(StartTestServer()); - ASSERT_TRUE( - RunExtensionTest("content_scripts/extension_process")) << message_; -} diff --git a/chrome/browser/extensions/execute_script_apitest.cc b/chrome/browser/extensions/execute_script_apitest.cc index 0015de9..8295ca4 100644 --- a/chrome/browser/extensions/execute_script_apitest.cc +++ b/chrome/browser/extensions/execute_script_apitest.cc @@ -38,3 +38,11 @@ IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, ExecuteScriptFileAfterClose) { ASSERT_TRUE(StartTestServer()); ASSERT_TRUE(RunExtensionTest("executescript/file_after_close")) << message_; } + +// Crashy, http://crbug.com/67774. +IN_PROC_BROWSER_TEST_F(ExecuteScriptApiTest, + DISABLED_ExecuteScriptFragmentNavigation) { + ASSERT_TRUE(StartTestServer()); + const char* extension_name = "executescript/fragment"; + ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; +} diff --git a/chrome/browser/extensions/fragment_navigation_apitest.cc b/chrome/browser/extensions/fragment_navigation_apitest.cc deleted file mode 100644 index 8d931a8..0000000 --- a/chrome/browser/extensions/fragment_navigation_apitest.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2010 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. - -#include "chrome/browser/extensions/extension_apitest.h" - - -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptFragmentNavigation) { - ASSERT_TRUE(StartTestServer()); - const char* extension_name = "content_scripts/fragment"; - ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; -} - -// Crashy, http://crbug.com/67774. -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, - DISABLED_ExecuteScriptFragmentNavigation) { - ASSERT_TRUE(StartTestServer()); - const char* extension_name = "executescript/fragment"; - ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; -} diff --git a/chrome/browser/extensions/isolated_world_apitest.cc b/chrome/browser/extensions/isolated_world_apitest.cc deleted file mode 100644 index 6a71b5b..0000000 --- a/chrome/browser/extensions/isolated_world_apitest.cc +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2009 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. - -#include "chrome/browser/extensions/extension_apitest.h" - -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IsolatedWorld1) { - // This extension runs various bits of script and tests that they all run in - // the same isolated world. - ASSERT_TRUE(StartTestServer()); - ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world1")) << message_; - - // Now load a different extension, inject into same page, verify worlds aren't - // shared. - ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world2")) << message_; -} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 9b7d0d3..eb7e57c 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2050,8 +2050,7 @@ 'browser/extensions/browser_action_test_util_gtk.cc', 'browser/extensions/browser_action_test_util_mac.mm', 'browser/extensions/browser_action_test_util_views.cc', - 'browser/extensions/content_script_all_frames_apitest.cc', - 'browser/extensions/content_script_extension_process_apitest.cc', + 'browser/extensions/content_script_apitest.cc', 'browser/extensions/convert_web_app_browsertest.cc', 'browser/extensions/cross_origin_xhr_apitest.cc', 'browser/extensions/crx_installer_browsertest.cc', @@ -2112,8 +2111,6 @@ 'browser/extensions/extension_webrequest_apitest.cc', 'browser/extensions/extension_websocket_apitest.cc', 'browser/extensions/extension_webstore_private_browsertest.cc', - 'browser/extensions/fragment_navigation_apitest.cc', - 'browser/extensions/isolated_world_apitest.cc', 'browser/extensions/notifications_apitest.cc', 'browser/extensions/page_action_apitest.cc', 'browser/extensions/permissions_apitest.cc', diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 415aff2..e601b21 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -2276,10 +2276,8 @@ bool Extension::CanExecuteScriptOnPage(const GURL& page_url, } // If a script is specified, use its matches. - if (script) { - if (script->MatchesUrl(page_url)) - return true; - } + if (script) + return script->MatchesUrl(page_url); // Otherwise, see if this extension has permission to execute script // programmatically on pages. diff --git a/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/background.html b/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/background.html new file mode 100644 index 0000000..f7c2e7a --- /dev/null +++ b/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/background.html @@ -0,0 +1,29 @@ +<script> +var receivedRequests = {}; + +chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { + if (receivedRequests[request.source]) { + chrome.test.fail( + 'Received multiple requests from "' + request.source + '".'); + return; + } + + chrome.test.assertEq(request.source == 'a.com', request.modified); + receivedRequests[request.source] = true; + if (receivedRequests['a.com'] && receivedRequests['b.com']) + chrome.test.succeed(); +}); + +// We load two pages. On a.com, both our modify and test script will run and we +// will receive a request that says that the page was modified. On b.com, only +// the test script will run, and the request will say that the page was not +// modified. +chrome.test.getConfig(function(config) { + chrome.tabs.create({ + url: 'http://a.com:' + config.testServer.port + + '/files/extensions/test_file.html'}); + chrome.tabs.create({ + url: 'http://b.com:' + config.testServer.port + + '/files/extensions/test_file.html'}); +}); +</script> diff --git a/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/manifest.json b/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/manifest.json new file mode 100644 index 0000000..072c49a --- /dev/null +++ b/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/manifest.json @@ -0,0 +1,22 @@ +{ + "name": "content script don't match host permissions", + "version": "1.0", + "description": "Tests that content scripts don't match host permissions.", + "background_page": "background.html", + "permissions": [ + "tabs", + "http://b.com/*" + ], + "content_scripts": [ + { + "matches": ["http://a.com/*"], + "js": ["modify.js"], + "run_at": "document_end" + }, + { + "matches": ["<all_urls>"], + "js": ["test.js"], + "run_at": "document_end" + } + ] +} diff --git a/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/modify.js b/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/modify.js new file mode 100644 index 0000000..eeff6f2 --- /dev/null +++ b/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/modify.js @@ -0,0 +1 @@ +window.title = "Hello"; diff --git a/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/test.js b/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/test.js new file mode 100644 index 0000000..4d1f3ee --- /dev/null +++ b/chrome/test/data/extensions/api_test/content_scripts/dont_match_host_permissions/test.js @@ -0,0 +1,4 @@ +chrome.extension.sendRequest({ + source: location.hostname, + modified: window.title == 'Hello' +}); |
