content/base/test/test_bug482935.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug482935.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test bug 482935</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="	/tests/SimpleTest/test.css" />
    1.10 +</head>
    1.11 +<body onload="onWindowLoad()">
    1.12 +<script class="testbody" type="text/javascript">
    1.13 +
    1.14 +var url = "bug482935.sjs";
    1.15 +
    1.16 +function clearCache() {
    1.17 +    SpecialPowers.Cc["@mozilla.org/netwerk/cache-storage-service;1"].
    1.18 +               getService(SpecialPowers.Ci.nsICacheStorageService).
    1.19 +               clear();
    1.20 +}
    1.21 +
    1.22 +// Tests that the response is cached if the request is cancelled
    1.23 +// after it has reached state 4
    1.24 +function testCancelInPhase4() {
    1.25 +
    1.26 +  clearCache();
    1.27 +
    1.28 +  // First request - should be loaded from server
    1.29 +  var xhr = new XMLHttpRequest();
    1.30 +  xhr.addEventListener("readystatechange", function(e) {
    1.31 +    if (xhr.readyState < xhr.DONE) return;
    1.32 +    is(xhr.readyState, xhr.DONE, "wrong readyState");
    1.33 +    xhr.abort();
    1.34 +    SimpleTest.executeSoon(function() {
    1.35 +      // This request was cancelled, so the responseText should be empty string
    1.36 +      is(xhr.responseText, "", "Expected empty response to cancelled request");
    1.37 +
    1.38 +      // Second request - should be found in cache
    1.39 +      var xhr2 = new XMLHttpRequest();
    1.40 +
    1.41 +      xhr2.addEventListener("load", function() {
    1.42 +        is(xhr2.responseText, "0", "Received fresh value for second request");
    1.43 +        SimpleTest.finish();
    1.44 +      }, false);
    1.45 +
    1.46 +      xhr2.open("GET", url);
    1.47 +      xhr2.setRequestHeader("X-Request", "1", false);
    1.48 +
    1.49 +      try { xhr2.send(); }
    1.50 +      catch(e) {
    1.51 +        is(xhr2.status, "200", "Exception!");
    1.52 +      }
    1.53 +    });
    1.54 +  }, false);
    1.55 +
    1.56 +  xhr.open("GET", url, true);
    1.57 +  xhr.setRequestHeader("X-Request", "0", false);
    1.58 +  try { xhr.send(); }
    1.59 +  catch(e) {
    1.60 +    is("Nothing", "Exception", "Boom: " + e);
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +function onWindowLoad() {
    1.65 +  testCancelInPhase4();
    1.66 +}
    1.67 +
    1.68 +SimpleTest.waitForExplicitFinish();
    1.69 +</script>
    1.70 +</body>
    1.71 +</html>

mercurial