| 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 console.warn('This test relies on console message comparison so there can ' + | |
| 14 'be different -expected.txt files for virtual test suites.'); | |
| 15 | |
| 16 function check_methods(t, script, scope) { | |
| 17 var registration; | |
| 18 var worker; | |
| 19 var message; | |
| 20 var log = ''; | |
| 21 return service_worker_unregister_and_register(t, script, scope) | |
| 22 .then(reg => { | |
| 23 registration = reg; | |
| 24 worker = registration.installing; | |
| 25 return wait_for_state(t, worker, 'activated'); | |
| 26 }) | |
| 27 .then(_ => registration.navigationPreload.disable()) | |
| 28 .then( | |
| 29 result => { log += 'disable() resolved with: ' + result + '\n';}, | |
| 30 error => { log += 'disable() rejected with: ' + error + '\n';}) | |
| 31 .then(_ => registration.navigationPreload.enable()) | |
| 32 .then( | |
| 33 result => { log += 'enable() resolved with: ' + result + '\n';}, | |
| 34 error => { log += 'enable() rejected with: ' + error + '\n';}) | |
| 35 .then(_ => registration.navigationPreload.getState()) | |
| 36 .then( | |
| 37 result => { | |
| 38 log += 'getState() resolved with: ' + JSON.stringify(result) + '\n'; | |
| 39 }, | |
| 40 error => { log += 'getState() rejected with: ' + error + '\n';}) | |
| 41 .then(_ => registration.navigationPreload.setHeaderValue('hello')) | |
| 42 .then( | |
| 43 result => { log += 'setHeaderValue() resolved with: ' + result + '\n';}, | |
| 44 error => { log += 'setHeaderValue() rejected with: ' + error + '\n';}) | |
| 45 .then(_ => with_iframe(scope)) | |
| 46 .then(_ => { | |
| 47 var saw_message = new Promise(resolve => { | |
| 48 navigator.serviceWorker.onmessage = | |
| 49 e => { resolve(e.data); }; | |
| 50 }); | |
| 51 worker.postMessage(""); | |
| 52 return saw_message; | |
| 53 }) | |
| 54 .then(message => { | |
| 55 log += 'log from SW\n' + message; | |
| 56 return registration.unregister(); | |
| 57 }) | |
| 58 .then(_ => { | |
| 59 return log; | |
| 60 }); | |
| 61 } | |
| 62 | |
| 63 promise_test(t => { | |
| 64 var script = 'resources/navigation-preload-origin-trial-methods-worker.php'; | |
| 65 var scope = | |
| 66 'resources/navigation-preload-origin-trial-methods-scope.php?default'; | |
| 67 return check_methods(t, script, scope).then(log => { | |
| 68 console.log('--normal SW--\n' + log); | |
| 69 }); | |
| 70 }, 'Calling Navigation preload related methods for normal SW.'); | |
| 71 | |
| 72 promise_test(t => { | |
| 73 var script = | |
| 74 'resources/navigation-preload-origin-trial-methods-worker.php?' + | |
| 75 'origintrial=true'; | |
| 76 var scope = | |
| 77 'resources/navigation-preload-origin-trial-methods-scope.php?enabled'; | |
| 78 return check_methods(t, script, scope).then(log => { | |
| 79 console.log('--Origin-Trial enabled SW--\n' + log); | |
| 80 }); | |
| 81 }, 'Calling Navigation preload related methods for Origin-Trial enabled SW.'); | |
| 82 </script> | |
| OLD | NEW |