OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset="utf-8"> |
| 3 <!-- Generate these token with the commands: |
| 4 generate_token.py http://127.0.0.1:8000 ServiceWorkerNavigationPreload -expire-
timestamp=2000000000 |
| 5 --> |
| 6 <meta http-equiv="origin-trial" content="AsAA4dg2Rm+GSgnpyxxnpVk1Bk8CcE+qVBTDpPb
IFNscyNRJOdqw1l0vkC4dtsGm1tmP4ZDAKwycQDzsc9xr7gMAAABmeyJvcmlnaW4iOiAiaHR0cDovLzE
yNy4wLjAuMTo4MDAwIiwgImZlYXR1cmUiOiAiU2VydmljZVdvcmtlck5hdmlnYXRpb25QcmVsb2FkIiw
gImV4cGlyeSI6IDIwMDAwMDAwMDB9" /> |
| 7 <title>Navigation Preload origin trial</title> |
| 8 <script src="../../resources/testharness.js"></script> |
| 9 <script src="../../resources/testharnessreport.js"></script> |
| 10 <script src="../resources/test-helpers.js"></script> |
| 11 <script src="./resources/get_interface_names.js"></script> |
| 12 <script> |
| 13 function check_methods(t, script, scope) { |
| 14 var registration; |
| 15 var worker; |
| 16 var message; |
| 17 var log = ''; |
| 18 return service_worker_unregister_and_register(t, script, scope) |
| 19 .then(reg => { |
| 20 registration = reg; |
| 21 worker = registration.installing; |
| 22 return wait_for_state(t, worker, 'activated'); |
| 23 }) |
| 24 .then(_ => registration.navigationPreload.disable()) |
| 25 .then( |
| 26 result => { log += 'disable() resolved with: ' + result + '\n';}, |
| 27 error => { log += 'disable() rejected with: ' + error + '\n';}) |
| 28 .then(_ => registration.navigationPreload.enable()) |
| 29 .then( |
| 30 result => { log += 'enable() resolved with: ' + result + '\n';}, |
| 31 error => { log += 'enable() rejected with: ' + error + '\n';}) |
| 32 .then(_ => registration.navigationPreload.getState()) |
| 33 .then( |
| 34 result => { |
| 35 log += 'getState() resolved with: ' + JSON.stringify(result) + '\n'; |
| 36 }, |
| 37 error => { log += 'getState() rejected with: ' + error + '\n';}) |
| 38 .then(_ => registration.navigationPreload.setHeaderValue('hello')) |
| 39 .then( |
| 40 result => { log += 'setHeaderValue() resolved with: ' + result + '\n';}, |
| 41 error => { log += 'setHeaderValue() rejected with: ' + error + '\n';}) |
| 42 .then(_ => with_iframe(scope)) |
| 43 .then(_ => { |
| 44 var saw_message = new Promise(resolve => { |
| 45 navigator.serviceWorker.onmessage = |
| 46 e => { resolve(e.data); }; |
| 47 }); |
| 48 worker.postMessage(""); |
| 49 return saw_message; |
| 50 }) |
| 51 .then(message => { |
| 52 log += 'log from SW\n' + message; |
| 53 return registration.unregister(); |
| 54 }) |
| 55 .then(_ => { |
| 56 return log; |
| 57 }); |
| 58 } |
| 59 |
| 60 promise_test(t => { |
| 61 var script = 'resources/navigation-preload-origin-trial-methods-worker.php'; |
| 62 var scope = |
| 63 'resources/navigation-preload-origin-trial-methods-scope.php?default'; |
| 64 return check_methods(t, script, scope).then(log => { |
| 65 console.log('--normal SW--\n' + log); |
| 66 }); |
| 67 }, 'Calling Navigation preload related methods for normal SW.'); |
| 68 |
| 69 promise_test(t => { |
| 70 var script = |
| 71 'resources/navigation-preload-origin-trial-methods-worker.php?' + |
| 72 'origintrial=true'; |
| 73 var scope = |
| 74 'resources/navigation-preload-origin-trial-methods-scope.php?enabled'; |
| 75 return check_methods(t, script, scope).then(log => { |
| 76 console.log('--Origin-Trial enabled SW--\n' + log); |
| 77 }); |
| 78 }, 'Calling Navigation preload related methods for Origin-Trial enabled SW.'); |
| 79 </script> |
OLD | NEW |