Bug 1120715 - Part 7: Always use the same date representing 'now' in the RequestCache test; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 10 Mar 2016 16:19:34 -0500
changeset 288318 2134819f1c61
parent 288317 5cce63231d48
child 288319 53638cfd818d
push id73383
push usereakhgari@mozilla.com
push dateFri, 11 Mar 2016 19:41:28 +0000
treeherdermozilla-inbound@53638cfd818d [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 7: Always use the same date representing 'now' 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
@@ -6,16 +6,17 @@
     <meta name="help" href="https://fetch.spec.whatwg.org/#request">
     <meta name="timeout" content="long">
     <script src="/resources/testharness.js"></script>
     <script src="/resources/testharnessreport.js"></script>
     <script src="/common/utils.js"></script>
   </head>
   <body>
     <script>
+    var now = new Date();
     var tests = [
       {
         name: 'RequestCache "default" mode checks the cache for previously cached content and goes to the network for stale responses',
         state: "stale",
         request_cache: ["default", "default"],
         expected_validation_headers: [false, true],
         expected_no_cache_headers: [false, false],
       },
@@ -127,41 +128,41 @@
         request_cache: ["no-store", "default"],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [true, false],
       },
       {
         name: 'RequestCache "default" mode with an If-Modified-Since header is treated similarly to "no-store"',
         state: "stale",
         request_cache: ["default", "default"],
-        request_headers: [{}, {"If-Modified-Since": new Date().toGMTString()}],
+        request_headers: [{}, {"If-Modified-Since": now.toGMTString()}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [false, true],
       },
       {
         name: 'RequestCache "default" mode with an If-Modified-Since header is treated similarly to "no-store"',
         state: "fresh",
         request_cache: ["default", "default"],
-        request_headers: [{}, {"If-Modified-Since": new Date().toGMTString()}],
+        request_headers: [{}, {"If-Modified-Since": now.toGMTString()}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [false, true],
       },
       {
         name: 'RequestCache "default" mode with an If-Modified-Since header is treated similarly to "no-store"',
         state: "stale",
         request_cache: ["default", "default"],
-        request_headers: [{"If-Modified-Since": new Date().toGMTString()}, {}],
+        request_headers: [{"If-Modified-Since": now.toGMTString()}, {}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [true, false],
       },
       {
         name: 'RequestCache "default" mode with an If-Modified-Since header is treated similarly to "no-store"',
         state: "fresh",
         request_cache: ["default", "default"],
-        request_headers: [{"If-Modified-Since": new Date().toGMTString()}, {}],
+        request_headers: [{"If-Modified-Since": now.toGMTString()}, {}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [true, false],
       },
       {
         name: 'RequestCache "default" mode with an If-None-Match header is treated similarly to "no-store"',
         state: "stale",
         request_cache: ["default", "default"],
         request_headers: [{}, {"If-None-Match": '"foo"'}],
@@ -191,41 +192,41 @@
         request_headers: [{"If-None-Match": '"foo"'}, {}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [true, false],
       },
       {
         name: 'RequestCache "default" mode with an If-Unmodified-Since header is treated similarly to "no-store"',
         state: "stale",
         request_cache: ["default", "default"],
-        request_headers: [{}, {"If-Unmodified-Since": new Date().toGMTString()}],
+        request_headers: [{}, {"If-Unmodified-Since": now.toGMTString()}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [false, true],
       },
       {
         name: 'RequestCache "default" mode with an If-Unmodified-Since header is treated similarly to "no-store"',
         state: "fresh",
         request_cache: ["default", "default"],
-        request_headers: [{}, {"If-Unmodified-Since": new Date().toGMTString()}],
+        request_headers: [{}, {"If-Unmodified-Since": now.toGMTString()}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [false, true],
       },
       {
         name: 'RequestCache "default" mode with an If-Unmodified-Since header is treated similarly to "no-store"',
         state: "stale",
         request_cache: ["default", "default"],
-        request_headers: [{"If-Unmodified-Since": new Date().toGMTString()}, {}],
+        request_headers: [{"If-Unmodified-Since": now.toGMTString()}, {}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [true, false],
       },
       {
         name: 'RequestCache "default" mode with an If-Unmodified-Since header is treated similarly to "no-store"',
         state: "fresh",
         request_cache: ["default", "default"],
-        request_headers: [{"If-Unmodified-Since": new Date().toGMTString()}, {}],
+        request_headers: [{"If-Unmodified-Since": now.toGMTString()}, {}],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [true, false],
       },
       {
         name: 'RequestCache "default" mode with an If-Match header is treated similarly to "no-store"',
         state: "stale",
         request_cache: ["default", "default"],
         request_headers: [{}, {"If-Match": '"foo"'}],
@@ -343,17 +344,16 @@
         name: 'RequestCache "reload" mode does store the response in the cache even if a previous response is already stored',
         state: "fresh",
         request_cache: ["default", "reload", "default"],
         expected_validation_headers: [false, false],
         expected_no_cache_headers: [false, true],
       },
     ];
     function make_url(uuid, id, value, content, info) {
-      var now = new Date();
       var dates = {
         fresh: new Date(now.getFullYear() + 1, now.getMonth(), now.getDay()).toGMTString(),
         stale: new Date(now.getFullYear() - 1, now.getMonth(), now.getDay()).toGMTString(),
       };
       var vary = "";
       if ("vary" in info) {
         vary = "&vary=" + info.vary;
       }
@@ -392,17 +392,17 @@
           return response.text();
         }).then(function(text) {
           assert_equals(text, content);
         });
     }
     function make_test(type, info) {
       return function(test) {
         var uuid = token();
-        var identifier = (type == "tag" ? Math.random() : new Date().toGMTString());
+        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);
         }];
         for (var i = 1; i < info.request_cache.length; ++i) {
           fetch_functions.push(function(idx) {
             var init = {cache: info.request_cache[idx]};