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

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

Issue 430993002: [ServiceWorker] CacheStorage tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 importScripts('worker-test-harness.js');
2
3 promise_test(function(t) {
4 return caches.create('foo')
jsbell 2014/08/15 21:36:13 IIUC, Caches are scoped to an origin, not to a SW
asanka 2014/08/20 03:10:29 I see. This was a bit of a head scratcher for me s
5 .then(t.step_func(function(cache) {
jsbell 2014/08/15 21:36:13 Should not need t.step_func in a promise_test (her
asanka 2014/08/20 03:10:29 Ah. Good point! Changed.
6 assert_true(cache instanceof Cache,
7 'CacheStorage.create should return a Cache.');
8 }));
9 }, 'CacheStorage.create');
10
11 promise_test(function(t) {
12 return caches.create()
13 .then(t.step_func(function(cache) {
14 assert_true(cache instanceof Cache,
15 'CacheStorage.create should accept an empty name.');
16 }));
17 }, 'CacheStorage.create with an empty name');
18
19 promise_test(function(t) {
20 var cache_name = 'there can be only one';
21
22 return caches.create(cache_name)
23 .then(function() {
24 return expect_promise_throws(
25 t,
26 caches.create(cache_name),
27 'InvalidAccessError',
28 'CacheStorage.create should throw InvalidAccessError if called ' +
29 'with existing cache name.');
30 });
31 }, 'CacheStorage.create');
32
33 promise_test(function(t) {
34 return caches.create('bar')
35 .then(t.step_func(function() { return caches.has('bar'); }))
36 .then(t.step_func(function(result) {
37 assert_true(result,
38 'CacheStorage.has should return true for ' +
39 'existing cache.');
40 }))
41
42 .then(function() { return caches.has('Bar'); })
43 .then(t.step_func(function(result) {
44 assert_false(result,
45 'CacheStorage.has should not match a cache name that ' +
46 'differs in case.');
47 }))
48
49 .then(function() { return caches.has(' bar'); })
50 .then(t.step_func(function(result) {
51 assert_false(result,
52 'CacheStorage.has should not ignore leading ' +
53 'whitespace in name.');
54 }))
55
56 .then(function() { return caches.has('bar '); })
57 .then(t.step_func(function(result) {
58 assert_false(result,
59 'CacheStorage.has should not ignore trailing ' +
jsbell 2014/08/15 21:36:13 Any particular reason to worry about leading/trail
asanka 2014/08/20 03:10:29 I added a test case for an embedded NUL. I didn't
60 'whitespace in name.');
61 }));
62 }, 'CacheStorage.has with existing cache');
63
64 promise_test(function(t) {
65 return caches.has('cheezburger')
66 .then(t.step_func(function(result) {
67 assert_false(result,
68 'CacheStorage.has should return false for ' +
69 'nonexistent cache.');
70 }));
71 }, 'CacheStorage.has with nonexistent cache');
72
73 promise_test(function(t) {
74 var cache_name = 'get-test';
75 var cache;
76 return caches.create(cache_name)
77 .then(t.step_func(function(result) {
78 cache = result;
79 return caches.get(cache_name);
80 }))
81 .then(t.step_func(function(result) {
82 assert_equals(result, cache,
83 'CacheStorage.get should return the named Cache object ' +
jsbell 2014/08/15 21:36:13 nit: line length (80 cols)
asanka 2014/08/20 03:10:29 Done.
84 'if it exists.');
85 return caches.get(cache_name);
86 }))
87 .then(t.step_func(function(result) {
88 assert_equals(result, cache,
89 'CacheStorage.get should return the same ' +
90 'instance of an existing Cache object.');
91 }));
92 }, 'CacheStorage.get with existing cache');
93
94 promise_test(function(t) {
95 return caches.get('cheezburger')
96 .then(t.step_func(function(result) {
97 assert_equals(result, undefined,
98 'CacheStorage.get should return undefined for a ' +
99 'nonexistent cache.');
100 }));
101 }, 'CacheStorage.get with nonexistent cache');
102
103 promise_test(function(t) {
104 var cache_name = 'to-be-deleted';
105
106 return caches.create(cache_name)
107 .then(function() { return caches.delete(cache_name); })
108 .then(t.step_func(function(result) {
109 assert_true(result,
110 'CacheStorage.delete should return true after ' +
111 'deleting an existing cache.');
112 }))
113
114 .then(function() { return caches.has(cache_name); })
115 .then(t.step_func(function(cache_exists) {
116 assert_false(cache_exists,
117 'CacheStorage.has should not return true after ' +
118 'fulfilment of CacheStorage.delete promise.');
119 }));
120 }, 'CacheStorage.delete with existing cache');
121
122 promise_test(function(t) {
123 return caches.delete('cheezburger')
124 .then(t.step_func(function(result) {
125 assert_false(result,
126 'CacheStorage.delete should return false for a ' +
127 'nonexistent cache.');
128 }));
129 }, 'CacheStorage.delete with nonexistent cache');
130
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698