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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..73639f126615859cff6798c07f8cd84e4d4d55bf |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-put-worker.js |
@@ -0,0 +1,126 @@ |
+importScripts('worker-testharness.js'); |
+importScripts('/resources/testharness-helpers.js'); |
+ |
+var test_request = new Request('http://example.com/foo', {method: 'GET'}); |
+ |
+var test_response = new Response('Hello, world!', { |
+ status: 200, |
+ statusText: 'OK', |
+ headers: [['Content-Type', 'text/plain']] |
+ }); |
+ |
+var alternate_test_response = new Response('Goodbye, world!', { |
+ status: 200, |
+ statusText: 'OK', |
+ headers: [['Content-Type', 'text/plain']] |
+ }); |
+ |
+promise_test(function(t) { |
+ return create_temporary_cache(t) |
jsbell
2014/10/20 18:20:41
Consider adding a helper: cache_test(function(t, c
asanka
2014/10/22 22:35:32
Good suggestion. Done.
|
+ .then(function(cache) { |
+ return cache.put(test_request, test_response) |
+ .then(function(result) { |
+ assert_object_equals(result, |
+ test_response, |
+ 'Cache.put should resolve with the ' + |
+ 'Response object.'); |
+ }) |
+ .then(function() { |
+ return cache.match(test_request); |
+ }) |
+ .then(function(result) { |
+ assert_object_equals(result, test_response, |
+ 'Cache.put should update the cache with ' + |
+ 'specified request.'); |
+ }); |
+ }); |
+ }, 'Cache.put with a valid request'); |
+ |
+promise_test(function(t) { |
+ return create_temporary_cache(t) |
+ .then(function(cache) { |
+ return cache.put(test_request, test_response) |
+ .then(function() { |
+ return cache.put(test_request, alternate_test_response); |
+ }) |
+ .then(function(result) { |
+ assert_object_equals(result, |
+ alternate_test_response, |
+ 'Cache.put should replace existing ' + |
+ 'response with new response.'); |
+ }) |
+ .then(function() { |
+ return cache.match(test_request); |
+ }) |
+ .then(function(result) { |
+ assert_object_equals(result, alternate_test_response, |
+ 'Cache.put should replace existing ' + |
+ 'response with new response.'); |
+ }); |
+ }); |
+ }, 'Cache.put with an existing request'); |
+ |
+promise_test(function(t) { |
+ return create_temporary_cache(t) |
+ .then(function(cache) { |
+ return cache.put('http://example.com/cow-goes-moo', test_response); |
+ }) |
+ .then(function(result) { |
+ assert_object_equals(result, test_response, |
+ 'Cache.put should accept a ScalarValueString ' + |
+ 'as the request.'); |
+ }); |
+ }, 'Cache.put with a request string'); |
+ |
+promise_test(function(t) { |
+ return create_temporary_cache(t) |
+ .then(function(cache) { |
+ return cache.put('invalid-scheme://should-accept', test_response); |
+ }) |
+ .then(function(result) { |
+ assert_object_equals(result, test_response, |
+ 'Cache.put should accept a ScalarValueString ' + |
+ 'as the request.'); |
+ }); |
+ }, 'Cache.put with a request string'); |
+ |
+promise_test(function(t) { |
+ return create_temporary_cache(t) |
+ .then(function(cache) { |
+ return cache.put('relative-url', test_response) |
+ .then(function(result) { |
+ assert_object_equals(result, test_response, |
+ 'Cache.put should accept a relative URL ' + |
+ 'as the request.'); |
+ }) |
+ .then(function() { |
+ return cache.match(new URL('relative-url', location.href).href); |
+ }) |
+ .then(function(result) { |
+ assert_object_equals(result, test_response, |
+ 'Cache.put should accept a relative URL ' + |
+ 'as the request.'); |
+ }); |
+ }); |
+ }, 'Cache.put with a relative URL'); |
+ |
+promise_test(function(t) { |
+ var request = new Request('http://example.com/foo', {method: 'HEAD'}); |
+ return create_temporary_cache(t) |
+ .then(function(cache) { |
+ return assert_promise_rejects( |
+ cache.put(request, test_response), |
+ new TypeError(), |
+ 'Cache.put should throw a TypeError for non-GET requests.'); |
+ }); |
+ }, 'Cache.put with a non-GET request'); |
+ |
+promise_test(function(t) { |
+ return create_temporary_cache(t) |
+ .then(function(cache) { |
+ return assert_promise_rejects( |
+ cache.put(test_request, null), |
+ new TypeError(), |
+ 'Cache.put should throw a TypeError for an empty response.'); |
+ }); |
+ }, 'Cache.put with an empty response'); |