content/base/test/test_bug475156.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=475156
     5 -->
     6 <head>
     7   <title>Test for Bug 475156</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    10 </head>
    11 <body onload="drive(tests.shift());">
    12 <script class="testbody" type="text/javascript">
    14 SimpleTest.waitForExplicitFinish();
    16 var path = "http://mochi.test:8888/tests/content/base/test/";
    18 function fromCache(xhr)
    19 {
    20   var ch = SpecialPowers.wrap(xhr).channel.QueryInterface(SpecialPowers.Ci.nsICacheInfoChannel);
    21   return ch.isFromCache();  
    22 }
    24 var tests = [
    25   // First just init the file with an ETag
    26   {
    27     init: function(xhr) 
    28     {
    29       xhr.open("GET", path + "bug475156.sjs?etag=a1");
    30     },
    32     loading: function(xhr)
    33     {
    34     },
    36     done: function(xhr)
    37     {
    38     },
    39   },
    41   // Try to load the file the first time regularly, we have to get 200 OK
    42   {    
    43     init: function(xhr)
    44     {
    45       xhr.open("GET", path + "bug475156.sjs");
    46     },
    48     loading: function(xhr)
    49     {
    50       is(fromCache(xhr), false, "Not coming from the cache");
    51     },
    53     done: function(xhr)
    54     {
    55       is(xhr.status, 200, "We get a fresh version of the file");
    56       is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
    57       is(xhr.responseText, "a1", "We got the expected file body");
    58     },
    59   },
    61   // Try to load the file the second time regularly, we have to get 304 Not Modified
    62   {    
    63     init: function(xhr)
    64     {
    65       xhr.open("GET", path + "bug475156.sjs");
    66       xhr.setRequestHeader("If-Match", "a1");
    67     },
    69     loading: function(xhr)
    70     {
    71       is(fromCache(xhr), true, "Coming from the cache");
    72     },
    74     done: function(xhr)
    75     {
    76       is(xhr.status, 200, "We got cached version");
    77       is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
    78       is(xhr.responseText, "a1", "We got the expected file body");
    79     },
    80   },
    82   // Try to load the file the third time regularly, we have to get 304 Not Modified
    83   {    
    84     init: function(xhr)
    85     {
    86       xhr.open("GET", path + "bug475156.sjs");
    87       xhr.setRequestHeader("If-Match", "a1");
    88     },
    90     loading: function(xhr)
    91     {
    92       is(fromCache(xhr), true, "Coming from the cache");
    93     },
    95     done: function(xhr)
    96     {
    97       is(xhr.status, 200, "We got cached version");
    98       is(xhr.getResponseHeader("Etag"), "a1", "We got correct ETag");
    99       is(xhr.responseText, "a1", "We got the expected file body");
   100     },
   101   },
   103   // Now modify the ETag
   104   {
   105     init: function(xhr) 
   106     {
   107       xhr.open("GET", path + "bug475156.sjs?etag=a2");
   108     },
   110     loading: function(xhr)
   111     {
   112     },
   114     done: function(xhr)
   115     {
   116     },
   117   },
   119   // Try to load the file, we have to get 200 OK with the new content
   120   {    
   121     init: function(xhr)
   122     {
   123       xhr.open("GET", path + "bug475156.sjs");
   124       xhr.setRequestHeader("If-Match", "a2");
   125     },
   127     loading: function(xhr)
   128     {
   129       is(fromCache(xhr), false, "Not coming from the cache");
   130     },
   132     done: function(xhr)
   133     {
   134       is(xhr.status, 200, "We get a fresh version of the file");
   135       is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
   136       is(xhr.responseText, "a2", "We got the expected file body");
   137     },
   138   },
   140   // Try to load the file the second time regularly, we have to get 304 Not Modified
   141   {    
   142     init: function(xhr)
   143     {
   144       xhr.open("GET", path + "bug475156.sjs");
   145       xhr.setRequestHeader("If-Match", "a2");
   146     },
   148     loading: function(xhr)
   149     {
   150       is(fromCache(xhr), true, "Coming from the cache");
   151     },
   153     done: function(xhr)
   154     {
   155       is(xhr.status, 200, "We got cached version");
   156       is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
   157       is(xhr.responseText, "a2", "We got the expected file body");
   158     },
   159   },
   161   // Try to load the file the third time regularly, we have to get 304 Not Modified
   162   {    
   163     init: function(xhr)
   164     {
   165       xhr.open("GET", path + "bug475156.sjs");
   166       xhr.setRequestHeader("If-Match", "a2");
   167     },
   169     loading: function(xhr)
   170     {
   171       is(fromCache(xhr), true, "Coming from the cache");
   172     },
   174     done: function(xhr)
   175     {
   176       is(xhr.status, 200, "We got cached version");
   177       is(xhr.getResponseHeader("Etag"), "a2", "We got correct ETag");
   178       is(xhr.responseText, "a2", "We got the expected file body");
   179     },
   180   },
   182   // Now modify the ETag ones more
   183   {
   184     init: function(xhr) 
   185     {
   186       xhr.open("GET", path + "bug475156.sjs?etag=a3");
   187     },
   189     loading: function(xhr)
   190     {
   191     },
   193     done: function(xhr)
   194     {
   195     },
   196   },
   198   // Try to load the file, we have to get 200 OK with the new content
   199   {    
   200     init: function(xhr)
   201     {
   202       xhr.open("GET", path + "bug475156.sjs");
   203       xhr.setRequestHeader("If-Match", "a3");
   204     },
   206     loading: function(xhr)
   207     {
   208       is(fromCache(xhr), false, "Not coming from the cache");
   209     },
   211     done: function(xhr)
   212     {
   213       is(xhr.status, 200, "We get a fresh version of the file");
   214       is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
   215       is(xhr.responseText, "a3", "We got the expected file body");
   216     },
   217   },
   219   // Try to load the file the second time regularly, we have to get 304 Not Modified
   220   {    
   221     init: function(xhr)
   222     {
   223       xhr.open("GET", path + "bug475156.sjs");
   224       xhr.setRequestHeader("If-Match", "a3");
   225     },
   227     loading: function(xhr)
   228     {
   229       is(fromCache(xhr), true, "Coming from the cache");
   230     },
   232     done: function(xhr)
   233     {
   234       is(xhr.status, 200, "We got cached version");
   235       is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
   236       is(xhr.responseText, "a3", "We got the expected file body");
   237     },
   238   },
   240   // Try to load the file the third time regularly, we have to get 304 Not Modified
   241   {    
   242     init: function(xhr)
   243     {
   244       xhr.open("GET", path + "bug475156.sjs");
   245       xhr.setRequestHeader("If-Match", "a3");
   246     },
   248     loading: function(xhr)
   249     {
   250       is(fromCache(xhr), true, "Coming from the cache");
   251     },
   253     done: function(xhr)
   254     {
   255       is(xhr.status, 200, "We got cached version");
   256       is(xhr.getResponseHeader("Etag"), "a3", "We got correct ETag");
   257       is(xhr.responseText, "a3", "We got the expected file body");
   258     },
   259   },
   260 ]
   263 function drive(test)
   264 {  
   265   var xhr = new XMLHttpRequest();
   266   test.init(xhr);
   267   xhr.onreadystatechange = function() {
   268     if (this.readyState == 3) {
   269       test.loading(this);
   270     }
   271     if (this.readyState == 4) {
   272       test.done(this);
   273       if (tests.length == 0)
   274         SimpleTest.finish();
   275       else
   276         drive(tests.shift());
   277     }
   278   }
   279   xhr.send();
   280 }
   282 </script>
   283 </pre>
   284 </body>
   285 </html>

mercurial