Bug 1120715 - Part 8: Expect a 304 response in the cases where we would do a successful revalidation in the RequestCache test; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 10 Mar 2016 16:42:52 -0500
changeset 339610 53638cfd818d5f31615c41287796bdda4beda854
parent 339609 2134819f1c6193d250d4505ded325f08482f9d8b
child 339611 a614aadd050c69470609aa21a9b43e25c753a40f
child 339692 0bf6e7b07ad241e2b9614594b0ebf0bb2f1d1562
push id12762
push userbmo:rail@mozilla.com
push dateFri, 11 Mar 2016 19:47:45 +0000
reviewersbkelly
bugs1120715
milestone48.0a1
Bug 1120715 - Part 8: Expect a 304 response in the cases where we would do a successful revalidation in the RequestCache test; r=bkelly
testing/web-platform/tests/fetch/api/request/request-cache.html
--- a/testing/web-platform/tests/fetch/api/request/request-cache.html
+++ b/testing/web-platform/tests/fetch/api/request/request-cache.html
@@ -367,60 +367,78 @@
         ignore_request_headers = "&ignore";
       }
       return "resources/cache.py?token=" + uuid +
              "&content=" + content +
              "&" + id + "=" + value +
              "&expires=" + dates[info.state] +
              vary + cache_control + ignore_request_headers;
     }
+    function expected_status(type, identifier, init) {
+      if (type == "date" &&
+          init.headers &&
+          init.headers["If-Modified-Since"] == identifier) {
+        // The server will respond with a 304 in this case.
+        return [304, "Not Modified"];
+      }
+      return [200, "OK"];
+    }
+    function expected_response_text(type, identifier, init, content) {
+      if (type == "date" &&
+          init.headers &&
+          init.headers["If-Modified-Since"] == identifier) {
+        // The server will respond with a 304 in this case.
+        return "";
+      }
+      return content;
+    }
     function server_state(uuid) {
       return fetch("resources/cache.py?querystate&token=" + uuid)
         .then(function(response) {
           return response.text();
         }).then(function(text) {
           return JSON.parse(text);
         });
     }
-    function populate_cache(url, content, info) {
+    function populate_cache(url, content, info, type, identifier) {
       var init = {cache: info.request_cache[0]};
       if ("request_headers" in info) {
         init.headers = info.request_headers[0];
       }
       return fetch(url, init)
         .then(function(response) {
-          assert_equals(response.status, 200);
-          assert_equals(response.statusText, "OK");
+          assert_array_equals([response.status, response.statusText],
+                              expected_status(type, identifier, init));
           return response.text();
         }).then(function(text) {
-          assert_equals(text, content);
+          assert_equals(text, expected_response_text(type, identifier, init, content));
         });
     }
     function make_test(type, info) {
       return function(test) {
         var uuid = token();
         var identifier = (type == "tag" ? Math.random() : now.toGMTString());
         var content = Math.random().toString();
         var url = make_url(uuid, type, identifier, content, info);
         var fetch_functions = [function() {
-          return populate_cache(url, content, info);
+          return populate_cache(url, content, info, type, identifier);
         }];
         for (var i = 1; i < info.request_cache.length; ++i) {
           fetch_functions.push(function(idx) {
             var init = {cache: info.request_cache[idx]};
             if ("request_headers" in info) {
               init.headers = info.request_headers[idx];
             }
             return fetch(url, init)
               .then(function(response) {
-                assert_equals(response.status, 200);
-                assert_equals(response.statusText, "OK");
+                assert_array_equals([response.status, response.statusText],
+                                    expected_status(type, identifier, init));
                 return response.text();
               }).then(function(text) {
-                assert_equals(text, content);
+                assert_equals(text, expected_response_text(type, identifier, init, content));
               });
           });
         }
         var i = 0;
         function run_next_step() {
           if (fetch_functions.length) {
             return fetch_functions.shift()(i++)
               .then(run_next_step);