| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <meta charset="utf-8"> | 2 <meta charset="utf-8"> |
| 3 <title>NavigationPreloadManager.getState</title> | 3 <title>NavigationPreloadManager.getState</title> |
| 4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/test-helpers.js"></script> | 6 <script src="../resources/test-helpers.js"></script> |
| 7 <body> | 7 <body> |
| 8 <script> | 8 <script> |
| 9 function post_and_wait_for_reply(worker, message) { | 9 function post_and_wait_for_reply(worker, message) { |
| 10 return new Promise(resolve => { | 10 return new Promise(resolve => { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 promise_test(t => { | 22 promise_test(t => { |
| 23 const scope = '../resources/get-state'; | 23 const scope = '../resources/get-state'; |
| 24 const script = '../resources/empty-worker.js'; | 24 const script = '../resources/empty-worker.js'; |
| 25 var np; | 25 var np; |
| 26 | 26 |
| 27 return service_worker_unregister_and_register(t, script, scope) | 27 return service_worker_unregister_and_register(t, script, scope) |
| 28 .then(r => { | 28 .then(r => { |
| 29 np = r.navigationPreload; | 29 np = r.navigationPreload; |
| 30 add_completion_callback(() => r.unregister()); | 30 add_completion_callback(() => r.unregister()); |
| 31 return np.getState(); | 31 return wait_for_state(t, r.installing, 'activated'); |
| 32 }) | 32 }) |
| 33 .then(() => np.getState()) |
| 33 .then(state => { | 34 .then(state => { |
| 34 expect_state(state, false, 'true', 'default state'); | 35 expect_state(state, false, 'true', 'default state'); |
| 35 return np.enable(); | 36 return np.enable(); |
| 36 }) | 37 }) |
| 37 .then(result => { | 38 .then(result => { |
| 38 assert_equals(result, undefined, | 39 assert_equals(result, undefined, |
| 39 'enable() should resolve to undefined'); | 40 'enable() should resolve to undefined'); |
| 40 return np.getState(); | 41 return np.getState(); |
| 41 }) | 42 }) |
| 42 .then(state => { | 43 .then(state => { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const scope = 'resources/get-state-worker'; | 105 const scope = 'resources/get-state-worker'; |
| 105 const script = 'resources/get-state-worker.js'; | 106 const script = 'resources/get-state-worker.js'; |
| 106 var worker; | 107 var worker; |
| 107 var registration; | 108 var registration; |
| 108 | 109 |
| 109 return service_worker_unregister_and_register(t, script, scope) | 110 return service_worker_unregister_and_register(t, script, scope) |
| 110 .then(r => { | 111 .then(r => { |
| 111 registration = r; | 112 registration = r; |
| 112 add_completion_callback(() => registration.unregister()); | 113 add_completion_callback(() => registration.unregister()); |
| 113 worker = registration.installing; | 114 worker = registration.installing; |
| 115 return wait_for_state(t, worker, 'activated'); |
| 116 }) |
| 117 .then(() => { |
| 114 // Call getState(). | 118 // Call getState(). |
| 115 return post_and_wait_for_reply(worker, 'getState'); | 119 return post_and_wait_for_reply(worker, 'getState'); |
| 116 }) | 120 }) |
| 117 .then(data => { | 121 .then(data => { |
| 118 return Promise.all([data, registration.navigationPreload.getState()]); | 122 return Promise.all([data, registration.navigationPreload.getState()]); |
| 119 }) | 123 }) |
| 120 .then(states => { | 124 .then(states => { |
| 121 expect_state(states[0], false, 'true', | 125 expect_state(states[0], false, 'true', |
| 122 'default state (from worker)'); | 126 'default state (from worker)'); |
| 123 expect_state(states[1], false, 'true', | 127 expect_state(states[1], false, 'true', |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 }) | 168 }) |
| 165 .then(states => { | 169 .then(states => { |
| 166 expect_state(states[0], false, 'insightful', | 170 expect_state(states[0], false, 'insightful', |
| 167 'state after setHeaderValue() (from worker)'); | 171 'state after setHeaderValue() (from worker)'); |
| 168 expect_state(states[1], false, 'insightful', | 172 expect_state(states[1], false, 'insightful', |
| 169 'state after setHeaderValue() (from page)'); | 173 'state after setHeaderValue() (from page)'); |
| 170 }); | 174 }); |
| 171 }, 'getState from a worker'); | 175 }, 'getState from a worker'); |
| 172 </script> | 176 </script> |
| 173 </body> | 177 </body> |
| OLD | NEW |