OLD | NEW |
---|---|
(Empty) | |
1 importScripts('worker-test-harness.js'); | |
2 | |
3 promise_test(function(t) { | |
4 var cache_name = 'cache-storage/foo'; | |
5 return self.caches.delete(cache_name) | |
6 .then(function() { | |
7 return self.caches.create(cache_name); | |
8 }) | |
9 .then(function(cache) { | |
10 assert_true(cache instanceof Cache, | |
11 'CacheStorage.create should return a Cache.'); | |
12 }); | |
13 }, 'CacheStorage.create'); | |
14 | |
15 promise_test(function(t) { | |
16 // Note that this test may collide with other tests running in the same | |
17 // origin that also uses an empty cache name. | |
18 var cache_name = ''; | |
19 return self.caches.delete(cache_name) | |
20 .then(function() { | |
21 return self.caches.create(cache_name); | |
22 }) | |
23 .then(function(cache) { | |
24 assert_true(cache instanceof Cache, | |
25 'CacheStorage.create should accept an empty name.'); | |
26 }); | |
27 }, 'CacheStorage.create with an empty name'); | |
28 | |
29 promise_test(function(t) { | |
30 return assert_promise_throws( | |
31 self.caches.create(), | |
32 'TypeError', | |
33 'CacheStorage.create should throw TypeError if called with no arguments.') ; | |
34 }, 'CacheStorage.create with no arguments'); | |
35 | |
36 promise_test(function(t) { | |
37 var cache_name = 'cache-storage/there can be only one'; | |
38 return self.caches.delete(cache_name) | |
39 .then(function() { | |
40 return self.caches.create(cache_name); | |
41 }) | |
42 .then(function() { | |
43 return assert_promise_throws( | |
44 self.caches.create(cache_name), | |
45 'InvalidAccessError', | |
46 'CacheStorage.create should throw InvalidAccessError if called ' + | |
47 'with existing cache name.'); | |
48 }); | |
49 }, 'CacheStorage.create with an existing cache name'); | |
50 | |
51 promise_test(function(t) { | |
52 var test_cases = [ | |
53 { | |
54 name: 'cache-storage/lowercase', | |
55 should_not_match: | |
56 [ | |
57 'cache-storage/Lowercase', | |
58 ' cache-storage/lowercase', | |
59 'cache-storage/lowercase ' | |
60 ] | |
61 }, | |
62 { | |
63 name: 'cache-storage/has a space', | |
64 should_not_match: | |
65 [ | |
66 'cache-storage/has' | |
67 ] | |
68 }, | |
69 { | |
70 name: 'cache-storage/has\000_in_the_name', | |
71 should_not_match: | |
72 [ | |
73 'cache-storage/has', | |
74 'cache-storage/has_in_the_name' | |
75 ] | |
76 } | |
77 ]; | |
78 return Promise.all(test_cases.map(function(testcase) { | |
79 var cache_name = testcase.name; | |
80 return self.caches.delete(cache_name) | |
81 .then(function() { | |
82 return self.caches.create(cache_name); | |
83 }) | |
84 .then(function() { | |
85 return self.caches.has(cache_name); | |
86 }) | |
87 .then(function(result) { | |
88 assert_true(result, | |
89 'CacheStorage.has should return true for existing ' + | |
90 'cache.'); | |
91 }) | |
92 .then(function() { | |
93 return Promise.all( | |
94 testcase.should_not_match.map(function(cache_name) { | |
95 return self.caches.has(cache_name) | |
96 .then(function(result) { | |
97 assert_false(result, | |
98 'CacheStorage.has should only perform ' + | |
99 'exact matches on cache names.'); | |
100 }); | |
101 })); | |
102 }) | |
103 .then(function() { | |
104 return self.caches.delete(cache_name); | |
105 }); | |
106 })); | |
107 }, 'CacheStorage.has with existing cache'); | |
108 | |
109 promise_test(function(t) { | |
110 return self.caches.has('cheezburger') | |
111 .then(function(result) { | |
112 assert_false(result, | |
113 'CacheStorage.has should return false for ' + | |
114 'nonexistent cache.'); | |
115 }); | |
116 }, 'CacheStorage.has with nonexistent cache'); | |
117 | |
118 promise_test(function(t) { | |
119 var cache_name = 'cache-storage/get'; | |
120 var cache; | |
121 return self.caches.create(cache_name) | |
jsbell
2014/08/27 23:20:07
This needs a 'delete' so it can be re-run.
asanka
2014/08/28 00:02:56
Done.
| |
122 .then(function(result) { | |
123 cache = result; | |
124 return self.caches.get(cache_name); | |
125 }) | |
126 .then(function(result) { | |
127 assert_equals(result, cache, | |
128 'CacheStorage.get should return the named Cache ' + | |
129 'object if it exists.'); | |
130 return self.caches.get(cache_name); | |
131 }) | |
132 .then(function(result) { | |
133 assert_equals(result, cache, | |
134 'CacheStorage.get should return the same ' + | |
135 'instance of an existing Cache object.'); | |
136 }); | |
137 }, 'CacheStorage.get with existing cache'); | |
138 | |
139 promise_test(function(t) { | |
140 return self.caches.get('cheezburger') | |
141 .then(function(result) { | |
142 assert_equals(result, undefined, | |
143 'CacheStorage.get should return undefined for a ' + | |
144 'nonexistent cache.'); | |
145 }); | |
146 }, 'CacheStorage.get with nonexistent cache'); | |
147 | |
148 promise_test(function(t) { | |
149 var cache_name = 'cache-storage/delete'; | |
150 | |
151 return self.caches.create(cache_name) | |
jsbell
2014/08/27 23:20:07
Ditto.
asanka
2014/08/28 00:02:56
Done.
| |
152 .then(function() { return self.caches.delete(cache_name); }) | |
153 .then(function(result) { | |
154 assert_true(result, | |
155 'CacheStorage.delete should return true after ' + | |
156 'deleting an existing cache.'); | |
157 }) | |
158 | |
159 .then(function() { return self.caches.has(cache_name); }) | |
160 .then(function(cache_exists) { | |
161 assert_false(cache_exists, | |
162 'CacheStorage.has should return false after ' + | |
163 'fulfillment of CacheStorage.delete promise.'); | |
164 }); | |
165 }, 'CacheStorage.delete with existing cache'); | |
166 | |
167 promise_test(function(t) { | |
168 return self.caches.delete('cheezburger') | |
169 .then(function(result) { | |
170 assert_false(result, | |
171 'CacheStorage.delete should return false for a ' + | |
172 'nonexistent cache.'); | |
173 }); | |
174 }, 'CacheStorage.delete with nonexistent cache'); | |
175 | |
OLD | NEW |