OLD | NEW |
(Empty) | |
| 1 <!-- Testing page used in ClearSiteDataThrottleTest. --> |
| 2 |
| 3 <html> |
| 4 <head> |
| 5 </head> |
| 6 <body> |
| 7 <img id="some_resource"/> |
| 8 |
| 9 <script> |
| 10 // The C++ side of this test will inform us about the origin on which to |
| 11 // test cross-origin requests. It will be passed in the |other_origin| |
| 12 // query paramater. |
| 13 var other_origin_param_regex = /other_origin=([^&=?]+)/; |
| 14 var other_origin = decodeURIComponent( |
| 15 window.location.search.match(other_origin_param_regex)[1]); |
| 16 |
| 17 if (other_origin == window.location.origin) |
| 18 throw new Error('|other_origin| must be different form the one this page
loads on.'); |
| 19 |
| 20 // Set up a service worker to handle future requests. |
| 21 function register_sw() { |
| 22 worker_url = '?file=worker.js&other_origin=' + encodeURIComponent(other_
origin); |
| 23 navigator.serviceWorker.register(worker_url).then(function() { |
| 24 // Inform the C++ side of this test that the worker is now registered. |
| 25 window.location.hash += 'service-worker-registered'; |
| 26 console.log('Service worker registered.'); |
| 27 }); |
| 28 } |
| 29 |
| 30 // Try to fetch a cross-origin resource with the Clear-Site-Data header. |
| 31 // The service worker is not yet set up, so the header should be honored. |
| 32 var header = encodeURIComponent('{ "types": [ "cookies" ] }'); |
| 33 var url = other_origin + 'some_resource?header=' + header; |
| 34 var image = document.getElementById('some_resource'); |
| 35 image.onload = image.onerror = register_sw; |
| 36 image.src = url; |
| 37 |
| 38 // When the image finishes loading, its onload() event will register |
| 39 // the service worker. |
| 40 </script> |
| 41 </body> |
| 42 </html> |
OLD | NEW |