Index: third_party/WebKit/LayoutTests/http/tests/cachestorage/serviceworker/ignore-search-with-credentials.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/cachestorage/serviceworker/ignore-search-with-credentials.html b/third_party/WebKit/LayoutTests/http/tests/cachestorage/serviceworker/ignore-search-with-credentials.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..79fa412b96fa17e2912909e1e8cf72d3dd99dc81 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/cachestorage/serviceworker/ignore-search-with-credentials.html |
@@ -0,0 +1,69 @@ |
+<!DOCTYPE html> |
+<title>Cache Storage: ignore search with credentials</title> |
+<script src="/resources/testharness.js"></script> |
+<script src="/resources/testharnessreport.js"></script> |
+<script src="../resources/test-helpers.js"></script> |
+<script src="../../serviceworker/resources/test-helpers.js"></script> |
+<script> |
+ |
+var request; |
nhiroki
2016/02/10 07:35:33
Probably you can move this global variable to
pro
zino
2016/02/11 03:35:05
Done.
|
+ |
+function remove_query(url_string) { |
+ return url_string.split('?')[0]; |
+} |
+ |
+function find_request_object(str) { |
+ return caches.open('ignore-search') |
+ .then(function(cache) { |
+ return cache.keys(); |
+ }) |
+ .then(function(requests) { |
+ for (var i = 0; i < requests.length; i++) |
nhiroki
2016/02/10 07:35:33
"Array.prototype.find()" may work?
zino
2016/02/11 03:35:05
Done.
|
+ if (requests[i].url.indexOf(str) > 0) |
+ return requests[i]; |
+ return undefined; |
+ }) |
+} |
+ |
+promise_test(function(test) { |
+ var service_worker; |
+ var script_url = '../resources/ignore-search-with-credentials-worker.js'; |
+ var scope = '../resources/ignore-search-with-credentials-iframe.html'; |
+ return caches.delete('ignore-search') |
+ .then(function() { |
+ return service_worker_unregister_and_register( |
+ test, script_url, scope) |
+ }) |
+ .then(function(registration) { |
+ service_worker = registration.installing; |
+ return wait_for_state(test, service_worker, 'activated'); |
+ }) |
+ .then(function(state) { |
+ return with_iframe(scope); |
+ }) |
+ .then(function(frame) { |
+ // The following xhr requests will be cached in service worker. |
+ return Promise.all([ |
+ frame.contentWindow.xhr('simple.txt?query=test', 'abc', 'def'), |
+ frame.contentWindow.xhr('simple.txt', 'abc', 'def'), |
+ frame.contentWindow.xhr('simple.txt?query_without_credential=test') |
nhiroki
2016/02/10 07:35:32
nit: can you wrap this line at the 80 column?
zino
2016/02/11 03:35:05
Done.
|
+ ]); |
+ }) |
+ .then(function() { |
nhiroki
2016/02/10 07:35:33
Can you add a comment about the reason why we need
zino
2016/02/11 03:35:05
Done.
|
+ return find_request_object('abc:def'); |
+ }) |
+ .then(function(r) { |
+ request = r; |
+ return caches.open('ignore-search') |
nhiroki
2016/02/10 07:35:32
The cache is already opened in find_request_object
zino
2016/02/11 03:35:05
Done.
|
+ .then(function(cache) { |
+ return cache.matchAll(request, { ignoreSearch : true }); |
+ }); |
+ }) |
+ .then(function(result) { |
nhiroki
2016/02/10 07:35:33
s/result/results/
zino
2016/02/11 03:35:05
Done.
|
+ assert_equals(result.length, 2); |
+ assert_equals(remove_query(request.url), remove_query(result[0].url)); |
+ assert_equals(remove_query(request.url), remove_query(result[1].url)); |
nhiroki
2016/02/10 07:35:32
assert_equals() receives 'actual' and 'expected' a
zino
2016/02/11 03:35:05
Done.
|
+ }) |
+ }); |
+ |
+</script> |