Bug 1147184 - Extend the tests for Cache.put; r=bkelly
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 24 Mar 2015 18:44:47 -0400
changeset 264627 d71343862e8dbf270231cf5144b339b4bb043c5a
parent 264626 0bf7f53464d6a587eb5bed4f1027facea3ba206e
child 264628 568da0ccb3adad33ce9262141b33fcce6fbf3f1e
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1147184
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 1147184 - Extend the tests for Cache.put; r=bkelly
dom/cache/test/mochitest/test_cache_put.js
--- a/dom/cache/test/mochitest/test_cache_put.js
+++ b/dom/cache/test/mochitest/test_cache_put.js
@@ -10,17 +10,41 @@ Promise.all([fetch(url),
   is(undefined, result, 'Successful put() should resolve undefined');
   return cache.match(url);
 }).then(function(response) {
   ok(response, 'match() should find resppnse that was previously put()');
   ok(response.url.endsWith(url), 'matched response should match original url');
   return Promise.all([fetchResponse.text(),
                       response.text()]);
 }).then(function(results) {
-  // suppress large assert spam unless its relevent
+  // suppress large assert spam unless it's relevent
   if (results[0] !== results[1]) {
     is(results[0], results[1], 'stored response body should match original');
   }
+
+  // Now, try to overwrite the request with a different response object.
+  return cache.put(url, new Response("overwritten"));
+}).then(function() {
+  return cache.matchAll(url);
+}).then(function(result) {
+  is(result.length, 1, "Only one entry should exist");
+  return result[0].text();
+}).then(function(body) {
+  is(body, "overwritten", "The cache entry should be successfully overwritten");
+
+  // Now, try to write a URL with a fragment
+  return cache.put(url + "#fragment", new Response("more overwritten"));
+}).then(function() {
+  return cache.matchAll(url + "#differentFragment");
+}).then(function(result) {
+  is(result.length, 1, "Only one entry should exist");
+  return result[0].text();
+}).then(function(body) {
+  is(body, "more overwritten", "The cache entry should be successfully overwritten");
+
+  // TODO: Verify that trying to store a response with an error raises a TypeError
+  // when bug 1147178 is fixed.
+
   return caches.delete('putter' + context);
 }).then(function(deleted) {
   ok(deleted, "The cache should be deleted successfully");
   testDone();
 });