Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/cachestorage/script-tests/cache-add.js

Issue 1926813004: Replace assert_promise_rejects with upstream promise_rejects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update testharness.js and rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('/resources/testharness.js'); 2 importScripts('/resources/testharness.js');
3 importScripts('/resources/testharness-helpers.js'); 3 importScripts('/resources/testharness-helpers.js');
4 importScripts('../resources/test-helpers.js'); 4 importScripts('../resources/test-helpers.js');
5 } 5 }
6 6
7 cache_test(function(cache) { 7 cache_test(function(cache, test) {
8 return assert_promise_rejects( 8 return promise_rejects(
jsbell 2016/04/29 17:39:07 I don't suppose you want to make the same changes
9 test,
10 new TypeError(),
9 cache.add(), 11 cache.add(),
10 new TypeError(),
11 'Cache.add should throw a TypeError when no arguments are given.'); 12 'Cache.add should throw a TypeError when no arguments are given.');
12 }, 'Cache.add called with no arguments'); 13 }, 'Cache.add called with no arguments');
13 14
14 cache_test(function(cache) { 15 cache_test(function(cache) {
15 return cache.add('../resources/simple.txt') 16 return cache.add('../resources/simple.txt')
16 .then(function(result) { 17 .then(function(result) {
17 assert_equals(result, undefined, 18 assert_equals(result, undefined,
18 'Cache.add should resolve with undefined on success.'); 19 'Cache.add should resolve with undefined on success.');
19 return cache.match('../resources/simple.txt'); 20 return cache.match('../resources/simple.txt');
20 }) 21 })
21 .then(function(response) { 22 .then(function(response) {
22 assert_class_string(response, 'Response', 23 assert_class_string(response, 'Response',
23 'Cache.add should put a resource in the cache.'); 24 'Cache.add should put a resource in the cache.');
24 return response.text(); 25 return response.text();
25 }) 26 })
26 .then(function(body) { 27 .then(function(body) {
27 assert_equals(body, 'a simple text file\n', 28 assert_equals(body, 'a simple text file\n',
28 'Cache.add should retrieve the correct body.'); 29 'Cache.add should retrieve the correct body.');
29 }); 30 });
30 }, 'Cache.add called with relative URL specified as a string'); 31 }, 'Cache.add called with relative URL specified as a string');
31 32
32 cache_test(function(cache) { 33 cache_test(function(cache, test) {
33 return assert_promise_rejects( 34 return promise_rejects(
35 test,
36 new TypeError(),
34 cache.add('javascript://this-is-not-http-mmkay'), 37 cache.add('javascript://this-is-not-http-mmkay'),
35 new TypeError(),
36 'Cache.add should throw a TypeError for non-HTTP/HTTPS URLs.'); 38 'Cache.add should throw a TypeError for non-HTTP/HTTPS URLs.');
37 }, 'Cache.add called with non-HTTP/HTTPS URL'); 39 }, 'Cache.add called with non-HTTP/HTTPS URL');
38 40
39 cache_test(function(cache) { 41 cache_test(function(cache) {
40 var request = new Request('../resources/simple.txt'); 42 var request = new Request('../resources/simple.txt');
41 return cache.add(request) 43 return cache.add(request)
42 .then(function(result) { 44 .then(function(result) {
43 assert_equals(result, undefined, 45 assert_equals(result, undefined,
44 'Cache.add should resolve with undefined on success.'); 46 'Cache.add should resolve with undefined on success.');
45 }); 47 });
46 }, 'Cache.add called with Request object'); 48 }, 'Cache.add called with Request object');
47 49
48 cache_test(function(cache) { 50 cache_test(function(cache, test) {
49 var request = new Request('../resources/simple.txt', 51 var request = new Request('../resources/simple.txt',
50 {method: 'POST', body: 'This is a body.'}); 52 {method: 'POST', body: 'This is a body.'});
51 return assert_promise_rejects( 53 return promise_rejects(
54 test,
55 new TypeError(),
52 cache.add(request), 56 cache.add(request),
53 new TypeError(),
54 'Cache.add should throw a TypeError for non-GET requests.'); 57 'Cache.add should throw a TypeError for non-GET requests.');
55 }, 'Cache.add called with POST request'); 58 }, 'Cache.add called with POST request');
56 59
57 cache_test(function(cache) { 60 cache_test(function(cache) {
58 var request = new Request('../resources/simple.txt'); 61 var request = new Request('../resources/simple.txt');
59 return cache.add(request) 62 return cache.add(request)
60 .then(function(result) { 63 .then(function(result) {
61 assert_equals(result, undefined, 64 assert_equals(result, undefined,
62 'Cache.add should resolve with undefined on success.'); 65 'Cache.add should resolve with undefined on success.');
63 }) 66 })
(...skipping 10 matching lines...) Expand all
74 var request = new Request('../resources/simple.txt'); 77 var request = new Request('../resources/simple.txt');
75 return request.text() 78 return request.text()
76 .then(function() { 79 .then(function() {
77 assert_false(request.bodyUsed); 80 assert_false(request.bodyUsed);
78 }) 81 })
79 .then(function() { 82 .then(function() {
80 return cache.add(request); 83 return cache.add(request);
81 }); 84 });
82 }, 'Cache.add called with Request object with a used body'); 85 }, 'Cache.add called with Request object with a used body');
83 86
84 cache_test(function(cache) { 87 cache_test(function(cache, test) {
85 return assert_promise_rejects( 88 return promise_rejects(
89 test,
90 new TypeError(),
86 cache.add('this-does-not-exist-please-dont-create-it'), 91 cache.add('this-does-not-exist-please-dont-create-it'),
87 new TypeError(),
88 'Cache.add should reject if response is !ok'); 92 'Cache.add should reject if response is !ok');
89 }, 'Cache.add with request that results in a status of 404'); 93 }, 'Cache.add with request that results in a status of 404');
90 94
91 cache_test(function(cache) { 95 cache_test(function(cache, test) {
92 return assert_promise_rejects( 96 return promise_rejects(
97 test,
98 new TypeError(),
93 cache.add('../resources/fetch-status.php?status=500'), 99 cache.add('../resources/fetch-status.php?status=500'),
94 new TypeError(),
95 'Cache.add should reject if response is !ok'); 100 'Cache.add should reject if response is !ok');
96 }, 'Cache.add with request that results in a status of 500'); 101 }, 'Cache.add with request that results in a status of 500');
97 102
98 cache_test(function(cache) { 103 cache_test(function(cache, test) {
99 return assert_promise_rejects( 104 return promise_rejects(
105 test,
106 new TypeError(),
100 cache.addAll(), 107 cache.addAll(),
101 new TypeError(),
102 'Cache.addAll with no arguments should throw TypeError.'); 108 'Cache.addAll with no arguments should throw TypeError.');
103 }, 'Cache.addAll with no arguments'); 109 }, 'Cache.addAll with no arguments');
104 110
105 cache_test(function(cache) { 111 cache_test(function(cache, test) {
106 // Assumes the existence of ../resources/simple.txt and ../resources/blank.h tml 112 // Assumes the existence of ../resources/simple.txt and ../resources/blank.h tml
107 var urls = ['../resources/simple.txt', undefined, '../resources/blank.html'] ; 113 var urls = ['../resources/simple.txt', undefined, '../resources/blank.html'] ;
108 return assert_promise_rejects( 114 return promise_rejects(
115 test,
116 new TypeError(),
109 cache.addAll(), 117 cache.addAll(),
110 new TypeError(),
111 'Cache.addAll should throw TypeError for an undefined argument.'); 118 'Cache.addAll should throw TypeError for an undefined argument.');
112 }, 'Cache.addAll with a mix of valid and undefined arguments'); 119 }, 'Cache.addAll with a mix of valid and undefined arguments');
113 120
114 cache_test(function(cache) { 121 cache_test(function(cache) {
115 return cache.addAll([]) 122 return cache.addAll([])
116 .then(function(result) { 123 .then(function(result) {
117 assert_equals(result, undefined, 124 assert_equals(result, undefined,
118 'Cache.addAll should resolve with undefined on ' + 125 'Cache.addAll should resolve with undefined on ' +
119 'success.'); 126 'success.');
120 return cache.keys(); 127 return cache.keys();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 .then(function(bodies) { 202 .then(function(bodies) {
196 assert_equals( 203 assert_equals(
197 bodies[0], 'a simple text file\n', 204 bodies[0], 'a simple text file\n',
198 'Cache.add should retrieve the correct body.'); 205 'Cache.add should retrieve the correct body.');
199 assert_equals( 206 assert_equals(
200 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n', 207 bodies[2], '<!DOCTYPE html>\n<title>Empty doc</title>\n',
201 'Cache.add should retrieve the correct body.'); 208 'Cache.add should retrieve the correct body.');
202 }); 209 });
203 }, 'Cache.addAll with Request arguments'); 210 }, 'Cache.addAll with Request arguments');
204 211
205 cache_test(function(cache) { 212 cache_test(function(cache, test) {
206 // Assumes that ../resources/simple.txt and ../resources/blank.html exist. 213 // Assumes that ../resources/simple.txt and ../resources/blank.html exist.
207 // The second resource does not. 214 // The second resource does not.
208 var urls = ['../resources/simple.txt', 215 var urls = ['../resources/simple.txt',
209 'this-resource-should-not-exist', 216 'this-resource-should-not-exist',
210 '../resources/blank.html']; 217 '../resources/blank.html'];
211 var requests = urls.map(function(url) { 218 var requests = urls.map(function(url) {
212 return new Request(url); 219 return new Request(url);
213 }); 220 });
214 return assert_promise_rejects( 221 return promise_rejects(
222 test,
223 new TypeError(),
215 cache.addAll(requests), 224 cache.addAll(requests),
216 new TypeError(),
217 'Cache.addAll should reject with TypeError if any request fails') 225 'Cache.addAll should reject with TypeError if any request fails')
218 .then(function() { 226 .then(function() {
219 return Promise.all(urls.map(function(url) { 227 return Promise.all(urls.map(function(url) {
220 return cache.match(url); 228 return cache.match(url);
221 })); 229 }));
222 }) 230 })
223 .then(function(matches) { 231 .then(function(matches) {
224 assert_array_equals( 232 assert_array_equals(
225 matches, 233 matches,
226 [undefined, undefined, undefined], 234 [undefined, undefined, undefined],
227 'If any response fails, no response should be added to cache'); 235 'If any response fails, no response should be added to cache');
228 }); 236 });
229 }, 'Cache.addAll with a mix of succeeding and failing requests'); 237 }, 'Cache.addAll with a mix of succeeding and failing requests');
230 238
231 cache_test(function(cache) { 239 cache_test(function(cache, test) {
232 var request = new Request('../resources/simple.txt'); 240 var request = new Request('../resources/simple.txt');
233 return assert_promise_rejects( 241 return promise_rejects(
242 test,
243 'InvalidStateError',
234 cache.addAll([request, request]), 244 cache.addAll([request, request]),
235 'InvalidStateError',
236 'Cache.addAll should throw InvalidStateError if the same request is added ' + 245 'Cache.addAll should throw InvalidStateError if the same request is added ' +
237 'twice.'); 246 'twice.');
238 }, 'Cache.addAll called with the same Request object specified twice'); 247 }, 'Cache.addAll called with the same Request object specified twice');
239 248
240 done(); 249 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698