| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 // Tab where the content script has been injected. | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 var testTabId; | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 | 4 * LICENSE file. |
| 5 var pass = chrome.test.callbackPass; | 5 --> |
| 6 | 6 <script src="test.js"></script> |
| 7 chrome.test.getConfig(function(config) { | |
| 8 | |
| 9 function rewriteURL(url) { | |
| 10 return url.replace(/PORT/, config.testServer.port); | |
| 11 } | |
| 12 | |
| 13 function doReq(domain, expectSuccess) { | |
| 14 var url = rewriteURL(domain + ':PORT/files/extensions/test_file.txt'); | |
| 15 | |
| 16 chrome.tabs.sendRequest(testTabId, url, pass(function(response) { | |
| 17 if (expectSuccess) { | |
| 18 chrome.test.assertEq('load', response.event); | |
| 19 chrome.test.assertEq(200, response.status); | |
| 20 chrome.test.assertEq('Hello!', response.text); | |
| 21 } else { | |
| 22 chrome.test.assertEq(0, response.status); | |
| 23 } | |
| 24 })); | |
| 25 } | |
| 26 | |
| 27 chrome.tabs.create({ | |
| 28 url: rewriteURL('http://localhost:PORT/files/extensions/test_file.html')}, | |
| 29 function(tab) { | |
| 30 testTabId = tab.id; | |
| 31 }); | |
| 32 | |
| 33 chrome.extension.onRequest.addListener(function(message) { | |
| 34 chrome.test.assertEq('injected', message); | |
| 35 | |
| 36 chrome.test.runTests([ | |
| 37 function domainOne() { | |
| 38 doReq('http://a.com', true); | |
| 39 }, | |
| 40 function domainTwo() { | |
| 41 doReq('http://c.com', true); | |
| 42 } | |
| 43 ]); | |
| 44 }); | |
| 45 }); | |
| 46 | |
| 47 </script> | |
| OLD | NEW |