OLD | NEW |
---|---|
(Empty) | |
1 importScripts('worker-test-harness.js'); | |
2 | |
3 var test_request = new Request('http://example.com/foo', {method: 'GET'}); | |
4 | |
5 var test_response = new Response('Hello, world!', { | |
6 status: 200, | |
7 statusText: 'OK', | |
8 headers: [['Content-Type', 'text/plain']] | |
9 }); | |
10 | |
11 var alternate_test_response = new Response('Goodbye, world!', { | |
12 status: 200, | |
13 statusText: 'OK', | |
14 headers: [['Content-Type', 'text/plain']] | |
15 }); | |
16 | |
17 promise_test(function(t) { | |
18 return new Cache().put(test_request, test_response) | |
19 .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.
| |
20 assert_equals(result, | |
21 test_response, | |
22 'Cache.put should resolve with the response ' + | |
23 'parameter.'); | |
24 })); | |
25 }, 'Cache.put with a valid request'); | |
26 | |
27 promise_test(function(t) { | |
28 var cache = new Cache(); | |
29 | |
30 return cache.put(test_request, test_response) | |
31 .then(function() { | |
32 return cache.put(test_request, alternate_test_response); | |
33 }) | |
34 .then(t.step_func(function(result) { | |
35 assert_equals(result, | |
36 alternate_test_response, | |
37 '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.
| |
38 'new response.'); | |
39 })); | |
40 }, 'Cache.put with an existing request'); | |
41 | |
42 promise_test(function(t) { | |
43 return new Cache().put('http://example.com/cow-goes-moo', test_response) | |
44 .then(t.step_func(function(result) { | |
45 assert_equals(result, test_response, | |
46 'Cache.put should accept a ScalarValueString as the ' + | |
47 'request.'); | |
48 })); | |
49 }, 'Cache.put with a request string'); | |
50 | |
51 promise_test(function(t) { | |
52 return new Cache().put('invalid-scheme://should-accept', test_response) | |
53 .then(t.step_func(function(result) { | |
54 assert_equals(result, test_response, | |
55 'Cache.put should accept a ScalarValueString as the ' + | |
56 'request.'); | |
57 })); | |
58 }, '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.
| |
59 | |
60 promise_test(function(t) { | |
61 var request = new Request('http://example.com/foo', {method: 'HEAD'}); | |
62 return expect_promise_throws( | |
63 t, | |
64 new Cache().put(request, test_response), | |
65 'TypeError', | |
66 'Cache.put should throw a TypeError for non-GET requests.'); | |
67 }, 'Cache.put with a non-GET request'); | |
68 | |
69 promise_test(function(t) { | |
70 return expect_promise_throws( | |
71 t, | |
72 new Cache().put(test_request, null), | |
73 'TypeError', | |
74 'Cache.put should throw a TypeError for an empty response.'); | |
75 }, 'Cache.put with an empty response'); | |
OLD | NEW |