OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 var got_request = false; |
| 6 |
| 7 var test_url = "http://localhost:PORT/files/extensions/test_file.html"; |
| 8 |
| 9 // For running in normal chrome (ie outside of the browser_tests environment), |
| 10 // set debug to 1 here. |
| 11 var debug = 0; |
| 12 if (debug) { |
| 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) { |
| 17 tests[i](); |
| 18 } |
| 19 }; |
| 20 chrome.test.succeed = function(){ console.log("succeed"); }; |
| 21 chrome.test.fail = function(){ console.log("fail"); }; |
| 22 } |
| 23 |
| 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); |
| 28 } |
| 29 |
| 30 var succeeded = false; |
| 31 |
| 32 function do_execute(tab) { |
| 33 chrome.tabs.executeScript(tab.id, {"file": "execute_script.js"}); |
| 34 setTimeout(function() { |
| 35 if (!succeeded) { |
| 36 chrome.test.fail("timed out"); |
| 37 } |
| 38 }, 10000); |
| 39 } |
| 40 |
| 41 function runTests() { |
| 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. |
| 46 function test1() { |
| 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") { |
| 52 suceeded = true; |
| 53 chrome.test.succeed(); |
| 54 } |
| 55 }); |
| 56 chrome.test.log("creating tab"); |
| 57 chrome.tabs.create({"url": test_url}); |
| 58 } |
| 59 ]); |
| 60 } |
| 61 |
| 62 if (debug) { |
| 63 // No port to fix. Run tests directly. |
| 64 runTests(); |
| 65 } else { |
| 66 chrome.test.getConfig(function(config) { |
| 67 test_url = test_url.replace(/PORT/, config.testServer.port); |
| 68 runTests(); |
| 69 }); |
| 70 } |
OLD | NEW |