| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 var failed = 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 function did_fail() { | 4 * LICENSE file. |
| 5 return failed; | 5 --> |
| 6 } | 6 <script src="background.js"></script> |
| 7 | |
| 8 function set_failed(val) { | |
| 9 failed = val; | |
| 10 } | |
| 11 | |
| 12 function fail() { | |
| 13 set_failed(true); | |
| 14 if (!did_fail()) { | |
| 15 chrome.test.fail(); | |
| 16 } | |
| 17 } | |
| 18 | |
| 19 var test_url = "http://localhost:PORT/files/extensions/test_file.html"; | |
| 20 | |
| 21 // For running in normal chrome (ie outside of the browser_tests environment), | |
| 22 // set debug to 1 here. | |
| 23 var debug = 0; | |
| 24 if (debug) { | |
| 25 test_url = "http://www.google.com"; | |
| 26 chrome.test.log = function(msg) { console.log(msg) }; | |
| 27 chrome.test.runTests = function(tests) { | |
| 28 for (var i in tests) { | |
| 29 tests[i](); | |
| 30 } | |
| 31 }; | |
| 32 chrome.test.succeed = function(){ console.log("succeed"); }; | |
| 33 chrome.test.fail = function(){ console.log("fail"); }; | |
| 34 } | |
| 35 | |
| 36 function runTests() { | |
| 37 chrome.test.runTests([ | |
| 38 function test1() { | |
| 39 chrome.extension.onRequest.addListener(function(req, sender) { | |
| 40 chrome.test.log("got request: " + JSON.stringify(req)); | |
| 41 if (req == "fail") { | |
| 42 fail(); | |
| 43 } else if (req == "content_script_start") { | |
| 44 var tab = sender.tab; | |
| 45 if (tab.url.indexOf("#") != -1) { | |
| 46 fail(); | |
| 47 } else { | |
| 48 chrome.tabs.update(tab.id, {"url": tab.url + "#foo"}); | |
| 49 } | |
| 50 } | |
| 51 }); | |
| 52 chrome.tabs.onUpdated.addListener(function(tabid, info, tab) { | |
| 53 chrome.test.log("onUpdated status: " + info.status + " url:" + tab.url); | |
| 54 if (info.status == "complete" && tab.url.indexOf("#foo") != -1) { | |
| 55 setTimeout(function() { | |
| 56 if (!did_fail()) { | |
| 57 chrome.test.succeed(); | |
| 58 } | |
| 59 }, 750); | |
| 60 } | |
| 61 }); | |
| 62 chrome.test.log("creating tab"); | |
| 63 chrome.tabs.create({"url": test_url}); | |
| 64 } | |
| 65 ]); | |
| 66 } | |
| 67 | |
| 68 if (debug) { | |
| 69 runTests(); | |
| 70 } else { | |
| 71 chrome.test.getConfig(function(config) { | |
| 72 test_url = test_url.replace(/PORT/, config.testServer.port); | |
| 73 runTests(); | |
| 74 }); | |
| 75 } | |
| 76 | |
| 77 </script> | |
| OLD | NEW |