Bug 1264178 - Part 3: Add a test in test_cache_keys and remove the added test in P1. r=bkelly
authorTom Tung <ttung@mozilla.com>
Thu, 03 Nov 2016 16:18:08 +0800
changeset 435809 de39b88af6c226c8cbe2ba0e3e14a8d0dcc7ebe1
parent 435808 3363a134f720f49c2f75cc953a297e5981cfea1f
child 435810 c5f08b96183010934b96dbb637933d77eac6212b
push id35126
push userbmo:mh+mozilla@glandium.org
push dateWed, 09 Nov 2016 06:43:04 +0000
reviewersbkelly
bugs1264178
milestone52.0a1
Bug 1264178 - Part 3: Add a test in test_cache_keys and remove the added test in P1. r=bkelly
dom/cache/test/mochitest/test_cache_keys.js
dom/cache/test/mochitest/test_cache_match_request.js
--- a/dom/cache/test/mochitest/test_cache_keys.js
+++ b/dom/cache/test/mochitest/test_cache_keys.js
@@ -10,16 +10,21 @@ caches.open(name).then(function(cache) {
   c = cache;
   return c.addAll(tests);
 }).then(function() {
   // Add another cache entry using Cache.add
   var another = "//mochi.test:8888/?yetanother" + context;
   tests.push(another);
   return c.add(another);
 }).then(function() {
+  // Add another cache entry with URL fragment using Cache.add
+  var anotherWithFragment = "//mochi.test:8888/?fragment" + context + "#fragment";
+  tests.push(anotherWithFragment);
+  return c.add(anotherWithFragment);
+}).then(function() {
   return c.keys();
 }).then(function(keys) {
   is(keys.length, tests.length, "Same number of elements");
   // Verify both the insertion order of the requests and their validity.
   keys.forEach(function(r, i) {
     ok(r instanceof Request, "Valid request object");
     ok(r.url.indexOf(tests[i]) >= 0, "Valid URL");
   });
--- a/dom/cache/test/mochitest/test_cache_match_request.js
+++ b/dom/cache/test/mochitest/test_cache_match_request.js
@@ -20,46 +20,16 @@ function checkResponse(r, expectedBody) 
      "Both responses should have the same status text");
   return r.text().then(function(text) {
     // Avoid dumping out the large response text to the log if they're equal.
     if (text !== expectedBody) {
       is(text, responseText, "The response body should be correct");
     }
   });
 }
-function checkFragment(cache, request, requestWithDifferentFragment) {
-  var req1 = new Request(request);
-  var req2 = new Request(requestWithDifferentFragment);
-  var res1 = new Response("Hello World1");
-  var res2 = new Response("Hello World2");
-
-  // Ensure both request and requestWithDifferentFragment have fragment.
-  ok(req1.url.includes('#fragment'), "Request URL should keep the fragment.");
-  ok(req2.url.includes('#other'), "Request URL should keep the fragment.");
-
-  cache.put(req1, res1).then(() => cache.put(req2, res2))
-  .then(function () {
-    // Test for ensuring we get the fragment from cache request.
-    cache.keys(req2).then(function(keys) {
-      keys.forEach(function(r, index, array) {
-        is(req2.url, r.url, "Request URL should be the same");
-      });
-    })
-    return cache.match(req1);
-  }).then(function (resp) {
-    return resp.text();
-  }).then(function (body) {
-    // Test for ensuring only the last response will be cached.
-    is(body, "Hello World2", "Response should be the same as last one");
-    cache.delete(req1);
-    cache.delete(req2);
-  });
-  return Promise.resolve();
-}
-
 fetch(new Request(request)).then(function(r) {
   response = r;
   return response.text();
 }).then(function(text) {
   responseText = text;
   return testRequest(request, unknownRequest, requestWithAltQS,
                      request.url.replace("#fragment", "#other"));
 }).then(function() {
@@ -68,18 +38,16 @@ fetch(new Request(request)).then(functio
 }).then(function() {
   testDone();
 });
 // The request argument can either be a URL string, or a Request object.
 function testRequest(request, unknownRequest, requestWithAlternateQueryString,
                      requestWithDifferentFragment) {
   return caches.open(name).then(function(cache) {
     c = cache;
-    return checkFragment(c, request, requestWithDifferentFragment);
-  }).then(function() {
     return c.add(request);
   }).then(function() {
     return Promise.all(
       ["HEAD", "POST", "PUT", "DELETE", "OPTIONS"]
         .map(function(method) {
           var r = new Request(request, {method: method});
           return c.add(r)
             .then(function() {