Index: LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js |
diff --git a/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js b/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js |
index 6a8151545e9f589177f73ba4d13912afc3bad5af..669ee63186564bbb5104868cb136cdde180add09 100644 |
--- a/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js |
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js |
@@ -5,8 +5,9 @@ var test_url = 'https://example.com/foo'; |
// Construct a generic Request object. The URL is |test_url|. All other fields |
jsbell
2014/11/06 22:48:37
Nit: adjust comment
But... what's the advantage f
asanka
2014/11/06 23:42:00
None whatsoever. Removed!
|
// are defaults. |
-function new_test_request() { |
- return new Request(test_url); |
+function new_test_request(url) { |
+ url = url || test_url; |
+ return new Request(url); |
} |
// Construct a generic Response object. The URL is empty. If specified |body| |
@@ -119,6 +120,8 @@ cache_test(function(cache) { |
var response; |
return fetch(test_url) |
.then(function(fetch_result) { |
+ assert_equals(fetch_result.status, 500, |
+ 'Test framework error: The status code should be 500.'); |
response = fetch_result.clone(); |
return cache.put(request, fetch_result); |
}) |
@@ -138,8 +141,10 @@ cache_test(function(cache) { |
}, 'Cache.put with HTTP 500 response'); |
cache_test(function(cache) { |
- var alternate_response = new_test_response('Lorem ipsum'); |
- return cache.put(new_test_request(), new_test_response()) |
+ var alternate_response_body = 'New body'; |
+ var alternate_response = new_test_response(alternate_response_body); |
+ return cache.put(new_test_request(), |
+ new_test_response('Old body')) |
.then(function() { |
return cache.put(new_test_request(), alternate_response); |
}) |
@@ -150,8 +155,74 @@ cache_test(function(cache) { |
assert_object_equals(result, alternate_response, |
'Cache.put should replace existing ' + |
'response with new response.'); |
+ return result.text(); |
+ }) |
+ .then(function(body) { |
+ assert_equals(body, alternate_response_body, |
+ 'Cache put should store new response body.'); |
+ }); |
+ }, 'Cache.put called twice with matching Requests and different Responses'); |
+ |
+cache_test(function(cache) { |
+ var first_url = test_url; |
+ var second_url = first_url + '#(O_o)'; |
+ var alternate_response_body = 'New body'; |
+ var alternate_response = new_test_response(alternate_response_body); |
+ return cache.put(new_test_request(first_url), |
+ new_test_response('Old body')) |
+ .then(function() { |
+ return cache.put(new_test_request(second_url), alternate_response); |
+ }) |
+ .then(function() { |
+ return cache.match(test_url); |
+ }) |
+ .then(function(result) { |
+ assert_object_equals(result, alternate_response, |
jsbell
2014/11/06 22:48:37
It's a bit weird since this assertion currently pa
asanka
2014/11/06 23:42:00
Yeah. I removed the new_test_response() function a
|
+ 'Cache.put should replace existing ' + |
+ 'response with new response.'); |
+ return result.text(); |
+ }) |
+ .then(function(body) { |
+ assert_equals(body, alternate_response_body, |
+ 'Cache put should store new response body.'); |
+ }); |
+ }, 'Cache.put called twice with request URLs that differ only by a fragment'); |
+ |
+cache_test(function(cache) { |
+ var entries = { |
+ dark: { |
+ url: 'http://darkhelmet:12345@example.com/spaceballs', |
+ body: 'Moranis' |
+ }, |
+ |
+ skroob: { |
+ url: 'http://skroob:12345@example.com/spaceballs', |
+ body: 'Brooks' |
+ }, |
+ |
+ control: { |
+ url: 'http://example.com/spaceballs', |
+ body: 'v(o.o)v' |
+ } |
+ }; |
+ |
+ return Promise.all(Object.keys(entries).map(function(key) { |
+ return cache.put(new_test_request(entries[key].url), |
+ new_test_response(entries[key].body)); |
+ })) |
+ .then(function() { |
+ return Promise.all(Object.keys(entries).map(function(key) { |
+ return cache.match(entries[key].url) |
+ .then(function(result) { |
+ return result.text(); |
+ }) |
+ .then(function(body) { |
+ assert_equals(body, entries[key].body, |
+ 'Cache put should store response body.'); |
+ }); |
+ })); |
}); |
- }, 'Cache.put called twice with same Request and different Responses'); |
+ }, 'Cache.put with request URLs containing embedded credentials'); |
cache_test(function(cache) { |
var url = 'http://example.com/foo'; |
@@ -162,7 +233,7 @@ cache_test(function(cache) { |
assert_equals(body, 'some body', |
'Cache.put should accept a string as request.'); |
}); |
- }, 'Cache.put with an string request'); |
+ }, 'Cache.put with a string request'); |
cache_test(function(cache) { |
return assert_promise_rejects( |