Bug 1146202 - Add a test for the handling of ignoreVary in Cache.keys; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 22 Mar 2015 20:38:19 -0400
changeset 235152 a6b8120d09f0
parent 235151 f0afd7c244cc
child 235153 5c92ecf1fcda
push id28467
push userryanvm@gmail.com
push dateTue, 24 Mar 2015 15:35:47 +0000
treeherdermozilla-central@08f09b24606e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1146202
milestone39.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 1146202 - Add a test for the handling of ignoreVary in Cache.keys; r=bkelly
dom/cache/test/mochitest/test_cache_keys.js
dom/cache/test/mochitest/test_cache_match_vary.js
--- a/dom/cache/test/mochitest/test_cache_keys.js
+++ b/dom/cache/test/mochitest/test_cache_keys.js
@@ -52,18 +52,16 @@ caches.open(name).then(function(cache) {
       })
   );
 }).then(function() {
   // But HEAD should be allowed even without ignoreMethod
   return c.keys(new Request(tests[0], {method: "HEAD"}));
 }).then(function(keys) {
   is(keys.length, 1, "One match should be found");
   ok(keys[0].url.indexOf(tests[0]) >= 0, "Valid URL");
-  // TODO: Add tests for ignoreVary
-
   // Make sure cacheName is ignored.
   return c.keys(tests[0], {cacheName: "non-existing-cache"});
 }).then(function(keys) {
   is(keys.length, 1, "One match should be found");
   ok(keys[0].url.indexOf(tests[0]) >= 0, "Valid URL");
   return caches.delete(name);
 }).then(function(deleted) {
   ok(deleted, "The cache should be successfully deleted");
--- a/dom/cache/test/mochitest/test_cache_match_vary.js
+++ b/dom/cache/test/mochitest/test_cache_match_vary.js
@@ -74,16 +74,43 @@ function testBasics() {
       // Ensure that searching with a non-matching value for the Cookie header but with ignoreVary set succeeds.
       return test.cache.match(new Request(requestURL, {headers: {"Cookie": "foo=bar"}}),
                               {ignoreVary: true});
     }).then(function(r) {
       return checkResponse(r, test.response, test.responseText);
     });
 }
 
+function testBasicKeys() {
+  function checkRequest(reqs) {
+    is(reqs.length, 1, "One request expected");
+    ok(reqs[0].url.indexOf(requestURL) >= 0, "The correct request expected");
+    ok(reqs[0].headers.get("WhatToVary"), "Cookie", "The correct request headers expected");
+  }
+  var test;
+  return setupTest({"WhatToVary": "Cookie"})
+    .then(function(t) {
+      test = t;
+      // Ensure that searching without specifying a Cookie header succeeds.
+      return test.cache.keys(requestURL);
+    }).then(function(r) {
+      return checkRequest(r);
+    }).then(function() {
+      // Ensure that searching with a non-matching value for the Cookie header fails.
+      return test.cache.keys(new Request(requestURL, {headers: {"Cookie": "foo=bar"}}));
+    }).then(function(r) {
+      is(r.length, 0, "Searching for a request with an unknown Vary header should not succeed");
+      // Ensure that searching with a non-matching value for the Cookie header but with ignoreVary set succeeds.
+      return test.cache.keys(new Request(requestURL, {headers: {"Cookie": "foo=bar"}}),
+                             {ignoreVary: true});
+    }).then(function(r) {
+      return checkRequest(r);
+    });
+}
+
 function testStar() {
   var test;
   return setupTest({"WhatToVary": "*", "Cookie": "foo=bar"})
     .then(function(t) {
       test = t;
       // Ensure that searching with a different Cookie header with Vary:* succeeds.
       return test.cache.match(new Request(requestURL, {headers: {"Cookie": "bar=baz"}}));
     }).then(function(r) {
@@ -257,16 +284,18 @@ function testMultipleCacheEntries() {
 // Make sure to clean up after each test step.
 function step(testPromise) {
   return testPromise.then(function() {
     caches.delete(name);
   });
 }
 
 step(testBasics()).then(function() {
+  return step(testBasicKeys());
+}).then(function() {
   return step(testStar());
 }).then(function() {
   return step(testMatch());
 }).then(function() {
   return step(testStarAndAnotherHeader());
 }).then(function() {
   return step(testInvalidHeaderName());
 }).then(function() {