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 | |
jsbell
2014/08/20 17:54:13
For Blink layout tests we won't run tests with the
asanka
2014/08/20 21:20:49
Acknowledged.
| |
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(); | |
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 var cache_name = 'cache-storage/there can be only one'; | |
jsbell
2014/08/20 17:54:13
No Highlander joke? I am disappoint!
asanka
2014/08/20 21:20:49
:)
| |
31 return self.caches(delete(cache_name)) | |
32 .then(function() { | |
33 return self.caches.create(cache_name); | |
34 }) | |
35 .then(function() { | |
36 return assert_promise_throws( | |
37 self.caches.create(cache_name), | |
38 'InvalidAccessError', | |
39 'CacheStorage.create should throw InvalidAccessError if called ' + | |
40 'with existing cache name.'); | |
41 }); | |
42 }, 'CacheStorage.create with an existing cache name'); | |
43 | |
44 promise_test(function(t) { | |
45 var test_cases = [ | |
46 { name: 'cache-storage/lowercase', | |
jsbell
2014/08/20 17:54:13
nit: Per style guide, either wrap after { or no sp
asanka
2014/08/20 21:20:49
Done.
| |
47 should_not_match: [ | |
48 'cache-storage/Lowercase', | |
49 ' cache-storage/lowercase', | |
50 'cache-storage/lowercase ' | |
51 ] }, | |
52 { name: 'cache-storage/has a space', | |
53 should_not_match: [ | |
54 'cache-storage/has' | |
55 ] }, | |
56 { name: 'cache-storage/has\000_in_the_name', | |
57 should_not_match: [ | |
58 'cache-storage/has', | |
59 'cache-storage/has_in_the_name' | |
60 ] } | |
61 ]; | |
62 return Promise.all(test_cases.map(function(testcase) { | |
63 var cache_name = testcase.name; | |
64 return self.caches.delete(cache_name) | |
65 .then(function() { | |
66 return self.caches.create(cache_name); | |
67 }) | |
68 .then(function() { | |
69 return self.caches.has(cache_name); | |
70 }) | |
71 .then(function(result) { | |
72 assert_true(result, | |
73 'CacheStorage.has should return true for existing ' + | |
74 'cache.'); | |
75 }) | |
76 .then(function() { | |
77 return Promise.all( | |
78 testcase.should_not_match.map(function(cache_name) { | |
79 return self.caches.has(cache_name) | |
80 .then(function(result) { | |
81 assert_false(result, | |
82 'CacheStorage.has should only perform ' + | |
83 'exact matches on cache names.'); | |
84 }); | |
85 })); | |
86 }) | |
87 .then(function() { | |
88 return self.caches.delete(cache_name); | |
89 }); | |
90 })); | |
91 }, 'CacheStorage.has with existing cache'); | |
92 | |
93 promise_test(function(t) { | |
94 return self.caches.has('cheezburger') | |
95 .then(function(result) { | |
96 assert_false(result, | |
97 'CacheStorage.has should return false for ' + | |
98 'nonexistent cache.'); | |
99 }); | |
100 }, 'CacheStorage.has with nonexistent cache'); | |
101 | |
102 promise_test(function(t) { | |
103 var cache_name = 'cache-storage/get'; | |
104 var cache; | |
105 return self.caches.create(cache_name) | |
106 .then(function(result) { | |
107 cache = result; | |
108 return self.caches.get(cache_name); | |
109 }) | |
110 .then(function(result) { | |
111 assert_equals(result, cache, | |
112 'CacheStorage.get should return the named Cache ' + | |
113 'object if it exists.'); | |
114 return self.caches.get(cache_name); | |
115 }) | |
116 .then(function(result) { | |
117 assert_equals(result, cache, | |
118 'CacheStorage.get should return the same ' + | |
119 'instance of an existing Cache object.'); | |
120 }); | |
121 }, 'CacheStorage.get with existing cache'); | |
122 | |
123 promise_test(function(t) { | |
124 return self.caches.get('cheezburger') | |
125 .then(function(result) { | |
126 assert_equals(result, undefined, | |
127 'CacheStorage.get should return undefined for a ' + | |
128 'nonexistent cache.'); | |
129 }); | |
130 }, 'CacheStorage.get with nonexistent cache'); | |
131 | |
132 promise_test(function(t) { | |
133 var cache_name = 'cache-storage/delete'; | |
134 | |
135 return self.caches.create(cache_name) | |
136 .then(function() { return self.caches.delete(cache_name); }) | |
137 .then(function(result) { | |
138 assert_true(result, | |
139 'CacheStorage.delete should return true after ' + | |
140 'deleting an existing cache.'); | |
141 }) | |
142 | |
143 .then(function() { return self.caches.has(cache_name); }) | |
144 .then(function(cache_exists) { | |
145 assert_false(cache_exists, | |
146 'CacheStorage.has should not return true after ' + | |
147 'fulfilment of CacheStorage.delete promise.'); | |
148 }); | |
149 }, 'CacheStorage.delete with existing cache'); | |
150 | |
151 promise_test(function(t) { | |
152 return self.caches.delete('cheezburger') | |
153 .then(function(result) { | |
154 assert_false(result, | |
155 'CacheStorage.delete should return false for a ' + | |
156 'nonexistent cache.'); | |
157 }); | |
158 }, 'CacheStorage.delete with nonexistent cache'); | |
159 | |
OLD | NEW |