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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/cache-storage/script-tests/cache-delete.js

Issue 2790143003: Cache Storage API tests: Fix WPT test bugs, remove redundant local copies (Closed)
Patch Set: Created 3 years, 8 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 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('/resources/testharness.js'); 2 importScripts('/resources/testharness.js');
3 importScripts('../resources/test-helpers.js'); 3 importScripts('../resources/test-helpers.js');
4 } 4 }
5 5
6 var test_url = 'https://example.com/foo'; 6 var test_url = 'https://example.com/foo';
7 7
8 // Construct a generic Request object. The URL is |test_url|. All other fields 8 // Construct a generic Request object. The URL is |test_url|. All other fields
9 // are defaults. 9 // are defaults.
10 function new_test_request() { 10 function new_test_request() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 }) 64 })
65 .then(function(result) { 65 .then(function(result) {
66 assert_false(result, 66 assert_false(result,
67 'Cache.delete should not match a non-GET request ' + 67 'Cache.delete should not match a non-GET request ' +
68 'unless ignoreMethod option is set.'); 68 'unless ignoreMethod option is set.');
69 return cache.match(test_url); 69 return cache.match(test_url);
70 }) 70 })
71 .then(function(result) { 71 .then(function(result) {
72 assert_response_equals(result, response, 72 assert_response_equals(result, response,
73 'Cache.delete should leave non-matching response in the cache.'); 73 'Cache.delete should leave non-matching response in the cache.');
74 return cache.delete(new Request(test_url, {method: 'HEAD'}),
75 {ignoreMethod: true});
76 })
77 .then(function(result) {
78 assert_true(result,
79 'Cache.delete should match a non-GET request ' +
80 ' if ignoreMethod is true.');
74 }); 81 });
75 }, 'Cache.delete called with a HEAD request'); 82 }, 'Cache.delete called with a HEAD request');
76 83
77 cache_test(function(cache) { 84 cache_test(function(cache) {
85 var vary_request = new Request('http://example.com/c',
86 {headers: {'Cookies': 'is-for-cookie'}});
87 var vary_response = new Response('', {headers: {'Vary': 'Cookies'}});
88 var mismatched_vary_request = new Request('http://example.com/c');
89
90 return cache.put(vary_request.clone(), vary_response.clone())
91 .then(function() {
92 return cache.delete(mismatched_vary_request.clone());
93 })
94 .then(function(result) {
95 assert_false(result,
96 'Cache.delete should not delete if vary does not ' +
97 'match unless ignoreVary is true');
98 return cache.delete(mismatched_vary_request.clone(),
99 {ignoreVary: true});
100 })
101 .then(function(result) {
102 assert_true(result,
103 'Cache.delete should ignore vary if ignoreVary is true');
104 });
105 }, 'Cache.delete supports ignoreVary');
106
107 cache_test(function(cache) {
78 return cache.delete(test_url) 108 return cache.delete(test_url)
79 .then(function(result) { 109 .then(function(result) {
80 assert_false(result, 110 assert_false(result,
81 'Cache.delete should resolve with "false" if there ' + 111 'Cache.delete should resolve with "false" if there ' +
82 'are no matching entries.'); 112 'are no matching entries.');
83 }); 113 });
84 }, 'Cache.delete with a non-existent entry'); 114 }, 'Cache.delete with a non-existent entry');
85 115
86 var cache_entries = { 116 prepopulated_cache_test(simple_entries, function(cache, entries) {
87 a: { 117 return cache.matchAll(entries.a_with_query.request,
88 request: new Request('http://example.com/abc'), 118 { ignoreSearch: true })
89 response: new Response('') 119 .then(function(result) {
120 assert_response_array_equals(
121 result,
122 [
123 entries.a.response,
124 entries.a_with_query.response
125 ]);
126 return cache.delete(entries.a_with_query.request,
127 { ignoreSearch: true });
128 })
129 .then(function(result) {
130 return cache.matchAll(entries.a_with_query.request,
131 { ignoreSearch: true });
132 })
133 .then(function(result) {
134 assert_response_array_equals(result, []);
135 });
90 }, 136 },
137 'Cache.delete with ignoreSearch option (request with search parameters)');
91 138
92 b: { 139 prepopulated_cache_test(simple_entries, function(cache, entries) {
93 request: new Request('http://example.com/b'), 140 return cache.matchAll(entries.a_with_query.request,
94 response: new Response('') 141 { ignoreSearch: true })
142 .then(function(result) {
143 assert_response_array_equals(
144 result,
145 [
146 entries.a.response,
147 entries.a_with_query.response
148 ]);
149 // cache.delete()'s behavior should be the same if ignoreSearch is
150 // not provided or if ignoreSearch is false.
151 return cache.delete(entries.a_with_query.request,
152 { ignoreSearch: false });
153 })
154 .then(function(result) {
155 return cache.matchAll(entries.a_with_query.request,
156 { ignoreSearch: true });
157 })
158 .then(function(result) {
159 assert_response_array_equals(result, [ entries.a.response ]);
160 });
95 }, 161 },
96 162 'Cache.delete with ignoreSearch option (when it is specified as false)');
97 a_with_query: {
98 request: new Request('http://example.com/abc?q=r'),
99 response: new Response('')
100 }
101 };
102
103 function prepopulated_cache_test(test_function, description) {
104 cache_test(function(cache) {
105 return Promise.all(Object.keys(cache_entries).map(function(k) {
106 return cache.put(cache_entries[k].request.clone(),
107 cache_entries[k].response.clone());
108 }))
109 .then(function() {
110 return test_function(cache);
111 });
112 }, description);
113 }
114 163
115 done(); 164 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698