Bug 1244764 P4 Update cache wpt tests for new add()/addAll() behavior. r=ehsan
authorBen Kelly <ben@wanderview.com>
Thu, 04 Feb 2016 07:59:52 -0800
changeset 283112 c9e84bd323962fe1ff5b418af11d26de58907344
parent 283111 0517781f5ff7c96cd47addcce6e703d8c350dd5b
child 283113 30210bbd013e29fd60e3b87f8ffa4997a95fd235
push id29974
push usercbook@mozilla.com
push dateFri, 05 Feb 2016 10:53:43 +0000
treeherdermozilla-central@1dbe350b57b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1244764
milestone47.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 1244764 P4 Update cache wpt tests for new add()/addAll() behavior. r=ehsan
testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js
--- a/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js
+++ b/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-add.js
@@ -77,29 +77,27 @@ cache_test(function(cache) {
           assert_false(request.bodyUsed);
         })
       .then(function() {
           return cache.add(request);
         });
   }, 'Cache.add with request with null body (not consumed)');
 
 cache_test(function(cache) {
-    return cache.add('this-does-not-exist-please-dont-create-it')
-      .then(function(result) {
-          assert_equals(result, undefined,
-                        'Cache.add should resolve with undefined on success.');
-        });
+    return assert_promise_rejects(
+      cache.add('this-does-not-exist-please-dont-create-it'),
+      new TypeError(),
+      'Cache.add should reject if response is !ok');
   }, 'Cache.add with request that results in a status of 404');
 
 cache_test(function(cache) {
-    return cache.add('../resources/fetch-status.py?status=500')
-      .then(function(result) {
-          assert_equals(result, undefined,
-                        'Cache.add should resolve with undefined on success.');
-        });
+    return assert_promise_rejects(
+      cache.add('../resources/fetch-status.php?status=500'),
+      new TypeError(),
+      'Cache.add should reject if response is !ok');
   }, 'Cache.add with request that results in a status of 500');
 
 cache_test(function(cache) {
     return assert_promise_rejects(
       cache.addAll(),
       new TypeError(),
       'Cache.addAll with no arguments should throw TypeError.');
   }, 'Cache.addAll with no arguments');
@@ -208,48 +206,29 @@ cache_test(function(cache) {
     // Assumes that ../resources/simple.txt and ../resources/blank.html exist.
     // The second resource does not.
     var urls = ['../resources/simple.txt',
                 'this-resource-should-not-exist',
                 '../resources/blank.html'];
     var requests = urls.map(function(url) {
         return new Request(url);
       });
-    return cache.addAll(requests)
-      .then(function(result) {
-          assert_equals(result, undefined,
-                        'Cache.addAll should resolve with undefined on ' +
-                        'success.');
-          return Promise.all(
-            urls.map(function(url) { return cache.match(url); }));
-        })
-      .then(function(responses) {
-          assert_class_string(
-            responses[0], 'Response',
-            'Cache.addAll should put a resource in the cache.');
-          assert_class_string(
-            responses[1], 'Response',
-            'Cache.addAll should put a resource in the cache.');
-          assert_equals(
-            responses[1].status, 404,
-            'Cache.addAll should put a 404 resource in the cache.');
-          assert_class_string(
-            responses[2], 'Response',
-            'Cache.addAll should put a resource in the cache.');
-          return Promise.all(
-            responses.map(function(response) { return response.text(); }));
-        })
-      .then(function(bodies) {
-          assert_equals(
-            bodies[0], 'a simple text file\n',
-            'Cache.add should retrieve the correct body.');
-          assert_equals(
-            bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n',
-            'Cache.add should retrieve the correct body.');
-        });
+    return assert_promise_rejects(
+      cache.addAll(requests),
+      new TypeError(),
+      'Cache.addAll should reject with TypeError if any request fails')
+      .then(function() {
+          return Promise.all(urls.map(function(url) { return cache.match(url); }));
+      })
+      .then(function(matches) {
+          assert_array_equals(
+            matches,
+            [undefined, undefined, undefined],
+            'If any response fails, no response should be added to cache');
+      });
   }, 'Cache.addAll with a mix of succeeding and failing requests');
 
 cache_test(function(cache) {
     var request = new Request('../resources/simple.txt');
     return assert_promise_rejects(
       cache.addAll([request, request]),
       'InvalidStateError',
       'Cache.addAll should throw InvalidStateError if the same request is added ' +