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