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', {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', {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', {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 success.'
); |
| 106 }); |
| 107 }, 'Cache.addAll with string URL arguments'); |
| 108 |
| 109 cache_test(function(cache) { |
| 110 // Assumes the existence of simple.txt and blank.html in the same directory |
| 111 // as this test script. |
| 112 var urls = ['simple.txt', self.location.href, 'blank.html']; |
| 113 var requests = urls.map(function(url) { |
| 114 return new Request(url); |
| 115 }); |
| 116 return cache.addAll(requests) |
| 117 .then(function(result) { |
| 118 assert_equals(result, undefined, |
| 119 'Cache.addAll should resolve with undefined on ' + |
| 120 'success.'); |
| 121 }); |
| 122 }, 'Cache.addAll with Request arguments'); |
| 123 |
| 124 cache_test(function(cache) { |
| 125 // Assumes that simple.txt and blank.html exist. The second |
| 126 // resource does not. |
| 127 var urls = ['simple.txt', 'this-resource-should-not-exist', 'blank.html']; |
| 128 var requests = urls.map(function(url) { |
| 129 return new Request(url); |
| 130 }); |
| 131 return cache.addAll(requests) |
| 132 .then(function(result) { |
| 133 assert_equals(result, undefined, |
| 134 'Cache.addAll should resolve with undefined on ' + |
| 135 'success.'); |
| 136 }); |
| 137 }, 'Cache.addAll with a mix of succeeding and failing requests'); |
| 138 |
| 139 cache_test(function(cache) { |
| 140 var request = new Request('simple.txt'); |
| 141 return assert_promise_rejects( |
| 142 cache.addAll([request, request]), |
| 143 new TypeError(), |
| 144 'Cache.addAll should throw TypeError if the same request is added ' + |
| 145 'twice.'); |
| 146 }, 'Cache.addAll called with the same Request object specified twice'); |
OLD | NEW |