| 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..cc59e92a67aced2355fe6457cb18b2b0b40521cf
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/cachestorage/serviceworker/ignore-search-with-credentials.html
|
| @@ -0,0 +1,79 @@
|
| +<!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>
|
| +
|
| +function remove_query(url_string) {
|
| + return url_string.split('?')[0];
|
| +}
|
| +
|
| +function find_request_object(cache, str) {
|
| + return cache.keys()
|
| + .then(function(requests) {
|
| + return requests.find(function(request) {
|
| + if (request.url.indexOf(str) > 0)
|
| + return true;
|
| + return false;
|
| + });
|
| + })
|
| +}
|
| +
|
| +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';
|
| + var cache;
|
| + var request;
|
| + 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')
|
| + ]);
|
| + })
|
| + .then(function() {
|
| + return caches.open('ignore-search');
|
| + })
|
| + .then(function(c) {
|
| + cache = c;
|
| +
|
| + // Per the Fetch spec[1] the Request constructor is intended to throw
|
| + // if credentails are present in the URL, but the Cache API still
|
| + // defines matching behavior for credentials. So, we need to make xhr
|
| + // requests with credentials and save them to cache storage on fetch
|
| + // event in service worker. Then we can retrieve a request(including
|
| + // credentials) from the cache storage.
|
| + //
|
| + // [1] https://fetch.spec.whatwg.org/#dom-request
|
| + return find_request_object(cache, 'abc:def');
|
| + })
|
| + .then(function(r) {
|
| + request = r;
|
| + return cache.matchAll(request, { ignoreSearch : true });
|
| + })
|
| + .then(function(results) {
|
| + assert_equals(results.length, 2);
|
| + var expected = remove_query(request.url);
|
| + assert_equals(remove_query(results[0].url), expected);
|
| + assert_equals(remove_query(results[1].url), expected);
|
| + })
|
| + });
|
| +
|
| +</script>
|
|
|