1 if (self
.importScripts
) {
2 importScripts('/resources/testharness.js');
3 importScripts('/resources/testharness-helpers.js');
4 importScripts('../resources/test-helpers.js');
7 promise_test(function(t
) {
8 var cache_name
= 'cache-storage/foo';
9 return self
.caches
.delete(cache_name
)
11 return self
.caches
.open(cache_name
);
13 .then(function(cache
) {
14 assert_true(cache
instanceof Cache
,
15 'CacheStorage.open should return a Cache.');
17 }, 'CacheStorage.open');
19 promise_test(function(t
) {
20 // Note that this test may collide with other tests running in the same
21 // origin that also uses an empty cache name.
23 return self
.caches
.delete(cache_name
)
25 return self
.caches
.open(cache_name
);
27 .then(function(cache
) {
28 assert_true(cache
instanceof Cache
,
29 'CacheStorage.open should accept an empty name.');
31 }, 'CacheStorage.open with an empty name');
33 promise_test(function(t
) {
34 return assert_promise_rejects(
37 'CacheStorage.open should throw TypeError if called with no arguments.');
38 }, 'CacheStorage.open with no arguments');
40 promise_test(function(t
) {
43 name
: 'cache-storage/lowercase',
46 'cache-storage/Lowercase',
47 ' cache-storage/lowercase',
48 'cache-storage/lowercase '
52 name
: 'cache-storage/has a space',
59 name
: 'cache-storage/has\000_in_the_name',
63 'cache-storage/has_in_the_name'
67 return Promise
.all(test_cases
.map(function(testcase
) {
68 var cache_name
= testcase
.name
;
69 return self
.caches
.delete(cache_name
)
71 return self
.caches
.open(cache_name
);
74 return self
.caches
.has(cache_name
);
76 .then(function(result
) {
78 'CacheStorage.has should return true for existing ' +
83 testcase
.should_not_match
.map(function(cache_name
) {
84 return self
.caches
.has(cache_name
)
85 .then(function(result
) {
87 'CacheStorage.has should only perform ' +
88 'exact matches on cache names.');
93 return self
.caches
.delete(cache_name
);
96 }, 'CacheStorage.has with existing cache');
98 promise_test(function(t
) {
99 return self
.caches
.has('cheezburger')
100 .then(function(result
) {
102 'CacheStorage.has should return false for ' +
103 'nonexistent cache.');
105 }, 'CacheStorage.has with nonexistent cache');
107 promise_test(function(t
) {
108 var cache_name
= 'cache-storage/open';
110 return self
.caches
.delete(cache_name
)
112 return self
.caches
.open(cache_name
);
114 .then(function(result
) {
118 return self
.caches
.open(cache_name
);
120 .then(function(result
) {
121 assert_equals(result
, cache
,
122 'CacheStorage.open should return the named Cache ' +
123 'object if it exists.');
126 return self
.caches
.open(cache_name
);
128 .then(function(result
) {
129 assert_equals(result
, cache
,
130 'CacheStorage.open should return the same ' +
131 'instance of an existing Cache object.');
133 }, 'CacheStorage.open with existing cache');
135 promise_test(function(t
) {
136 var cache_name
= 'cache-storage/delete';
138 return self
.caches
.delete(cache_name
)
140 return self
.caches
.open(cache_name
);
142 .then(function() { return self
.caches
.delete(cache_name
); })
143 .then(function(result
) {
145 'CacheStorage.delete should return true after ' +
146 'deleting an existing cache.');
149 .then(function() { return self
.caches
.has(cache_name
); })
150 .then(function(cache_exists
) {
151 assert_false(cache_exists
,
152 'CacheStorage.has should return false after ' +
153 'fulfillment of CacheStorage.delete promise.');
155 }, 'CacheStorage.delete with existing cache');
157 promise_test(function(t
) {
158 return self
.caches
.delete('cheezburger')
159 .then(function(result
) {
161 'CacheStorage.delete should return false for a ' +
162 'nonexistent cache.');
164 }, 'CacheStorage.delete with nonexistent cache');
166 promise_test(function(t
) {
167 var bad_name
= 'unpaired\uD800';
168 var converted_name
= 'unpaired\uFFFD'; // Don't create cache with this name.
169 return self
.caches
.has(converted_name
)
170 .then(function(cache_exists
) {
171 assert_false(cache_exists
,
172 'Test setup failure: cache should not exist');
174 .then(function() { return self
.caches
.open(bad_name
); })
175 .then(function() { return self
.caches
.keys(); })
176 .then(function(keys
) {
177 assert_true(keys
.indexOf(bad_name
) !== -1,
178 'keys should include cache with bad name');
180 .then(function() { return self
.caches
.has(bad_name
); })
181 .then(function(cache_exists
) {
182 assert_true(cache_exists
,
183 'CacheStorage names should be not be converted.');
185 .then(function() { return self
.caches
.has(converted_name
); })
186 .then(function(cache_exists
) {
187 assert_false(cache_exists
,
188 'CacheStorage names should be not be converted.');
190 }, 'CacheStorage names are DOMStrings not USVStrings');