| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 var got_request = false; | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 var test_url = "http://localhost:PORT/files/extensions/test_file.html"; | 4 * LICENSE file. |
| 5 | 5 --> |
| 6 // For running in normal chrome (ie outside of the browser_tests environment), | 6 <script src="background.js"></script> |
| 7 // set debug to 1 here. | |
| 8 var debug = 0; | |
| 9 if (debug) { | |
| 10 test_url = "http://www.google.com/"; | |
| 11 chrome.test.log = function(msg) { console.log(msg) }; | |
| 12 chrome.test.runTests = function(tests) { | |
| 13 for (var i in tests) { | |
| 14 tests[i](); | |
| 15 } | |
| 16 }; | |
| 17 chrome.test.succeed = function(){ console.log("succeed"); }; | |
| 18 chrome.test.fail = function(){ console.log("fail"); }; | |
| 19 } | |
| 20 | |
| 21 function navigate_to_fragment(tab, callback) { | |
| 22 var new_url = test_url + "#foo"; | |
| 23 chrome.test.log("navigating tab to " + new_url); | |
| 24 chrome.tabs.update(tab.id, {"url": new_url}, callback); | |
| 25 } | |
| 26 | |
| 27 var succeeded = false; | |
| 28 | |
| 29 function do_execute(tab) { | |
| 30 chrome.tabs.executeScript(tab.id, {"file": "execute_script.js"}); | |
| 31 setTimeout(function() { | |
| 32 if (!succeeded) { | |
| 33 chrome.test.fail("timed out"); | |
| 34 } | |
| 35 }, 10000); | |
| 36 } | |
| 37 | |
| 38 function runTests() { | |
| 39 chrome.test.runTests([ | |
| 40 // When the tab is created, a content script will send a request letting | |
| 41 // know the onload has fired. Then we navigate to a fragment, and try | |
| 42 // running chrome.tabs.executeScript. | |
| 43 function test1() { | |
| 44 chrome.extension.onRequest.addListener(function(req, sender) { | |
| 45 chrome.test.log("got request: " + JSON.stringify(req)); | |
| 46 if (req == "content_script") { | |
| 47 navigate_to_fragment(sender.tab, do_execute); | |
| 48 } else if (req == "execute_script") { | |
| 49 suceeded = true; | |
| 50 chrome.test.succeed(); | |
| 51 } | |
| 52 }); | |
| 53 chrome.test.log("creating tab"); | |
| 54 chrome.tabs.create({"url": test_url}); | |
| 55 } | |
| 56 ]); | |
| 57 } | |
| 58 | |
| 59 if (debug) { | |
| 60 // No port to fix. Run tests directly. | |
| 61 runTests(); | |
| 62 } else { | |
| 63 chrome.test.getConfig(function(config) { | |
| 64 test_url = test_url.replace(/PORT/, config.testServer.port); | |
| 65 runTests(); | |
| 66 }); | |
| 67 } | |
| 68 | |
| 69 </script> | |
| OLD | NEW |