OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Cache Storage: ignore search with credentials</title> |
| 3 <script src="/resources/testharness.js"></script> |
| 4 <script src="/resources/testharnessreport.js"></script> |
| 5 <script src="../resources/test-helpers.js"></script> |
| 6 <script src="../../serviceworker/resources/test-helpers.js"></script> |
| 7 <script> |
| 8 |
| 9 function remove_query(url_string) { |
| 10 return url_string.split('?')[0]; |
| 11 } |
| 12 |
| 13 function find_request_object(cache, str) { |
| 14 return cache.keys() |
| 15 .then(function(requests) { |
| 16 return requests.find(function(request) { |
| 17 if (request.url.indexOf(str) > 0) |
| 18 return true; |
| 19 return false; |
| 20 }); |
| 21 }) |
| 22 } |
| 23 |
| 24 promise_test(function(test) { |
| 25 var service_worker; |
| 26 var script_url = '../resources/ignore-search-with-credentials-worker.js'; |
| 27 var scope = '../resources/ignore-search-with-credentials-iframe.html'; |
| 28 var cache; |
| 29 var request; |
| 30 return caches.delete('ignore-search') |
| 31 .then(function() { |
| 32 return service_worker_unregister_and_register( |
| 33 test, script_url, scope) |
| 34 }) |
| 35 .then(function(registration) { |
| 36 service_worker = registration.installing; |
| 37 return wait_for_state(test, service_worker, 'activated'); |
| 38 }) |
| 39 .then(function(state) { |
| 40 return with_iframe(scope); |
| 41 }) |
| 42 .then(function(frame) { |
| 43 // The following xhr requests will be cached in service worker. |
| 44 return Promise.all([ |
| 45 frame.contentWindow.xhr('simple.txt?query=test', 'abc', 'def'), |
| 46 frame.contentWindow.xhr('simple.txt', 'abc', 'def'), |
| 47 frame.contentWindow.xhr( |
| 48 'simple.txt?query_without_credential=test') |
| 49 ]); |
| 50 }) |
| 51 .then(function() { |
| 52 return caches.open('ignore-search'); |
| 53 }) |
| 54 .then(function(c) { |
| 55 cache = c; |
| 56 |
| 57 // Per the Fetch spec[1] the Request constructor is intended to throw |
| 58 // if credentails are present in the URL, but the Cache API still |
| 59 // defines matching behavior for credentials. So, we need to make xhr |
| 60 // requests with credentials and save them to cache storage on fetch |
| 61 // event in service worker. Then we can retrieve a request(including |
| 62 // credentials) from the cache storage. |
| 63 // |
| 64 // [1] https://fetch.spec.whatwg.org/#dom-request |
| 65 return find_request_object(cache, 'abc:def'); |
| 66 }) |
| 67 .then(function(r) { |
| 68 request = r; |
| 69 return cache.matchAll(request, { ignoreSearch : true }); |
| 70 }) |
| 71 .then(function(results) { |
| 72 assert_equals(results.length, 2); |
| 73 var expected = remove_query(request.url); |
| 74 assert_equals(remove_query(results[0].url), expected); |
| 75 assert_equals(remove_query(results[1].url), expected); |
| 76 }) |
| 77 }); |
| 78 |
| 79 </script> |
OLD | NEW |