Index: third_party/WebKit/LayoutTests/http/tests/cachestorage/script-tests/cache-keys.js |
diff --git a/third_party/WebKit/LayoutTests/http/tests/cachestorage/script-tests/cache-keys.js b/third_party/WebKit/LayoutTests/http/tests/cachestorage/script-tests/cache-keys.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b5a011de05858f06ec069ad76b6c4fd2902d9e3e |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/cachestorage/script-tests/cache-keys.js |
@@ -0,0 +1,69 @@ |
+if (self.importScripts) { |
jkarlin
2016/08/10 13:22:45
You're going to have rebase issues.
https://coder
jsbell
2016/08/10 15:50:10
Hah, great timing. Yeah, that renders some of this
|
+ importScripts('/resources/testharness.js'); |
+ importScripts('../resources/test-helpers.js'); |
+} |
+ |
+var test_url1 = 'https://example.com/foo'; |
+var test_body1 = 'Hello world!'; |
+ |
+var test_url2 = 'https://example.com/wacko'; |
+var test_body2 = 'Hello nurse!'; |
+ |
+cache_test(cache => { |
+ return cache.keys() |
+ .then(requests => { |
+ assert_equals(requests.length, 0); |
+ }); |
+ }, 'Cache.keys() called on an empty cache'); |
+ |
+cache_test(cache => { |
+ return Promise.all([ |
+ cache.put(new Request(test_url1), new Response(test_body1)), |
+ cache.put(new Request(test_url2), new Response(test_body2)) |
+ ]) |
+ .then(() => cache.keys()) |
+ .then(requests => { |
+ assert_equals(requests.length, 2); |
+ assert_true(requests.some(r => r.url === test_url1)); |
+ assert_true(requests.some(r => r.url === test_url2)); |
+ }); |
+ }, 'Cache.keys() called on a cache with entries'); |
+ |
+cache_test(cache => { |
+ return Promise.all([ |
+ cache.put(new Request(test_url1), new Response(test_body1)), |
+ cache.put(new Request(test_url2), new Response(test_body2)) |
+ ]) |
+ .then(() => cache.keys(test_url1)) |
+ .then(requests => { |
+ assert_equals(requests.length, 1); |
jkarlin
2016/08/10 13:22:45
This test fails. Why not expect 2 here?
jsbell
2016/08/10 15:50:10
keys(test_url1) should not match test_url2 so shou
jkarlin
2016/08/10 17:30:04
Acknowledged.
|
+ assert_equals(requests[0].url, test_url1); |
+ }); |
+ }, 'Cache.keys() called with a string URL'); |
+ |
+cache_test(cache => { |
+ return Promise.all([ |
+ cache.put(new Request(test_url1), new Response(test_body1)), |
+ cache.put(new Request(test_url2), new Response(test_body2)) |
+ ]) |
+ .then(() => cache.keys(new Request(test_url1))) |
+ .then(requests => { |
+ assert_equals(requests.length, 1); |
jkarlin
2016/08/10 13:22:45
Ditto
|
+ assert_equals(requests[0].url, test_url1); |
+ }); |
+ }, 'Cache.keys() called with a Request object'); |
+ |
+cache_test(cache => { |
+ return Promise.all([ |
+ cache.put(new Request(test_url1), new Response(test_body1)), |
+ cache.put(new Request(test_url2), new Response(test_body2)) |
+ ]) |
+ .then(() => cache.keys(new Request(test_url1, {method: 'HEAD'}))) |
+ .then(requests => { |
+ assert_equals( |
+ requests.length, 0, |
+ 'HEAD request should not match unless ignoreMethod option is set'); |
+ }); |
+ }, 'Cache.keys() called with a HEAD Request'); |
+ |
+done(); |