You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/09/20 02:28:26 UTC

spec commit: added test for onload being called, as well as multiple local overlapping calls in async mode

Updated Branches:
  refs/heads/master 1e1f6d343 -> c77ae04e7


added test for onload being called, as well as multiple local overlapping calls in async mode


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/c77ae04e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/c77ae04e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/c77ae04e

Branch: refs/heads/master
Commit: c77ae04e7acc303aa4d8749d30dcf03619239c30
Parents: 1e1f6d3
Author: purplecabbage <pu...@gmail.com>
Authored: Thu Sep 19 17:27:48 2013 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Thu Sep 19 17:27:48 2013 -0700

----------------------------------------------------------------------
 autotest/tests/localXHR.tests.js | 177 ++++++++++++++++++++--------------
 1 file changed, 106 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/c77ae04e/autotest/tests/localXHR.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/localXHR.tests.js b/autotest/tests/localXHR.tests.js
index 9b4cd8b..f15d0a5 100644
--- a/autotest/tests/localXHR.tests.js
+++ b/autotest/tests/localXHR.tests.js
@@ -21,92 +21,127 @@
 
 describe("XMLHttpRequest", function () {
 
-    var createXHR = function(url,bAsync,win,lose) {
+    var createXHR = function (url, bAsync, win, lose) {
         var xhr = new XMLHttpRequest();
-        xhr.open("GET",url,bAsync);
+        xhr.open("GET", url, bAsync);
         xhr.onload = win;
         xhr.onerror = lose;
         xhr.send();
         return xhr;
     }
 
-    it("XMLHttpRequest.spec.1 should exist", function () {
-        expect(window.XMLHttpRequest).toBeDefined();
-        expect(window.XMLHttpRequest.UNSENT).toBe(0);
-        expect(window.XMLHttpRequest.OPENED).toBe(1);
-        expect(window.XMLHttpRequest.HEADERS_RECEIVED).toBe(2);
-        expect(window.XMLHttpRequest.LOADING).toBe(3);
-        expect(window.XMLHttpRequest.DONE).toBe(4);
-    });
+        it("XMLHttpRequest.spec.1 should exist", function () {
+            expect(window.XMLHttpRequest).toBeDefined();
+            expect(window.XMLHttpRequest.UNSENT).toBe(0);
+            expect(window.XMLHttpRequest.OPENED).toBe(1);
+            expect(window.XMLHttpRequest.HEADERS_RECEIVED).toBe(2);
+            expect(window.XMLHttpRequest.LOADING).toBe(3);
+            expect(window.XMLHttpRequest.DONE).toBe(4);
+        });
 
-    it("XMLHttpRequest.spec.2 should be able to create new XHR", function () {
-
-    	var xhr = new XMLHttpRequest();
-    	expect(xhr).toBeDefined();
-
-// abort
-    	expect(xhr.abort).toBeDefined();
-    	expect(typeof xhr.abort == 'function').toBe(true);
-
-// getResponseHeader
-    	expect(xhr.getResponseHeader).toBeDefined();
-    	expect(typeof xhr.getResponseHeader == 'function').toBe(true);
-
-// getAllResponseHeaders
-    	expect(xhr.getAllResponseHeaders).toBeDefined();
-    	expect(typeof xhr.getAllResponseHeaders == 'function').toBe(true);
-
-// overrideMimeType
-    	expect(xhr.overrideMimeType).toBeDefined();
-    	expect(typeof xhr.overrideMimeType == 'function').toBe(true);
-    	return;
-// open
-    	expect(xhr.open).toBeDefined();
-    	expect(typeof xhr.open == 'function').toBe(true);
-// send
-    	expect(xhr.send).toBeDefined();
-    	expect(typeof xhr.send == 'function').toBe(true);
-// setRequestHeader
-    	expect(xhr.setRequestHeader).toBeDefined();
-    	expect(typeof xhr.setRequestHeader == 'function').toBe(true);
-    });
+        it("XMLHttpRequest.spec.2 should be able to create new XHR", function () {
+
+        	var xhr = new XMLHttpRequest();
+        	expect(xhr).toBeDefined();
+
+    // abort
+        	expect(xhr.abort).toBeDefined();
+        	expect(typeof xhr.abort == 'function').toBe(true);
+
+    // getResponseHeader
+        	expect(xhr.getResponseHeader).toBeDefined();
+        	expect(typeof xhr.getResponseHeader == 'function').toBe(true);
+
+    // getAllResponseHeaders
+        	expect(xhr.getAllResponseHeaders).toBeDefined();
+        	expect(typeof xhr.getAllResponseHeaders == 'function').toBe(true);
+
+    // overrideMimeType
+        	expect(xhr.overrideMimeType).toBeDefined();
+        	expect(typeof xhr.overrideMimeType == 'function').toBe(true);
+        	return;
+    // open
+        	expect(xhr.open).toBeDefined();
+        	expect(typeof xhr.open == 'function').toBe(true);
+    // send
+        	expect(xhr.send).toBeDefined();
+        	expect(typeof xhr.send == 'function').toBe(true);
+    // setRequestHeader
+        	expect(xhr.setRequestHeader).toBeDefined();
+        	expect(typeof xhr.setRequestHeader == 'function').toBe(true);
+        });
 
-    it("XMLHttpRequest.spec.2 should be able to load the current page", function () {
-        var win = jasmine.createSpy().andCallFake(function (res) {});
-        var lose = createDoNotCallSpy('xhrFail');
-        var xhr = createXHR("localXHR.html", true, win, lose);
-        waitsForAny(win, lose);
+        it("XMLHttpRequest.spec.2 should be able to load the current page", function () {
+            var win = jasmine.createSpy().andCallFake(function (res) {});
+            var lose = createDoNotCallSpy('xhrFail');
+            var xhr = createXHR("localXHR.html", true, win, lose);
+            waitsForAny(win, lose);
 
-    });
+        });
 
-    it("XMLHttpRequest.spec.3 should be able to load the current page", function () {
-        var win = jasmine.createSpy().andCallFake(function (res) {});
-        var lose = createDoNotCallSpy('xhrFail');
-        var xhr = createXHR(window.location.href, true, win, lose);
-        waitsForAny(win, lose);
-    });
+        it("XMLHttpRequest.spec.9 calls onload from successful http get", function () {
+            var win = jasmine.createSpy().andCallFake(function (res) { });
+            var lose = createDoNotCallSpy('xhrFail');
+            var xhr = createXHR("http://cordova-filetransfer.jitsu.com", true, win, lose);
+            waitsForAny(win, lose);
+        });
 
-    it("XMLHttpRequest.spec.4 should be able to load the parent folder page ../index.html", function () {
-        var win = jasmine.createSpy().andCallFake(function (res) {});
-        var lose = createDoNotCallSpy('xhrFail');
-        var xhr = createXHR("../index.html", true, win, lose);
-        waitsForAny(win, lose);
-    });
+        it("XMLHttpRequest.spec.3 should be able to load the current page", function () {
+            var win = jasmine.createSpy().andCallFake(function (res) {});
+            var lose = createDoNotCallSpy('xhrFail');
+            var xhr = createXHR(window.location.href, true, win, lose);
+            waitsForAny(win, lose);
+        });
 
-    it("XMLHttpRequest.spec.5 should be able to load the current page ./???.html", function () {
-        var win = jasmine.createSpy().andCallFake(function (res) { });
-        var lose = createDoNotCallSpy('xhrFail');
-        var fileName = window.location.href.split('#')[0].split('/').pop();
-        var xhr = createXHR("./" + fileName, true, win, lose);
-        waitsForAny(win, lose);
-    });
+        it("XMLHttpRequest.spec.4 should be able to load the parent folder page ../index.html", function () {
+            var win = jasmine.createSpy().andCallFake(function (res) {});
+            var lose = createDoNotCallSpy('xhrFail');
+            var xhr = createXHR("../index.html", true, win, lose);
+            waitsForAny(win, lose);
+        });
+
+        it("XMLHttpRequest.spec.5 should be able to load the current page ./???.html", function () {
+            var win = jasmine.createSpy().andCallFake(function (res) { });
+            var lose = createDoNotCallSpy('xhrFail');
+            var fileName = window.location.href.split('#')[0].split('/').pop();
+            var xhr = createXHR("./" + fileName, true, win, lose);
+            waitsForAny(win, lose);
+        });
 
-    it("XMLHttpRequest.spec.6 adds hash-path and loads file okay", function () {
-        window.location = window.location.href + "#asd/asd/asdasd";
-        var win = jasmine.createSpy().andCallFake(function (res) { });
+        it("XMLHttpRequest.spec.6 adds hash-path and loads file okay", function () {
+            window.location = window.location.href + "#asd/asd/asdasd";
+            var win = jasmine.createSpy().andCallFake(function (res) { });
+            var lose = createDoNotCallSpy('xhrFail');
+            var xhr = createXHR(window.location.href, true, win, lose);
+            waitsForAny(win, lose);
+        });
+
+    it("XMLHttpRequest.spec.10 overlapping async calls are not muxed", function () {
+
+        var order = "";
+
+        var winA = jasmine.createSpy("spyWinA").andCallFake(function(){
+            order += "A";  
+        });
+        var winB = jasmine.createSpy("spyWinB").andCallFake(function(){
+            order += "B";  
+        });
         var lose = createDoNotCallSpy('xhrFail');
-        var xhr = createXHR(window.location.href, true, win, lose);
-        waitsForAny(win, lose);
+        var fileName = window.location.href.split('#')[0].split('/').pop();
+        createXHR(fileName, true, winA, lose);
+        createXHR(fileName, false, winB, lose);
+
+        waitsFor(function () {
+            return lose.wasCalled ||
+                (winA.wasCalled && winB.wasCalled);
+        }, "Expecting both callbacks to be called.", Tests.TEST_TIMEOUT);
+
+        runs(function () {
+            expect(lose).not.toHaveBeenCalled();
+            expect(winA).toHaveBeenCalled();
+            expect(winB).toHaveBeenCalled();
+            console.log("order = " + order);
+        });
     });