content/base/test/test_bug482935.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test bug 482935</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href=" /tests/SimpleTest/test.css" />
michael@0 7 </head>
michael@0 8 <body onload="onWindowLoad()">
michael@0 9 <script class="testbody" type="text/javascript">
michael@0 10
michael@0 11 var url = "bug482935.sjs";
michael@0 12
michael@0 13 function clearCache() {
michael@0 14 SpecialPowers.Cc["@mozilla.org/netwerk/cache-storage-service;1"].
michael@0 15 getService(SpecialPowers.Ci.nsICacheStorageService).
michael@0 16 clear();
michael@0 17 }
michael@0 18
michael@0 19 // Tests that the response is cached if the request is cancelled
michael@0 20 // after it has reached state 4
michael@0 21 function testCancelInPhase4() {
michael@0 22
michael@0 23 clearCache();
michael@0 24
michael@0 25 // First request - should be loaded from server
michael@0 26 var xhr = new XMLHttpRequest();
michael@0 27 xhr.addEventListener("readystatechange", function(e) {
michael@0 28 if (xhr.readyState < xhr.DONE) return;
michael@0 29 is(xhr.readyState, xhr.DONE, "wrong readyState");
michael@0 30 xhr.abort();
michael@0 31 SimpleTest.executeSoon(function() {
michael@0 32 // This request was cancelled, so the responseText should be empty string
michael@0 33 is(xhr.responseText, "", "Expected empty response to cancelled request");
michael@0 34
michael@0 35 // Second request - should be found in cache
michael@0 36 var xhr2 = new XMLHttpRequest();
michael@0 37
michael@0 38 xhr2.addEventListener("load", function() {
michael@0 39 is(xhr2.responseText, "0", "Received fresh value for second request");
michael@0 40 SimpleTest.finish();
michael@0 41 }, false);
michael@0 42
michael@0 43 xhr2.open("GET", url);
michael@0 44 xhr2.setRequestHeader("X-Request", "1", false);
michael@0 45
michael@0 46 try { xhr2.send(); }
michael@0 47 catch(e) {
michael@0 48 is(xhr2.status, "200", "Exception!");
michael@0 49 }
michael@0 50 });
michael@0 51 }, false);
michael@0 52
michael@0 53 xhr.open("GET", url, true);
michael@0 54 xhr.setRequestHeader("X-Request", "0", false);
michael@0 55 try { xhr.send(); }
michael@0 56 catch(e) {
michael@0 57 is("Nothing", "Exception", "Boom: " + e);
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 function onWindowLoad() {
michael@0 62 testCancelInPhase4();
michael@0 63 }
michael@0 64
michael@0 65 SimpleTest.waitForExplicitFinish();
michael@0 66 </script>
michael@0 67 </body>
michael@0 68 </html>

mercurial