[OpenLayers-Commits] r10965 - trunk/openlayers/tests/Request

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Dec 15 02:51:50 EST 2010


Author: erilem
Date: 2010-12-14 23:51:50 -0800 (Tue, 14 Dec 2010)
New Revision: 10965

Modified:
   trunk/openlayers/tests/Request/XMLHttpRequest.html
Log:
add XMLHttpRequest readyState compliance tests, p=jorix (References #2913)

Modified: trunk/openlayers/tests/Request/XMLHttpRequest.html
===================================================================
--- trunk/openlayers/tests/Request/XMLHttpRequest.html	2010-12-14 16:08:44 UTC (rev 10964)
+++ trunk/openlayers/tests/Request/XMLHttpRequest.html	2010-12-15 07:51:50 UTC (rev 10965)
@@ -7,6 +7,51 @@
             t.ok(new OpenLayers.Request.XMLHttpRequest(),
                  "constructor didn't fail and we trust the code is well tested in OpenLayers.Request methods");
         }
+        function test_readyState(t) {
+        // Verify compliance of the standard (a part) See: http://www.w3.org/TR/XMLHttpRequest/
+        t.plan(9);
+        // Case 1: Request-A: open & abort
+            var requestA = new OpenLayers.Request.XMLHttpRequest();
+            //requestA.onreadystatechange = function() {};
+            t.eq(requestA.readyState, 0, "Request-A: readyState after new is 0-UNSENT");
+            requestA.open("GET", ".", true);
+            t.eq(requestA.readyState, 1, "Request-A: readyState after open is 1-OPENED");
+            requestA.abort();
+            t.eq(requestA.readyState, 0, "Request-A: readyState after abort is 0-UNSENT");
+
+        // Case 2: Request-B: open & send
+            var requestB = new OpenLayers.Request.XMLHttpRequest();
+            requestB.onreadystatechange = function() {
+                if (requestB.readyState == 4) {
+                    t.ok(true, "Request-B: triggered the event onreadystatechange when 4-DONE");
+                }
+            };
+            t.eq(requestB.readyState, 0, "Request-B: readyState after new is 0-UNSENT");
+            requestB.open("GET", ".", true);
+            t.eq(requestB.readyState, 1, "Request-B: readyState after open is 1-OPENED");
+            requestB.send();
+
+        // Case 3: Request-C: open, send & abort
+            var requestC = new OpenLayers.Request.XMLHttpRequest();
+            requestC.onreadystatechange = function() {
+                if (requestC.readyState == 4) {
+                    t.fail("Request-C: triggered the event onreadystatechange when 4-DONE after abort");
+                }
+            };
+            t.eq(requestC.readyState, 0, "Request-C: readyState after new is 0-UNSENT");
+            requestC.open("GET", ".", true);
+            t.eq(requestC.readyState, 1, "Request-C: readyState after open is 1-OPENED");
+            requestC.send();
+            requestC.abort();
+            t.eq(requestC.readyState, 0, "Request-C: readyState after abort is 0-UNSENT");
+
+        // delay destroy
+            t.delay_call( 
+                2, function() {
+                    // to await the end of requestB and requestC
+                }
+            );
+        }
     </script>
 </head>
 <body>



More information about the Commits mailing list