Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/cache-storage-worker.js

Issue 638023003: [ServiceWorkerCacheStorage] Blink changes to remove create/get and add open function (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 importScripts('worker-testharness.js'); 1 importScripts('worker-testharness.js');
2 importScripts('../../resources/testharness-helpers.js'); 2 importScripts('../../resources/testharness-helpers.js');
3 3
4 promise_test(function(t) { 4 promise_test(function(t) {
5 var cache_name = 'cache-storage/foo'; 5 var cache_name = 'cache-storage/foo';
6 return self.caches.delete(cache_name) 6 return self.caches.delete(cache_name)
7 .then(function() { 7 .then(function() {
8 return self.caches.create(cache_name); 8 return self.caches.open(cache_name);
9 }) 9 })
10 .then(function(cache) { 10 .then(function(cache) {
11 assert_true(cache instanceof Cache, 11 assert_true(cache instanceof Cache,
12 'CacheStorage.create should return a Cache.'); 12 'CacheStorage.open should return a Cache.');
13 }); 13 });
14 }, 'CacheStorage.create'); 14 }, 'CacheStorage.open');
15 15
16 promise_test(function(t) { 16 promise_test(function(t) {
17 // Note that this test may collide with other tests running in the same 17 // Note that this test may collide with other tests running in the same
18 // origin that also uses an empty cache name. 18 // origin that also uses an empty cache name.
19 var cache_name = ''; 19 var cache_name = '';
20 return self.caches.delete(cache_name) 20 return self.caches.delete(cache_name)
21 .then(function() { 21 .then(function() {
22 return self.caches.create(cache_name); 22 return self.caches.open(cache_name);
23 }) 23 })
24 .then(function(cache) { 24 .then(function(cache) {
25 assert_true(cache instanceof Cache, 25 assert_true(cache instanceof Cache,
26 'CacheStorage.create should accept an empty name.'); 26 'CacheStorage.open should accept an empty name.');
27 }); 27 });
28 }, 'CacheStorage.create with an empty name'); 28 }, 'CacheStorage.open with an empty name');
29 29
30 promise_test(function(t) { 30 promise_test(function(t) {
31 return assert_promise_rejects( 31 return assert_promise_rejects(
32 self.caches.create(), 32 self.caches.open(),
33 new TypeError(), 33 new TypeError(),
34 'CacheStorage.create should throw TypeError if called with no arguments.') ; 34 'CacheStorage.open should throw TypeError if called with no arguments.');
35 }, 'CacheStorage.create with no arguments'); 35 }, 'CacheStorage.open with no arguments');
36
37 promise_test(function(t) {
38 var cache_name = 'cache-storage/there can be only one';
39 return self.caches.delete(cache_name)
40 .then(function() {
41 return self.caches.create(cache_name);
42 })
43 .then(function() {
44 return assert_promise_rejects(
45 self.caches.create(cache_name),
46 'InvalidAccessError',
47 'CacheStorage.create should throw InvalidAccessError if called ' +
48 'with existing cache name.');
49 });
50 }, 'CacheStorage.create with an existing cache name');
51 36
52 promise_test(function(t) { 37 promise_test(function(t) {
53 var test_cases = [ 38 var test_cases = [
54 { 39 {
55 name: 'cache-storage/lowercase', 40 name: 'cache-storage/lowercase',
56 should_not_match: 41 should_not_match:
57 [ 42 [
58 'cache-storage/Lowercase', 43 'cache-storage/Lowercase',
59 ' cache-storage/lowercase', 44 ' cache-storage/lowercase',
60 'cache-storage/lowercase ' 45 'cache-storage/lowercase '
(...skipping 12 matching lines...) Expand all
73 [ 58 [
74 'cache-storage/has', 59 'cache-storage/has',
75 'cache-storage/has_in_the_name' 60 'cache-storage/has_in_the_name'
76 ] 61 ]
77 } 62 }
78 ]; 63 ];
79 return Promise.all(test_cases.map(function(testcase) { 64 return Promise.all(test_cases.map(function(testcase) {
80 var cache_name = testcase.name; 65 var cache_name = testcase.name;
81 return self.caches.delete(cache_name) 66 return self.caches.delete(cache_name)
82 .then(function() { 67 .then(function() {
83 return self.caches.create(cache_name); 68 return self.caches.open(cache_name);
84 }) 69 })
85 .then(function() { 70 .then(function() {
86 return self.caches.has(cache_name); 71 return self.caches.has(cache_name);
87 }) 72 })
88 .then(function(result) { 73 .then(function(result) {
89 assert_true(result, 74 assert_true(result,
90 'CacheStorage.has should return true for existing ' + 75 'CacheStorage.has should return true for existing ' +
91 'cache.'); 76 'cache.');
92 }) 77 })
93 .then(function() { 78 .then(function() {
(...skipping 16 matching lines...) Expand all
110 promise_test(function(t) { 95 promise_test(function(t) {
111 return self.caches.has('cheezburger') 96 return self.caches.has('cheezburger')
112 .then(function(result) { 97 .then(function(result) {
113 assert_false(result, 98 assert_false(result,
114 'CacheStorage.has should return false for ' + 99 'CacheStorage.has should return false for ' +
115 'nonexistent cache.'); 100 'nonexistent cache.');
116 }); 101 });
117 }, 'CacheStorage.has with nonexistent cache'); 102 }, 'CacheStorage.has with nonexistent cache');
118 103
119 promise_test(function(t) { 104 promise_test(function(t) {
120 var cache_name = 'cache-storage/get'; 105 var cache_name = 'cache-storage/open';
121 var cache; 106 var cache;
122 return self.caches.delete(cache_name) 107 return self.caches.delete(cache_name)
123 .then(function() { 108 .then(function() {
124 return self.caches.create(cache_name); 109 return self.caches.open(cache_name);
125 }) 110 })
126 .then(function(result) { 111 .then(function(result) {
127 cache = result; 112 cache = result;
128 }) 113 })
129 .then(function() { 114 .then(function() {
130 return self.caches.get(cache_name); 115 return self.caches.open(cache_name);
131 }) 116 })
132 .then(function(result) { 117 .then(function(result) {
133 assert_equals(result, cache, 118 assert_equals(result, cache,
134 'CacheStorage.get should return the named Cache ' + 119 'CacheStorage.open should return the named Cache ' +
135 'object if it exists.'); 120 'object if it exists.');
136 }) 121 })
137 .then(function() { 122 .then(function() {
138 return self.caches.get(cache_name); 123 return self.caches.open(cache_name);
139 }) 124 })
140 .then(function(result) { 125 .then(function(result) {
141 assert_equals(result, cache, 126 assert_equals(result, cache,
142 'CacheStorage.get should return the same ' + 127 'CacheStorage.open should return the same ' +
143 'instance of an existing Cache object.'); 128 'instance of an existing Cache object.');
144 }); 129 });
145 }, 'CacheStorage.get with existing cache'); 130 }, 'CacheStorage.open with existing cache');
146
147 promise_test(function(t) {
148 return self.caches.get('cheezburger')
149 .then(function(result) {
150 assert_equals(result, undefined,
151 'CacheStorage.get should return undefined for a ' +
152 'nonexistent cache.');
153 });
154 }, 'CacheStorage.get with nonexistent cache');
155 131
156 promise_test(function(t) { 132 promise_test(function(t) {
157 var cache_name = 'cache-storage/delete'; 133 var cache_name = 'cache-storage/delete';
158 134
159 return self.caches.delete(cache_name) 135 return self.caches.delete(cache_name)
160 .then(function() { 136 .then(function() {
161 return self.caches.create(cache_name); 137 return self.caches.open(cache_name);
162 }) 138 })
163 .then(function() { return self.caches.delete(cache_name); }) 139 .then(function() { return self.caches.delete(cache_name); })
164 .then(function(result) { 140 .then(function(result) {
165 assert_true(result, 141 assert_true(result,
166 'CacheStorage.delete should return true after ' + 142 'CacheStorage.delete should return true after ' +
167 'deleting an existing cache.'); 143 'deleting an existing cache.');
168 }) 144 })
169 145
170 .then(function() { return self.caches.has(cache_name); }) 146 .then(function() { return self.caches.has(cache_name); })
171 .then(function(cache_exists) { 147 .then(function(cache_exists) {
172 assert_false(cache_exists, 148 assert_false(cache_exists,
173 'CacheStorage.has should return false after ' + 149 'CacheStorage.has should return false after ' +
174 'fulfillment of CacheStorage.delete promise.'); 150 'fulfillment of CacheStorage.delete promise.');
175 }); 151 });
176 }, 'CacheStorage.delete with existing cache'); 152 }, 'CacheStorage.delete with existing cache');
177 153
178 promise_test(function(t) { 154 promise_test(function(t) {
179 return self.caches.delete('cheezburger') 155 return self.caches.delete('cheezburger')
180 .then(function(result) { 156 .then(function(result) {
181 assert_false(result, 157 assert_false(result,
182 'CacheStorage.delete should return false for a ' + 158 'CacheStorage.delete should return false for a ' +
183 'nonexistent cache.'); 159 'nonexistent cache.');
184 }); 160 });
185 }, 'CacheStorage.delete with nonexistent cache'); 161 }, 'CacheStorage.delete with nonexistent cache');
186 162
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698