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/08/22 23:52:25 UTC

spec commit: added tests for using XHR to load local files

Updated Branches:
  refs/heads/master ed09c2124 -> 4b129f7e0


added tests for using XHR to load local files


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/4b129f7e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/4b129f7e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/4b129f7e

Branch: refs/heads/master
Commit: 4b129f7e0e38d107de7107b528bf2a42f6657793
Parents: ed09c21
Author: purplecabbage <pu...@gmail.com>
Authored: Thu Aug 22 12:57:45 2013 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Thu Aug 22 12:57:45 2013 -0700

----------------------------------------------------------------------
 autotest/index.html              |   2 +-
 autotest/pages/all.html          |   1 +
 autotest/tests/localXHR.tests.js | 109 ++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4b129f7e/autotest/index.html
----------------------------------------------------------------------
diff --git a/autotest/index.html b/autotest/index.html
index d213400..f75cebc 100644
--- a/autotest/index.html
+++ b/autotest/index.html
@@ -55,7 +55,7 @@
     <a href="pages/bridge.html" class="btn large" style="width:100%;">Run Bridge Tests</a>
     <a href="pages/splashscreen.html" class="btn large" style="width:100%;">Run Splashscreen Tests</a>
     <a href="pages/whitelist.html" class="btn large" style="width:100%;">Run Whitelist Tests</a>
-
+    <a href="pages/localXHR.html" class="btn large" style="width:100%;">Run local XHR Tests</a>
     <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4b129f7e/autotest/pages/all.html
----------------------------------------------------------------------
diff --git a/autotest/pages/all.html b/autotest/pages/all.html
index 92d9b36..0cb962f 100644
--- a/autotest/pages/all.html
+++ b/autotest/pages/all.html
@@ -62,6 +62,7 @@
   <script type="text/javascript" src="../tests/platform.tests.js"></script>
   <script type="text/javascript" src="../tests/storage.tests.js"></script>
   <script type="text/javascript" src="../tests/splashscreen.tests.js"></script>
+  <script type="text/javascript" src="../tests/localXHR.tests.js"></script>
 
   <script type="text/javascript">
       var root, temp_root, persistent_root;

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4b129f7e/autotest/tests/localXHR.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/localXHR.tests.js b/autotest/tests/localXHR.tests.js
new file mode 100644
index 0000000..3713603
--- /dev/null
+++ b/autotest/tests/localXHR.tests.js
@@ -0,0 +1,109 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+describe("XMLHttpRequest", function () {
+
+    var createXHR = function(url,bAsync,win,lose) {
+        var xhr = new XMLHttpRequest();
+        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.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.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.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 (WP8 backwards compatability) root page www/index.html", function () {
+        var win = jasmine.createSpy().andCallFake(function (res) {});
+        var lose = createDoNotCallSpy('xhrFail');
+        var xhr = createXHR("www/index.html", true, win, lose);
+        waitsForAny(win, lose);
+    });
+
+    it("XMLHttpRequest.spec.6 should be able to load the (WP7 backwards compatability) root page app/www/index.html", function () {
+        var win = jasmine.createSpy().andCallFake(function (res) {});
+        var lose = createDoNotCallSpy('xhrFail');
+        var xhr = createXHR("app/www/index.html", true, win, lose);
+        waitsForAny(win, lose);
+    });
+});
\ No newline at end of file