OLD | NEW |
(Empty) | |
| 1 <script> |
| 2 // Tab where the content script has been injected. |
| 3 var testTabId; |
| 4 |
| 5 chrome.test.getConfig(function(config) { |
| 6 |
| 7 function rewriteURL(url) { |
| 8 return url.replace(/PORT/, config.testServer.port); |
| 9 } |
| 10 |
| 11 function doReq(domain, expectSuccess) { |
| 12 var url = rewriteURL(domain + ':PORT/files/extensions/test_file.txt'); |
| 13 |
| 14 chrome.tabs.sendRequest(testTabId, url, function(response) { |
| 15 if (expectSuccess) { |
| 16 chrome.test.assertEq('load', response.event); |
| 17 chrome.test.assertEq(200, response.status); |
| 18 chrome.test.assertEq('Hello!', response.text); |
| 19 } else { |
| 20 chrome.test.assertEq(0, response.status); |
| 21 } |
| 22 |
| 23 chrome.test.runNextTest(); |
| 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 allowedOrigin() { |
| 38 doReq('http://a.com', true); |
| 39 }, |
| 40 function diallowedOrigin() { |
| 41 doReq('http://c.com', false); |
| 42 }, |
| 43 function allowedSubdomain() { |
| 44 doReq('http://foo.b.com', true); |
| 45 }, |
| 46 function noSubdomain() { |
| 47 doReq('http://b.com', true); |
| 48 }, |
| 49 function disallowedSubdomain() { |
| 50 doReq('http://foob.com', false); |
| 51 }, |
| 52 function disallowedSSL() { |
| 53 doReq('https://a.com', false); |
| 54 }, |
| 55 function targetPageAlwaysAllowed() { |
| 56 // Even though localhost does not show up in the host permissions, we |
| 57 // can still make requests to it since it's the page that the content |
| 58 // script is injected into. |
| 59 doReq('http://localhost', true); |
| 60 } |
| 61 ]); |
| 62 }); |
| 63 }); |
| 64 |
| 65 </script> |
OLD | NEW |