Index: LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js |
diff --git a/LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js b/LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..be4a78f905d039528b7e3f337583d58dccd74999 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js |
@@ -0,0 +1,45 @@ |
+importScripts('worker-test-harness.js'); |
+ |
+promise_test(function(t) { |
+ var request = new Request('http://example.com/foo', {method: 'GET'}); |
+ var response = new Response( |
+ 'Hello, world!', { |
jsbell
2014/08/01 00:02:25
This line break is weird.
asanka
2014/08/13 03:30:04
Indeed. Fixed.
|
+ status: 200, |
+ statusText: 'OK', |
+ headers: [['Content-Type', 'text/plain']] |
+ }); |
+ return new Cache().put(request, response) |
+ .then(t.step_func(function(result) { |
+ assert_equals(result, |
+ response, |
+ 'Cache.put should resolve with the response ' + |
+ 'parameter.'); |
+ })); |
+ }, 'Cache.put with a valid request'); |
+ |
+promise_test(function(t) { |
+ var request = new Request('http://example.com/foo', {method: 'HEAD'}); |
+ var response = new Response('Hello, world!', { |
+ status: 200, |
+ statusText: 'OK', |
+ headers: [['Content-Type', 'text/plain']] |
+ }); |
+ return new Cache().put(request, response) |
+ .then(t.unreached_func('Cache.put should not accept non-GET requests.')) |
+ .catch(t.step_func(function(e) { |
+ assert_true(e instanceof TypeError, |
+ 'Cache.put should throw a TypeError for non-GET ' + |
+ 'requests'); |
+ })); |
+ }, 'Cache.put with a non-GET request'); |
+ |
+promise_test(function(t) { |
+ var request = new Request('http://example.com/foo', {method: 'HEAD'}); |
+ return new Cache().put(request, null) |
+ .then(t.unreached_func('Cache.put should not accept empty responses.')) |
+ .catch(t.step_func(function(e) { |
+ assert_true(e instanceof TypeError, |
+ 'Cache.put should throw a TypeError for an empty ' + |
+ 'response'); |
+ })); |
+ }, 'Cache.put with an empty response'); |