1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var got_request
= false;
7 var test_url
= "http://localhost:PORT/extensions/test_file.html";
9 // For running in normal chrome (ie outside of the browser_tests environment),
10 // set debug to 1 here.
13 test_url
= "http://www.google.com/";
14 chrome
.test
.log = function(msg
) { console
.log(msg
) };
15 chrome
.test
.runTests = function(tests
) {
16 for (var i
in tests
) {
20 chrome
.test
.succeed = function(){ console
.log("succeed"); };
21 chrome
.test
.fail = function(){ console
.log("fail"); };
24 function navigate_to_fragment(tab
, callback
) {
25 var new_url
= test_url
+ "#foo";
26 chrome
.test
.log("navigating tab to " + new_url
);
27 chrome
.tabs
.update(tab
.id
, {"url": new_url
}, callback
);
30 var succeeded
= false;
32 function do_execute(tab
) {
33 chrome
.tabs
.executeScript(tab
.id
, {"file": "execute_script.js"});
34 setTimeout(function() {
36 chrome
.test
.fail("timed out");
42 chrome
.test
.runTests([
43 // When the tab is created, a content script will send a request letting
44 // know the onload has fired. Then we navigate to a fragment, and try
45 // running chrome.tabs.executeScript.
47 chrome
.extension
.onRequest
.addListener(function(req
, sender
) {
48 chrome
.test
.log("got request: " + JSON
.stringify(req
));
49 if (req
== "content_script") {
50 navigate_to_fragment(sender
.tab
, do_execute
);
51 } else if (req
== "execute_script") {
53 chrome
.test
.succeed();
56 chrome
.test
.log("creating tab");
57 chrome
.tabs
.create({"url": test_url
});
63 // No port to fix. Run tests directly.
66 chrome
.test
.getConfig(function(config
) {
67 test_url
= test_url
.replace(/PORT/, config
.testServer
.port
);