OLD | NEW |
---|---|
(Empty) | |
1 importScripts('worker-testharness.js'); | |
2 importScripts('/resources/testharness-helpers.js'); | |
3 | |
4 var test_request = new Request('http://example.com/foo', {method: 'GET'}); | |
5 | |
6 var test_response = new Response('Hello, world!', { | |
7 status: 200, | |
8 statusText: 'OK', | |
9 headers: [['Content-Type', 'text/plain']] | |
10 }); | |
11 | |
12 var alternate_test_response = new Response('Goodbye, world!', { | |
13 status: 200, | |
14 statusText: 'OK', | |
15 headers: [['Content-Type', 'text/plain']] | |
16 }); | |
17 | |
18 promise_test(function(t) { | |
19 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.
| |
20 .then(function(cache) { | |
21 return cache.put(test_request, test_response) | |
22 .then(function(result) { | |
23 assert_object_equals(result, | |
24 test_response, | |
25 'Cache.put should resolve with the ' + | |
26 'Response object.'); | |
27 }) | |
28 .then(function() { | |
29 return cache.match(test_request); | |
30 }) | |
31 .then(function(result) { | |
32 assert_object_equals(result, test_response, | |
33 'Cache.put should update the cache with ' + | |
34 'specified request.'); | |
35 }); | |
36 }); | |
37 }, 'Cache.put with a valid request'); | |
38 | |
39 promise_test(function(t) { | |
40 return create_temporary_cache(t) | |
41 .then(function(cache) { | |
42 return cache.put(test_request, test_response) | |
43 .then(function() { | |
44 return cache.put(test_request, alternate_test_response); | |
45 }) | |
46 .then(function(result) { | |
47 assert_object_equals(result, | |
48 alternate_test_response, | |
49 'Cache.put should replace existing ' + | |
50 'response with new response.'); | |
51 }) | |
52 .then(function() { | |
53 return cache.match(test_request); | |
54 }) | |
55 .then(function(result) { | |
56 assert_object_equals(result, alternate_test_response, | |
57 'Cache.put should replace existing ' + | |
58 'response with new response.'); | |
59 }); | |
60 }); | |
61 }, 'Cache.put with an existing request'); | |
62 | |
63 promise_test(function(t) { | |
64 return create_temporary_cache(t) | |
65 .then(function(cache) { | |
66 return cache.put('http://example.com/cow-goes-moo', test_response); | |
67 }) | |
68 .then(function(result) { | |
69 assert_object_equals(result, test_response, | |
70 'Cache.put should accept a ScalarValueString ' + | |
71 'as the request.'); | |
72 }); | |
73 }, 'Cache.put with a request string'); | |
74 | |
75 promise_test(function(t) { | |
76 return create_temporary_cache(t) | |
77 .then(function(cache) { | |
78 return cache.put('invalid-scheme://should-accept', test_response); | |
79 }) | |
80 .then(function(result) { | |
81 assert_object_equals(result, test_response, | |
82 'Cache.put should accept a ScalarValueString ' + | |
83 'as the request.'); | |
84 }); | |
85 }, 'Cache.put with a request string'); | |
86 | |
87 promise_test(function(t) { | |
88 return create_temporary_cache(t) | |
89 .then(function(cache) { | |
90 return cache.put('relative-url', test_response) | |
91 .then(function(result) { | |
92 assert_object_equals(result, test_response, | |
93 'Cache.put should accept a relative URL ' + | |
94 'as the request.'); | |
95 }) | |
96 .then(function() { | |
97 return cache.match(new URL('relative-url', location.href).href); | |
98 }) | |
99 .then(function(result) { | |
100 assert_object_equals(result, test_response, | |
101 'Cache.put should accept a relative URL ' + | |
102 'as the request.'); | |
103 }); | |
104 }); | |
105 }, 'Cache.put with a relative URL'); | |
106 | |
107 promise_test(function(t) { | |
108 var request = new Request('http://example.com/foo', {method: 'HEAD'}); | |
109 return create_temporary_cache(t) | |
110 .then(function(cache) { | |
111 return assert_promise_rejects( | |
112 cache.put(request, test_response), | |
113 new TypeError(), | |
114 'Cache.put should throw a TypeError for non-GET requests.'); | |
115 }); | |
116 }, 'Cache.put with a non-GET request'); | |
117 | |
118 promise_test(function(t) { | |
119 return create_temporary_cache(t) | |
120 .then(function(cache) { | |
121 return assert_promise_rejects( | |
122 cache.put(test_request, null), | |
123 new TypeError(), | |
124 'Cache.put should throw a TypeError for an empty response.'); | |
125 }); | |
126 }, 'Cache.put with an empty response'); | |
OLD | NEW |