Index: chrome/test/data/extensions/api_test/cross_origin_xhr/content_script/content_script.js |
diff --git a/chrome/test/data/extensions/api_test/cross_origin_xhr/content_script/content_script.js b/chrome/test/data/extensions/api_test/cross_origin_xhr/content_script/content_script.js |
index c30c8dddf9ab45569b8f28afd44688350e07913a..c46805a2a4e2b5f2ce91539613a23de79aabe6cd 100644 |
--- a/chrome/test/data/extensions/api_test/cross_origin_xhr/content_script/content_script.js |
+++ b/chrome/test/data/extensions/api_test/cross_origin_xhr/content_script/content_script.js |
@@ -4,6 +4,7 @@ |
chrome.extension.onRequest.addListener( |
function(url, sender, sendResponse) { |
+ var isErrorTriggered = false; |
var req = new XMLHttpRequest(); |
console.log('Requesting url: ' + url); |
req.open('GET', url, true); |
@@ -16,6 +17,7 @@ chrome.extension.onRequest.addListener( |
}); |
}; |
req.onerror = function() { |
+ isErrorTriggered = true; |
sendResponse({ |
'event': 'error', |
'status': req.status, |
@@ -23,7 +25,22 @@ chrome.extension.onRequest.addListener( |
}); |
}; |
- req.send(null); |
+ try { |
+ req.send(null); |
+ } catch (e) { |
+ if (/^https?:/i.test(url)) { |
+ sendResponse({ |
+ 'thrownError': 'req.send() has thrown an error for ' + url + ': ' + e |
+ }); |
+ } else if (!isErrorTriggered) { |
+ // A NetworkError will synchronously be be thrown whenever a |
+ // FTP request fails. This should be handled by req.onerror. |
+ sendResponse({ |
+ 'thrownError': 'req.send() has thrown an error without dispatching ' + |
+ 'the req.onerror event for ' + url + ': ' + e |
+ }); |
+ } |
+ } |
}); |
chrome.extension.sendRequest('injected'); |