Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / cachestorage / script-tests / cache-storage.js
blob1e3280c99ed0a35fbb3dec36c2afb6265e5b4ff5
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)
10 .then(function() {
11 return self.caches.open(cache_name);
13 .then(function(cache) {
14 assert_true(cache instanceof Cache,
15 'CacheStorage.open should return a Cache.');
16 });
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.
22 var cache_name = '';
23 return self.caches.delete(cache_name)
24 .then(function() {
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.');
30 });
31 }, 'CacheStorage.open with an empty name');
33 promise_test(function(t) {
34 return assert_promise_rejects(
35 self.caches.open(),
36 new TypeError(),
37 'CacheStorage.open should throw TypeError if called with no arguments.');
38 }, 'CacheStorage.open with no arguments');
40 promise_test(function(t) {
41 var test_cases = [
43 name: 'cache-storage/lowercase',
44 should_not_match:
46 'cache-storage/Lowercase',
47 ' cache-storage/lowercase',
48 'cache-storage/lowercase '
52 name: 'cache-storage/has a space',
53 should_not_match:
55 'cache-storage/has'
59 name: 'cache-storage/has\000_in_the_name',
60 should_not_match:
62 'cache-storage/has',
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)
70 .then(function() {
71 return self.caches.open(cache_name);
73 .then(function() {
74 return self.caches.has(cache_name);
76 .then(function(result) {
77 assert_true(result,
78 'CacheStorage.has should return true for existing ' +
79 'cache.');
81 .then(function() {
82 return Promise.all(
83 testcase.should_not_match.map(function(cache_name) {
84 return self.caches.has(cache_name)
85 .then(function(result) {
86 assert_false(result,
87 'CacheStorage.has should only perform ' +
88 'exact matches on cache names.');
89 });
90 }));
92 .then(function() {
93 return self.caches.delete(cache_name);
94 });
95 }));
96 }, 'CacheStorage.has with existing cache');
98 promise_test(function(t) {
99 return self.caches.has('cheezburger')
100 .then(function(result) {
101 assert_false(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';
109 var cache;
110 return self.caches.delete(cache_name)
111 .then(function() {
112 return self.caches.open(cache_name);
114 .then(function(result) {
115 cache = result;
117 .then(function() {
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.');
125 .then(function() {
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)
139 .then(function() {
140 return self.caches.open(cache_name);
142 .then(function() { return self.caches.delete(cache_name); })
143 .then(function(result) {
144 assert_true(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) {
160 assert_false(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');
192 done();