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