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

Side by Side Diff: LayoutTests/http/tests/cachestorage/script-tests/cache-put.js

Issue 1295633003: Cache Storage: replace assert_object_equals w/ assert_response_equals (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review feedback and rebased Created 5 years, 4 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 | Annotate | Revision Log
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 var test_url = 'https://example.com/foo'; 7 var test_url = 'https://example.com/foo';
8 var test_body = 'Hello world!'; 8 var test_body = 'Hello world!';
9 9
10 cache_test(function(cache) { 10 cache_test(function(cache) {
(...skipping 12 matching lines...) Expand all
23 var response; 23 var response;
24 return fetch(test_url) 24 return fetch(test_url)
25 .then(function(fetch_result) { 25 .then(function(fetch_result) {
26 response = fetch_result.clone(); 26 response = fetch_result.clone();
27 return cache.put(request, fetch_result); 27 return cache.put(request, fetch_result);
28 }) 28 })
29 .then(function() { 29 .then(function() {
30 return cache.match(test_url); 30 return cache.match(test_url);
31 }) 31 })
32 .then(function(result) { 32 .then(function(result) {
33 assert_object_equals_fixed(result, response, 33 assert_response_equals(result, response,
34 'Cache.put should update the cache with ' + 34 'Cache.put should update the cache with ' +
35 'new request and response.'); 35 'new request and response.');
36 return result.text(); 36 return result.text();
37 }) 37 })
38 .then(function(body) { 38 .then(function(body) {
39 assert_equals(body, 'a simple text file\n', 39 assert_equals(body, 'a simple text file\n',
40 'Cache.put should store response body.'); 40 'Cache.put should store response body.');
41 }); 41 });
42 }, 'Cache.put called with Request and Response from fetch()'); 42 }, 'Cache.put called with Request and Response from fetch()');
43 43
44 cache_test(function(cache) { 44 cache_test(function(cache) {
45 var request = new Request(test_url); 45 var request = new Request(test_url);
(...skipping 22 matching lines...) Expand all
68 }, 'Cache.put with Response without a body'); 68 }, 'Cache.put with Response without a body');
69 69
70 cache_test(function(cache) { 70 cache_test(function(cache) {
71 var request = new Request(test_url); 71 var request = new Request(test_url);
72 var response = new Response(test_body); 72 var response = new Response(test_body);
73 return cache.put(request, response.clone()) 73 return cache.put(request, response.clone())
74 .then(function() { 74 .then(function() {
75 return cache.match(test_url); 75 return cache.match(test_url);
76 }) 76 })
77 .then(function(result) { 77 .then(function(result) {
78 assert_object_equals_fixed(result, response, 78 assert_response_equals(result, response,
79 'Cache.put should update the cache with ' + 79 'Cache.put should update the cache with ' +
80 'new Request and Response.'); 80 'new Request and Response.');
81 }); 81 });
82 }, 'Cache.put with a Response containing an empty URL'); 82 }, 'Cache.put with a Response containing an empty URL');
83 83
84 cache_test(function(cache) { 84 cache_test(function(cache) {
85 var request = new Request(test_url); 85 var request = new Request(test_url);
86 var response = new Response('', { 86 var response = new Response('', {
87 status: 200, 87 status: 200,
88 headers: [['Content-Type', 'text/plain']] 88 headers: [['Content-Type', 'text/plain']]
89 }); 89 });
90 return cache.put(request, response) 90 return cache.put(request, response)
(...skipping 20 matching lines...) Expand all
111 .then(function(fetch_result) { 111 .then(function(fetch_result) {
112 assert_equals(fetch_result.status, 500, 112 assert_equals(fetch_result.status, 500,
113 'Test framework error: The status code should be 500.'); 113 'Test framework error: The status code should be 500.');
114 response = fetch_result.clone(); 114 response = fetch_result.clone();
115 return cache.put(request, fetch_result); 115 return cache.put(request, fetch_result);
116 }) 116 })
117 .then(function() { 117 .then(function() {
118 return cache.match(test_url); 118 return cache.match(test_url);
119 }) 119 })
120 .then(function(result) { 120 .then(function(result) {
121 assert_object_equals_fixed(result, response, 121 assert_response_equals(result, response,
122 'Cache.put should update the cache with ' + 122 'Cache.put should update the cache with ' +
123 'new request and response.'); 123 'new request and response.');
124 return result.text(); 124 return result.text();
125 }) 125 })
126 .then(function(body) { 126 .then(function(body) {
127 assert_equals(body, '', 127 assert_equals(body, '',
128 'Cache.put should store response body.'); 128 'Cache.put should store response body.');
129 }); 129 });
130 }, 'Cache.put with HTTP 500 response'); 130 }, 'Cache.put with HTTP 500 response');
131 131
132 cache_test(function(cache) { 132 cache_test(function(cache) {
133 var alternate_response_body = 'New body'; 133 var alternate_response_body = 'New body';
134 var alternate_response = new Response(alternate_response_body, 134 var alternate_response = new Response(alternate_response_body,
135 { statusText: 'New status' }); 135 { statusText: 'New status' });
136 return cache.put(new Request(test_url), 136 return cache.put(new Request(test_url),
137 new Response('Old body', { statusText: 'Old status' })) 137 new Response('Old body', { statusText: 'Old status' }))
138 .then(function() { 138 .then(function() {
139 return cache.put(new Request(test_url), alternate_response.clone()); 139 return cache.put(new Request(test_url), alternate_response.clone());
140 }) 140 })
141 .then(function() { 141 .then(function() {
142 return cache.match(test_url); 142 return cache.match(test_url);
143 }) 143 })
144 .then(function(result) { 144 .then(function(result) {
145 assert_object_equals_fixed(result, alternate_response, 145 assert_response_equals(result, alternate_response,
146 'Cache.put should replace existing ' + 146 'Cache.put should replace existing ' +
147 'response with new response.'); 147 'response with new response.');
148 return result.text(); 148 return result.text();
149 }) 149 })
150 .then(function(body) { 150 .then(function(body) {
151 assert_equals(body, alternate_response_body, 151 assert_equals(body, alternate_response_body,
152 'Cache put should store new response body.'); 152 'Cache put should store new response body.');
153 }); 153 });
154 }, 'Cache.put called twice with matching Requests and different Responses'); 154 }, 'Cache.put called twice with matching Requests and different Responses');
155 155
156 cache_test(function(cache) { 156 cache_test(function(cache) {
157 var first_url = test_url; 157 var first_url = test_url;
158 var second_url = first_url + '#(O_o)'; 158 var second_url = first_url + '#(O_o)';
159 var alternate_response_body = 'New body'; 159 var alternate_response_body = 'New body';
160 var alternate_response = new Response(alternate_response_body, 160 var alternate_response = new Response(alternate_response_body,
161 { statusText: 'New status' }); 161 { statusText: 'New status' });
162 return cache.put(new Request(first_url), 162 return cache.put(new Request(first_url),
163 new Response('Old body', { statusText: 'Old status' })) 163 new Response('Old body', { statusText: 'Old status' }))
164 .then(function() { 164 .then(function() {
165 return cache.put(new Request(second_url), alternate_response.clone()); 165 return cache.put(new Request(second_url), alternate_response.clone());
166 }) 166 })
167 .then(function() { 167 .then(function() {
168 return cache.match(test_url); 168 return cache.match(test_url);
169 }) 169 })
170 .then(function(result) { 170 .then(function(result) {
171 assert_object_equals_fixed(result, alternate_response, 171 assert_response_equals(result, alternate_response,
172 'Cache.put should replace existing ' + 172 'Cache.put should replace existing ' +
173 'response with new response.'); 173 'response with new response.');
174 return result.text(); 174 return result.text();
175 }) 175 })
176 .then(function(body) { 176 .then(function(body) {
177 assert_equals(body, alternate_response_body, 177 assert_equals(body, alternate_response_body,
178 'Cache put should store new response body.'); 178 'Cache put should store new response body.');
179 }); 179 });
180 }, 'Cache.put called twice with request URLs that differ only by a fragment'); 180 }, 'Cache.put called twice with request URLs that differ only by a fragment');
181 181
182 cache_test(function(cache) { 182 cache_test(function(cache) {
183 var entries = { 183 var entries = {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 'Cache.put should reject non-HTTP/HTTPS requests with a TypeError.'); 241 'Cache.put should reject non-HTTP/HTTPS requests with a TypeError.');
242 }, 'Cache.put with a non-HTTP/HTTPS request'); 242 }, 'Cache.put with a non-HTTP/HTTPS request');
243 243
244 cache_test(function(cache) { 244 cache_test(function(cache) {
245 var response = new Response(test_body); 245 var response = new Response(test_body);
246 return cache.put(new Request('relative-url'), response.clone()) 246 return cache.put(new Request('relative-url'), response.clone())
247 .then(function() { 247 .then(function() {
248 return cache.match(new URL('relative-url', location.href).href); 248 return cache.match(new URL('relative-url', location.href).href);
249 }) 249 })
250 .then(function(result) { 250 .then(function(result) {
251 assert_object_equals_fixed(result, response, 251 assert_response_equals(result, response,
252 'Cache.put should accept a relative URL ' + 252 'Cache.put should accept a relative URL ' +
253 'as the request.'); 253 'as the request.');
254 }); 254 });
255 }, 'Cache.put with a relative URL'); 255 }, 'Cache.put with a relative URL');
256 256
257 cache_test(function(cache) { 257 cache_test(function(cache) {
258 var request = new Request('http://example.com/foo', { method: 'HEAD' }); 258 var request = new Request('http://example.com/foo', { method: 'HEAD' });
259 return assert_promise_rejects( 259 return assert_promise_rejects(
260 cache.put(request, new Response(test_body)), 260 cache.put(request, new Response(test_body)),
261 new TypeError(), 261 new TypeError(),
262 'Cache.put should throw a TypeError for non-GET requests.'); 262 'Cache.put should throw a TypeError for non-GET requests.');
263 }, 'Cache.put with a non-GET request'); 263 }, 'Cache.put with a non-GET request');
(...skipping 29 matching lines...) Expand all
293 293
294 cache_test(function(cache) { 294 cache_test(function(cache) {
295 var response = new Response(test_body); 295 var response = new Response(test_body);
296 return cache.put(new Request(test_url), response) 296 return cache.put(new Request(test_url), response)
297 .then(function() { 297 .then(function() {
298 return response.body.getReader().closed; 298 return response.body.getReader().closed;
299 }); 299 });
300 }, 'getReader() after Cache.put'); 300 }, 'getReader() after Cache.put');
301 301
302 done(); 302 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698