Bug 1320871 Add a wpt test verifying Cache API Response objects can be cloned and read. r=asuth
authorBen Kelly <ben@wanderview.com>
Fri, 02 Dec 2016 10:41:33 -0800
changeset 325117 e132c0d60a690be93cff96adf362c2b9afcda524
parent 325116 d366e6c749d64283bfc6b947b2f015e524a32420
child 325118 f49a4f2953f35a1161d79902ba71e26592371c3d
push id84600
push userbkelly@mozilla.com
push dateFri, 02 Dec 2016 21:38:19 +0000
treeherdermozilla-inbound@e132c0d60a69 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1320871
milestone53.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 1320871 Add a wpt test verifying Cache API Response objects can be cloned and read. r=asuth
testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-match.js
--- a/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-match.js
+++ b/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-match.js
@@ -185,9 +185,33 @@ prepopulated_cache_test(simple_entries, 
       .then(function(result) {
           assert_response_equals(
               result, entries.error_response.response,
               'Cache.match should return a Response object that has the ' +
                   'same properties as a stored network error response.');
         });
   }, 'Cache.match with a network error Response');
 
+cache_test(function(cache) {
+    // This test validates that we can get a Response from the Cache API,
+    // clone it, and read just one side of the clone.  This was previously
+    // bugged in FF for Responses with large bodies.
+    var data = [];
+    data.length = 80 * 1024;
+    data.fill('F');
+    var response;
+    return cache.put('/', new Response(data.toString()))
+      .then(function(result) {
+          return cache.match('/');
+        })
+      .then(function(r) {
+          // Make sure the original response is not GC'd.
+          response = r;
+          // Return only the clone.  We purposefully test that the other
+          // half of the clone does not need to be read here.
+          return response.clone().text();
+        })
+      .then(function(text) {
+          assert_equals(text, data.toString(), 'cloned body text can be read correctly');
+        })
+  }, 'Cache produces large Responses that can be cloned and read correctly.');
+
 done();