Chromium Code Reviews| 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..2cfd78388a97773d81e37e11c624e82ce360687f |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/resources/cache-put-test-worker.js |
| @@ -0,0 +1,75 @@ |
| +importScripts('worker-test-harness.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 new Cache().put(test_request, test_response) |
| + .then(t.step_func(function(result) { |
|
jsbell
2014/08/15 20:49:35
t.step_func should be unnecessary in promise_test
asanka
2014/08/20 03:11:58
Done.
|
| + assert_equals(result, |
| + test_response, |
| + 'Cache.put should resolve with the response ' + |
| + 'parameter.'); |
| + })); |
| + }, 'Cache.put with a valid request'); |
| + |
| +promise_test(function(t) { |
| + var cache = new Cache(); |
| + |
| + return cache.put(test_request, test_response) |
| + .then(function() { |
| + return cache.put(test_request, alternate_test_response); |
| + }) |
| + .then(t.step_func(function(result) { |
| + assert_equals(result, |
| + alternate_test_response, |
| + 'Cache.put should replace existing response with ' + |
|
jsbell
2014/08/15 20:49:34
Should this have an extra step that does a match()
asanka
2014/08/20 03:11:58
Done.
|
| + 'new response.'); |
| + })); |
| + }, 'Cache.put with an existing request'); |
| + |
| +promise_test(function(t) { |
| + return new Cache().put('http://example.com/cow-goes-moo', test_response) |
| + .then(t.step_func(function(result) { |
| + assert_equals(result, test_response, |
| + 'Cache.put should accept a ScalarValueString as the ' + |
| + 'request.'); |
| + })); |
| + }, 'Cache.put with a request string'); |
| + |
| +promise_test(function(t) { |
| + return new Cache().put('invalid-scheme://should-accept', test_response) |
| + .then(t.step_func(function(result) { |
| + assert_equals(result, test_response, |
| + 'Cache.put should accept a ScalarValueString as the ' + |
| + 'request.'); |
| + })); |
| + }, 'Cache.put with a request string'); |
|
jsbell
2014/08/15 20:49:34
Add another case with a relative URL string?
asanka
2014/08/20 03:11:58
Done.
|
| + |
| +promise_test(function(t) { |
| + var request = new Request('http://example.com/foo', {method: 'HEAD'}); |
| + return expect_promise_throws( |
| + t, |
| + new Cache().put(request, test_response), |
| + 'TypeError', |
| + 'Cache.put should throw a TypeError for non-GET requests.'); |
| + }, 'Cache.put with a non-GET request'); |
| + |
| +promise_test(function(t) { |
| + return expect_promise_throws( |
| + t, |
| + new Cache().put(test_request, null), |
| + 'TypeError', |
| + 'Cache.put should throw a TypeError for an empty response.'); |
| + }, 'Cache.put with an empty response'); |