Permalink
Browse files

Merge branch 'ie-xdr-abort-fix' of git://github.com/benjamincochran/y…

…ui3 into benjamincochran-ie-xdr-abort-fix

Conflicts:
	src/io/tests/unit/modules.js
  • Loading branch information...
2 parents 6bb7337 + 30f6941 commit c38ceab58eee612cb7e2a06c36367b186c95ba3a @ericf ericf committed Jan 3, 2013
Showing with 122 additions and 14 deletions.
  1. +14 −8 src/io/js/io-xdr.js
  2. +95 −0 src/io/tests/unit/js/xdr-tests.js
  3. +8 −1 src/io/tests/unit/modules.js
  4. +5 −5 src/io/tests/unit/urls.js
View
@@ -6,6 +6,10 @@ cross-domain requests.
@for IO
**/
+// Helpful resources when working with the mess that is XDomainRequest:
+// http://www.cypressnorth.com/blog/web-programming-and-development/internet-explorer-aborting-ajax-requests-fixed/
+// http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
+
/**
Fires when the XDR transport is ready for use.
@event io:xdrReady
@@ -142,13 +146,11 @@ Y.mix(Y.IO.prototype, {
_rS[i] = 4;
io.xdrResponse('failure', o, c);
};
- if (c[t]) {
- o.c.ontimeout = function() {
- _rS[i] = 4;
- io.xdrResponse(t, o, c);
- };
- o.c[t] = c[t];
- }
+ o.c.ontimeout = function() {
+ _rS[i] = 4;
+ io.xdrResponse(t, o, c);
+ };
+ o.c[t] = c[t] || 0;
},
/**
@@ -184,7 +186,11 @@ Y.mix(Y.IO.prototype, {
else if (xdr) {
io._ieEvt(o, c);
o.c.open(c.method || 'GET', uri);
- o.c.send(c.data);
+
+ // Make async to protect against IE 8 oddities.
+ setTimeout(function() {
+ o.c.send(c.data);
+ }, 0);
}
else {
o.c.send(uri, o, c);
@@ -0,0 +1,95 @@
+YUI.add('xdr-tests', function (Y) {
+
+ var URLS = Y.IO.URLS,
+ suite = new Y.Test.Suite('IO XDR Tests'),
+ xdrNative = getNativeXDRSupport(),
+ xdrServer = getXDRServerLocation();
+
+ function getNativeXDRSupport() {
+ var win = Y.config.win;
+
+ if (!win) { return false; }
+
+ // Checks for the presence of the `withCredentials` in an XHR instance
+ // object, which will be present if the environment supports CORS.
+ if (win.XMLHttpRequest && 'withCredentials' in (new XMLHttpRequest())) {
+ return 'CORS';
+ }
+
+ // IE's proprietary cross-domain transport.
+ return win.XDomainRequest ? 'XDR' : false;
+ }
+
+ function getXDRServerLocation() {
+ var loc = window.location,
+ port = window.YOGI_CONFIG && YOGI_CONFIG.xdrPort;
+
+ // We need a location and XDR server port.
+ if (!(loc && port)) { return; }
+
+ return loc.protocol + '//' + loc.hostname + ':' + port + '/';
+ }
+
+ suite.add(new Y.Test.Case({
+ name: "XDR GET",
+
+ _should: {
+ ignore: {
+ 'XDR GET should return the queried data in the response': !(xdrNative && xdrServer)
+ }
+ },
+
+ 'XDR GET should return the queried data in the response': function () {
+ var test = this,
+ data = Y.QueryString.stringify({foo: 'bar'});
+
+ function handleSuccess(tx, res, args) {
+ test.resume(function () {
+ Y.Assert.areSame(data, res.responseText);
+ });
+ }
+
+ Y.io(xdrServer + URLS.get + '?' + data, {
+ method: 'GET',
+ xdr : {use: 'native'},
+ on : {success: handleSuccess}
+ });
+
+ test.wait(2000);
+ }
+ }));
+
+ suite.add(new Y.Test.Case({
+ name: "XDR POST",
+
+ _should: {
+ ignore: {
+ 'XDR POST should return the POSTed data in the response': !(xdrNative && xdrServer)
+ }
+ },
+
+ 'XDR POST should return the POSTed data in the response': function () {
+ var test = this,
+ data = Y.QueryString.stringify({foo: 'bar'});
+
+ function handleSuccess(tx, res, args) {
+ test.resume(function () {
+ Y.Assert.areSame(data, res.responseText);
+ });
+ }
+
+ Y.io(xdrServer + URLS.post, {
+ method : 'POST',
+ data : data,
+ headers: {'Content-Type': 'text/plain'},
+ xdr : {use: 'native'},
+ on : {success: handleSuccess}
+ });
+
+ test.wait(2000);
+ }
+ }));
+
+ Y.Test.Runner.add(suite);
+
+});
@@ -38,10 +38,17 @@ var testModules = {
"serialize-tests": {
"fullpath": "./js/serialize-tests.js",
"requires": ["io-form", "test"]
+ },
+ "xdr-tests": {
+ "fullpath": "./js/xdr-tests.js",
+ "requires": ["io-xdr", "test"]
}
};
if (typeof exports !== 'undefined') {
module.exports = testModules;
- delete testModules['transport-tests']; //Remove non Nodejs Tests
+
+ // Remove non Nodejs Tests
+ delete testModules['transport-tests'];
+ delete testModules['xdr-tests'];
}
View
@@ -1,11 +1,11 @@
-YUI.add('io-urls', function(Y) {
+YUI.add('io-urls', function (Y) {
Y.IO.URLS = {
- 'http': 'echo/status/',
- 'get': 'echo/get/',
+ 'http' : 'echo/status/',
+ 'get' : 'echo/get/',
'delete': 'echo/delete/',
- 'post': 'echo/post/',
- 'non': 'echo/status/404'
+ 'post' : 'echo/post/',
+ 'non' : 'echo/status/404'
};
});

0 comments on commit c38ceab

Please sign in to comment.