Index: chrome/test/data/extensions/api_test/cross_origin_xhr/background_page/test.js |
diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/background_page/test.js b/chrome/test/data/extensions/api_test/cross_origin_xhr/background_page/test.js |
index a3e92119b0c5c15e524778a84f8475a7150a8bd6..ccb2e4fd8ed9c79287fd685c347f39ab4e8bdba2 100644 |
--- a/chrome/test/data/extensions/api_test/cross_origin_xhr/background_page/test.js |
+++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/background_page/test.js |
@@ -4,10 +4,16 @@ |
chrome.test.getConfig(function(config) { |
+ function rewriteURL(url) { |
+ var isFtp = /^ftp:/i.test(url); |
+ var port = isFtp ? config.ftpServer.port : config.testServer.port; |
+ return url.replace(/PORT/, port); |
+ } |
+ |
function doReq(domain, expectSuccess) { |
var req = new XMLHttpRequest(); |
- var url = domain + ":PORT/extensions/test_file.txt"; |
- url = url.replace(/PORT/, config.testServer.port); |
+ var url = rewriteURL(domain + ":PORT/extensions/test_file.txt"); |
+ var isErrorTriggered = false; |
chrome.test.log("Requesting url: " + url); |
req.open("GET", url, true); |
@@ -15,11 +21,13 @@ chrome.test.getConfig(function(config) { |
if (expectSuccess) { |
req.onload = function() { |
- chrome.test.assertEq(200, req.status); |
+ if (/^https?:/i.test(url)) |
+ chrome.test.assertEq(200, req.status); |
chrome.test.assertEq("Hello!", req.responseText); |
chrome.test.succeed(); |
} |
req.onerror = function() { |
+ isErrorTriggered = true; |
chrome.test.log("status: " + req.status); |
chrome.test.log("text: " + req.responseText); |
chrome.test.fail("Unexpected error for domain: " + domain); |
@@ -29,12 +37,25 @@ chrome.test.getConfig(function(config) { |
chrome.test.fail("Unexpected success for domain: " + domain); |
} |
req.onerror = function() { |
+ isErrorTriggered = true; |
chrome.test.assertEq(0, req.status); |
chrome.test.succeed(); |
} |
} |
- req.send(null); |
+ try { |
+ req.send(null); |
+ } catch (e) { |
+ if (/^https?:/i.test(url)) { |
+ chrome.test.fail( |
+ "req.send() has thrown an error for " + domain + ": " + e); |
+ } else if (!isErrorTriggered) { |
+ // A NetworkError will synchronously be be thrown whenever a |
+ // FTP request fails. This should be handled by req.onerror. |
+ chrome.test.fail("req.send() has thrown an error without dispatching " + |
+ "the req.onerror event for " + domain + ": " + e); |
+ } |
+ } |
} |
chrome.test.runTests([ |
@@ -56,6 +77,12 @@ chrome.test.getConfig(function(config) { |
// TODO(asargent): Explicitly create SSL test server and enable the test. |
// function disallowedSSL() { |
// doReq("https://a.com", false); |
- // } |
+ // }, |
+ function allowedFtpHostAllowed() { |
+ doReq('ftp://127.0.0.1', true); |
+ }, |
+ function disallowedFtpHostDisallowed() { |
+ doReq('ftp://this.host.is.not.whitelisted', false); |
+ } |
]); |
}); |