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 288349 53638cfd818d
parent 288348 2134819f1c61
child 288350 0bf6e7b07ad2
push id30079
push userryanvm@gmail.com
push dateSat, 12 Mar 2016 20:24:19 +0000
treeherdermozilla-central@d1d47ba19ce9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1120715
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);