Bug 1144337 - Add tests to ensure that cacheName is only honored on CacheStorage, and not Cache; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 17 Mar 2015 16:38:59 -0400
changeset 252110 c89f330bf7818b3150efc971e35b5ffe450c835f
parent 252109 9b47ec7ffe71b8da76d3e3bd0915ce82513bfe78
child 252111 324071d6d325ad1ecd6aa14e91e010734c1bd28a
push id1174
push usernsm.nikhil@gmail.com
push dateSun, 22 Mar 2015 01:24:25 +0000
reviewersbkelly
bugs1144337
milestone39.0a1
Bug 1144337 - Add tests to ensure that cacheName is only honored on CacheStorage, and not Cache; r=bkelly
dom/cache/test/mochitest/test_cache_matchAll_request.js
dom/cache/test/mochitest/test_cache_match_request.js
--- a/dom/cache/test/mochitest/test_cache_matchAll_request.js
+++ b/dom/cache/test/mochitest/test_cache_matchAll_request.js
@@ -96,17 +96,17 @@ function testRequest(request1, request2,
     );
   }).then(function() {
     return c.matchAll(requestWithDifferentFragment);
   }).then(function(r) {
     is(r.length, 1, "Should only find 1 item");
     return checkResponse(r[0], response1, response1Text);
   }).then(function() {
     return c.matchAll(requestWithAlternateQueryString,
-                      {ignoreSearch: true, cacheName: name});
+                      {ignoreSearch: true});
   }).then(function(r) {
     is(r.length, 2, "Should find 2 items");
     return Promise.all([
       checkResponse(r[0], response1, response1Text),
       checkResponse(r[1], response3, response3Text)
     ]);
   }).then(function() {
     return c.matchAll(request3);
@@ -117,26 +117,35 @@ function testRequest(request1, request2,
     return c.matchAll();
   }).then(function(r) {
     is(r.length, 2, "Should find 2 items");
     return Promise.all([
       checkResponse(r[0], response1, response1Text),
       checkResponse(r[1], response3, response3Text)
     ]);
   }).then(function() {
-    return c.matchAll({cacheName: name + "mambojambo"});
-  }).then(function(r) {
-    is(r.length, 0, "Searching in the wrong cache should not succeed");
+    return caches.match(request1, {cacheName: name + "mambojambo"})
+      .then(function() {
+        ok(false, "Promise should be rejected");
+      }, function(err) {
+        is(err.name, "NotFoundError", "Searching in the wrong cache should not succeed");
+      });
   }).then(function() {
     return c.matchAll(unknownRequest);
   }).then(function(r) {
     is(r.length, 0, "Searching for an unknown request should not succeed");
-    return c.matchAll(unknownRequest, {cacheName: name});
+    return caches.match(unknownRequest, {cacheName: name});
   }).then(function(r) {
-    is(r.length, 0, "Searching for an unknown request should not succeed");
+    is(typeof r, "undefined", "Searching for an unknown request should not succeed");
+    // Make sure that cacheName is ignored on Cache
+    return c.matchAll(request1, {cacheName: name + "mambojambo"});
+  }).then(function(r) {
+    is(r.length, 1, "Should only find 1 item");
+    return checkResponse(r[0], response1, response1Text);
+  }).then(function() {
     return caches.delete(name);
   }).then(function(success) {
     ok(success, "We should be able to delete the cache successfully");
     // Make sure that the cache is still usable after deletion.
     return c.matchAll(request1);
   }).then(function(r) {
     is(r.length, 1, "Should only find 1 item");
     return checkResponse(r[0], response1, response1Text);
--- a/dom/cache/test/mochitest/test_cache_match_request.js
+++ b/dom/cache/test/mochitest/test_cache_match_request.js
@@ -98,16 +98,21 @@ function testRequest(request, unknownReq
   }).then(function() {
     return caches.match(request, {cacheName: name + "mambojambo"})
       .then(function() {
         ok(false, "Promise should be rejected");
       }, function(err) {
         is(err.name, "NotFoundError", "Searching in the wrong cache should not succeed");
       });
   }).then(function() {
+    // Make sure that cacheName is ignored on Cache
+    return c.match(request, {cacheName: name + "mambojambo"});
+  }).then(function(r) {
+    return checkResponse(r);
+  }).then(function() {
     return c.match(unknownRequest);
   }).then(function(r) {
     is(typeof r, "undefined", "Searching for an unknown request should not succeed");
     return caches.match(unknownRequest);
   }).then(function(r) {
     is(typeof r, "undefined", "Searching for an unknown request should not succeed");
     return caches.match(unknownRequest, {cacheName: name});
   }).then(function(r) {