| OLD | NEW |
| (Empty) |
| 1 importScripts('worker-testharness.js'); | |
| 2 importScripts('/resources/testharness-helpers.js'); | |
| 3 | |
| 4 cache_test(function(cache) { | |
| 5 return assert_promise_rejects( | |
| 6 cache.add(), | |
| 7 new TypeError(), | |
| 8 'Cache.add should throw a TypeError when no arguments are given.'); | |
| 9 }, 'Cache.add called with no arguments'); | |
| 10 | |
| 11 cache_test(function(cache) { | |
| 12 return cache.add('simple.txt') | |
| 13 .then(function(result) { | |
| 14 assert_equals(result, undefined, | |
| 15 'Cache.add should resolve with undefined on success.'); | |
| 16 }); | |
| 17 }, 'Cache.add called with relative URL specified as a string'); | |
| 18 | |
| 19 cache_test(function(cache) { | |
| 20 return assert_promise_rejects( | |
| 21 cache.add('javascript://this-is-not-http-mmkay'), | |
| 22 'NetworkError', | |
| 23 'Cache.add should throw a NetworkError for non-HTTP/HTTPS URLs.'); | |
| 24 }, 'Cache.add called with non-HTTP/HTTPS URL'); | |
| 25 | |
| 26 cache_test(function(cache) { | |
| 27 var request = new Request('simple.txt', {method: 'POST', body: 'Hello'}); | |
| 28 return cache.add(request) | |
| 29 .then(function(result) { | |
| 30 assert_equals(result, undefined, | |
| 31 'Cache.add should resolve with undefined on success.'); | |
| 32 }); | |
| 33 }, 'Cache.add called with Request object'); | |
| 34 | |
| 35 cache_test(function(cache) { | |
| 36 var request = new Request('simple.txt', {method: 'POST', body: 'Hello'}); | |
| 37 return request.text() | |
| 38 .then(function() { | |
| 39 assert_true(request.bodyUsed); | |
| 40 }) | |
| 41 .then(function() { | |
| 42 return assert_promise_rejects( | |
| 43 cache.add(request), | |
| 44 new TypeError(), | |
| 45 'Cache.add with a Request object with a used body should reject ' + | |
| 46 'with a TypeError.'); | |
| 47 }); | |
| 48 }, 'Cache.add called with Request object with a used body'); | |
| 49 | |
| 50 cache_test(function(cache) { | |
| 51 var request = new Request('simple.txt', {method: 'POST', body: 'Hello'}); | |
| 52 return cache.add(request) | |
| 53 .then(function(result) { | |
| 54 assert_equals(result, undefined, | |
| 55 'Cache.add should resolve with undefined on success.'); | |
| 56 }) | |
| 57 .then(function() { | |
| 58 return assert_promise_rejects( | |
| 59 cache.add(request), | |
| 60 new TypeError(), | |
| 61 'Cache.add should throw TypeError if same request is added twice.'); | |
| 62 }); | |
| 63 }, 'Cache.add called twice with the same Request object'); | |
| 64 | |
| 65 cache_test(function(cache) { | |
| 66 return cache.add('this-does-not-exist-please-dont-create-it') | |
| 67 .then(function(result) { | |
| 68 assert_equals(result, undefined, | |
| 69 'Cache.add should resolve with undefined on success.'); | |
| 70 }); | |
| 71 }, 'Cache.add with request that results in a status of 404'); | |
| 72 | |
| 73 cache_test(function(cache) { | |
| 74 return cache.add('fetch-status.php?status=500') | |
| 75 .then(function(result) { | |
| 76 assert_equals(result, undefined, | |
| 77 'Cache.add should resolve with undefined on success.'); | |
| 78 }); | |
| 79 }, 'Cache.add with request that results in a status of 500'); | |
| 80 | |
| 81 cache_test(function(cache) { | |
| 82 return assert_promise_rejects( | |
| 83 cache.addAll(), | |
| 84 new TypeError(), | |
| 85 'Cache.addAll with no arguments should throw TypeError.'); | |
| 86 }, 'Cache.addAll with no arguments'); | |
| 87 | |
| 88 cache_test(function(cache) { | |
| 89 // Assumes the existence of simple.txt and blank.html in the same directory | |
| 90 // as this test script. | |
| 91 var urls = ['simple.txt', undefined, 'blank.html']; | |
| 92 return assert_promise_rejects( | |
| 93 cache.addAll(), | |
| 94 new TypeError(), | |
| 95 'Cache.addAll should throw TypeError for an undefined argument.'); | |
| 96 }, 'Cache.addAll with a mix of valid and undefined arguments'); | |
| 97 | |
| 98 cache_test(function(cache) { | |
| 99 // Assumes the existence of simple.txt and blank.html in the same directory | |
| 100 // as this test script. | |
| 101 var urls = ['simple.txt', self.location.href, 'blank.html']; | |
| 102 return cache.addAll(urls) | |
| 103 .then(function(result) { | |
| 104 assert_equals(result, undefined, | |
| 105 'Cache.addAll should resolve with undefined on ' + | |
| 106 'success.'); | |
| 107 }); | |
| 108 }, 'Cache.addAll with string URL arguments'); | |
| 109 | |
| 110 cache_test(function(cache) { | |
| 111 // Assumes the existence of simple.txt and blank.html in the same directory | |
| 112 // as this test script. | |
| 113 var urls = ['simple.txt', self.location.href, 'blank.html']; | |
| 114 var requests = urls.map(function(url) { | |
| 115 return new Request(url); | |
| 116 }); | |
| 117 return cache.addAll(requests) | |
| 118 .then(function(result) { | |
| 119 assert_equals(result, undefined, | |
| 120 'Cache.addAll should resolve with undefined on ' + | |
| 121 'success.'); | |
| 122 }); | |
| 123 }, 'Cache.addAll with Request arguments'); | |
| 124 | |
| 125 cache_test(function(cache) { | |
| 126 // Assumes that simple.txt and blank.html exist. The second | |
| 127 // resource does not. | |
| 128 var urls = ['simple.txt', 'this-resource-should-not-exist', 'blank.html']; | |
| 129 var requests = urls.map(function(url) { | |
| 130 return new Request(url); | |
| 131 }); | |
| 132 return cache.addAll(requests) | |
| 133 .then(function(result) { | |
| 134 assert_equals(result, undefined, | |
| 135 'Cache.addAll should resolve with undefined on ' + | |
| 136 'success.'); | |
| 137 }); | |
| 138 }, 'Cache.addAll with a mix of succeeding and failing requests'); | |
| 139 | |
| 140 cache_test(function(cache) { | |
| 141 var request = new Request('simple.txt'); | |
| 142 return assert_promise_rejects( | |
| 143 cache.addAll([request, request]), | |
| 144 new TypeError(), | |
| 145 'Cache.addAll should throw TypeError if the same request is added ' + | |
| 146 'twice.'); | |
| 147 }, 'Cache.addAll called with the same Request object specified twice'); | |
| OLD | NEW |