Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make sure that the callback chains for the XHR fire exactly once.

R=vbhasin,chrishenry
DELTA=22  (22 added, 0 deleted, 0 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=5773


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2275 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
commit 8ced4dfd256282b6c23158d98562cca5297e2e07 1 parent 402c562
divye@google.com authored
View
2  closure/goog/labs/net/xhr.js
@@ -292,6 +292,8 @@ _.makeRequest = function(
} catch (e) {
// XMLHttpRequest.send is known to throw on some versions of FF, for example
// if a cross-origin request is disallowed.
+ xhr.onreadystatechange = goog.nullFunction;
+ window.clearTimeout(timer);
errback(new _.Error('Error sending XHR: ' + e.message, url, xhr));
}
View
20 closure/goog/labs/net/xhr_test.html
@@ -432,6 +432,26 @@
assertObjectEquals({a: 1, b: 2}, responseData);
}
+ function testSendWithClientException() {
+ var stubXhr = setupStubXMLHttpRequest();
+ stubXhr.send = function(data) {
+ throw new Error('CORS XHR with file:// schemas not allowed.');
+ };
+ var err;
+ var result = xhr.send('POST', 'file://test-url', null);
+ goog.result.waitOnSuccess(result, fail);
+ goog.result.waitOnError(result, function(result) {
+ err = result.getError();
+ });
+
+ stubXhr.load(0);
+
+ assertFalse('XHR should not have been sent', stubXhr.sent);
+ assertTrue(err instanceof Error);
+ assertTrue(
+ /CORS XHR with file:\/\/ schemas not allowed./.test(err.message));
+ }
+
</script>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.