forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't re-run content scripts on fragment navigations.
This regression was inadvertently introduced by a fix to make executeScript run after a fragment navigation (bug 29541). That patch was: http://codereview.chromium.org/566041 The problem is that on frame navigations (didChangeLocationWithinPage), we end up creating a new UserScriptIdleScheduler, so this patch keeps track of the previous has_run state and propagates that to the new UserScriptIdleScheduler. BUG=35924 TEST=Steps to verify are outlined in bug report Review URL: http://codereview.chromium.org/646017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39939 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
asargent@chromium.org
committed
Feb 24, 2010
1 parent
a6e82fc
commit f6c2459
Showing
12 changed files
with
216 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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) { | ||
StartHTTPServer(); | ||
const char* extension_name = "content_scripts/fragment"; | ||
ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ExecuteScriptFragmentNavigation) { | ||
StartHTTPServer(); | ||
const char* extension_name = "executescript/fragment"; | ||
ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
chrome/test/data/extensions/api_test/content_scripts/fragment/background.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<script> | ||
var failed = false; | ||
|
||
function did_fail() { | ||
return failed; | ||
} | ||
|
||
function set_failed(val) { | ||
failed = val; | ||
} | ||
|
||
function fail() { | ||
set_failed(true); | ||
if (!did_fail()) { | ||
chrome.test.fail(); | ||
} | ||
} | ||
|
||
var test_url = "http://localhost:1337/files/extensions/test_file.html"; | ||
|
||
// For running in normal chrome (ie outside of the browser_tests environment), | ||
// set debug to 1 here. | ||
var debug = 0; | ||
if (debug) { | ||
test_url = "http://www.google.com"; | ||
chrome.test.log = function(msg) { console.log(msg) }; | ||
chrome.test.runTests = function(tests) { | ||
for (var i in tests) { | ||
tests[i](); | ||
} | ||
}; | ||
chrome.test.succeed = function(){ console.log("succeed"); }; | ||
chrome.test.fail = function(){ console.log("fail"); }; | ||
} | ||
|
||
chrome.test.runTests([ | ||
function test1() { | ||
chrome.extension.onRequest.addListener(function(req, sender) { | ||
chrome.test.log("got request: " + JSON.stringify(req)); | ||
if (req == "fail") { | ||
fail(); | ||
} else if (req == "content_script_start") { | ||
var tab = sender.tab; | ||
if (tab.url.indexOf("#") != -1) { | ||
fail(); | ||
} else { | ||
chrome.tabs.update(tab.id, {"url": tab.url + "#foo"}); | ||
} | ||
} | ||
}); | ||
chrome.tabs.onUpdated.addListener(function(tabid, info, tab) { | ||
chrome.test.log("onUpdated status: " + info.status + " url:" + tab.url); | ||
if (info.status == "complete" && tab.url.indexOf("#foo") != -1) { | ||
setTimeout(function() { | ||
if (!did_fail()) { | ||
chrome.test.succeed(); | ||
} | ||
}, 750); | ||
} | ||
}); | ||
chrome.test.log("creating tab"); | ||
chrome.tabs.create({"url": test_url}); | ||
} | ||
]); | ||
|
||
|
||
</script> |
14 changes: 14 additions & 0 deletions
14
chrome/test/data/extensions/api_test/content_scripts/fragment/content_script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 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. | ||
|
||
// Tests that we don't re-inject scripts after fragment navigation. | ||
|
||
// The background page should only see this once - it will then use tab.update | ||
// to navigate this page to #foo. | ||
chrome.extension.sendRequest("content_script_start"); | ||
|
||
if (location.href.indexOf("#foo") != -1) { | ||
// This means the content script ran again. | ||
chrome.extension.sendRequest("fail"); | ||
} |
10 changes: 10 additions & 0 deletions
10
chrome/test/data/extensions/api_test/content_scripts/fragment/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "content_scripts_fragment_navigation", | ||
"version": "1.0", | ||
"description": "Tests content scripts running with navigation to fragments within a page", | ||
"background_page": "background.html", | ||
"permissions": ["tabs"], | ||
"content_scripts": [ | ||
{ "matches": ["http://*/*"], "js": ["content_script.js"] } | ||
] | ||
} |
59 changes: 59 additions & 0 deletions
59
chrome/test/data/extensions/api_test/executescript/fragment/background.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script> | ||
var got_request = false; | ||
|
||
var test_url = "http://localhost:1337/files/extensions/test_file.html"; | ||
|
||
// For running in normal chrome (ie outside of the browser_tests environment), | ||
// set debug to 1 here. | ||
var debug = 0; | ||
if (debug) { | ||
test_url = "http://www.google.com"; | ||
chrome.test.log = function(msg) { console.log(msg) }; | ||
chrome.test.runTests = function(tests) { | ||
for (var i in tests) { | ||
tests[i](); | ||
} | ||
}; | ||
chrome.test.succeed = function(){ console.log("succeed"); }; | ||
chrome.test.fail = function(){ console.log("fail"); }; | ||
} | ||
|
||
function navigate_to_fragment(tab, callback) { | ||
var new_url = test_url + "#foo"; | ||
chrome.test.log("navigating tab to " + new_url); | ||
chrome.tabs.update(tab.id, {"url": new_url}, callback); | ||
} | ||
|
||
var succeeded = false; | ||
|
||
function do_execute(tab) { | ||
chrome.tabs.executeScript(tab.id, {"file": "execute_script.js"}); | ||
setTimeout(function() { | ||
if (!succeeded) { | ||
chrome.test.fail("timed out"); | ||
} | ||
}, 10000); | ||
} | ||
|
||
|
||
chrome.test.runTests([ | ||
// When the tab is created, a content script will send a request letting | ||
// know the onload has fired. Then we navigate to a fragment, and try | ||
// running chrome.tabs.executeScript. | ||
function test1() { | ||
chrome.extension.onRequest.addListener(function(req, sender) { | ||
chrome.test.log("got request: " + JSON.stringify(req)); | ||
if (req == "content_script") { | ||
navigate_to_fragment(sender.tab, do_execute); | ||
} else if (req == "execute_script") { | ||
suceeded = true; | ||
chrome.test.succeed(); | ||
} | ||
}); | ||
chrome.test.log("creating tab"); | ||
chrome.tabs.create({"url": test_url}); | ||
} | ||
]); | ||
|
||
|
||
</script> |
13 changes: 13 additions & 0 deletions
13
chrome/test/data/extensions/api_test/executescript/fragment/content_script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 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. | ||
|
||
function notify() { | ||
chrome.extension.sendRequest("content_script"); | ||
} | ||
|
||
if (document.readyState) { | ||
notify(); | ||
} else { | ||
document.onload = notify; | ||
} |
6 changes: 6 additions & 0 deletions
6
chrome/test/data/extensions/api_test/executescript/fragment/execute_script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// 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. | ||
|
||
// Notify the background page that we ran. | ||
chrome.extension.sendRequest("execute_script"); |
10 changes: 10 additions & 0 deletions
10
chrome/test/data/extensions/api_test/executescript/fragment/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "execute_script_fragment_navigation", | ||
"version": "1.0", | ||
"description": "Tests execute script running after navigation to a fragments within a page", | ||
"background_page": "background.html", | ||
"permissions": ["tabs", "http://*/*"], | ||
"content_scripts": [ | ||
{"matches": ["http://*/*"], "js": ["content_script.js"]} | ||
] | ||
} |