| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/get-state.html
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/get-state.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/get-state.html
|
| index 46b71f9110045add9985fa6d88f6a9bbbecbb3a9..560cc3e87d3c52f95c8650466cd787e4506e24e5 100644
|
| --- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/get-state.html
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/navigation-preload/get-state.html
|
| @@ -4,6 +4,7 @@
|
| <script src="../../resources/testharness.js"></script>
|
| <script src="../../resources/testharnessreport.js"></script>
|
| <script src="../resources/test-helpers.js"></script>
|
| +<script src="resources/helpers.js"></script>
|
| <body>
|
| <script>
|
| function post_and_wait_for_reply(worker, message) {
|
| @@ -13,12 +14,6 @@ function post_and_wait_for_reply(worker, message) {
|
| });
|
| }
|
|
|
| -function expect_state(state, enabled, header, desc) {
|
| - assert_equals(Object.keys(state).length, 2, desc + ': # of keys');
|
| - assert_equals(state.enabled, enabled, desc + ': enabled');
|
| - assert_equals(state.headerValue, header, desc + ': header');
|
| -}
|
| -
|
| promise_test(t => {
|
| const scope = '../resources/get-state';
|
| const script = '../resources/empty-worker.js';
|
| @@ -28,10 +23,11 @@ promise_test(t => {
|
| .then(r => {
|
| np = r.navigationPreload;
|
| add_completion_callback(() => r.unregister());
|
| - return np.getState();
|
| + return wait_for_state(t, r.installing, 'activated');
|
| })
|
| + .then(() => np.getState())
|
| .then(state => {
|
| - expect_state(state, false, 'true', 'default state');
|
| + expect_navigation_preload_state(state, false, 'true', 'default state');
|
| return np.enable();
|
| })
|
| .then(result => {
|
| @@ -40,7 +36,8 @@ promise_test(t => {
|
| return np.getState();
|
| })
|
| .then(state => {
|
| - expect_state(state, true, 'true', 'state after enable()');
|
| + expect_navigation_preload_state(state, true, 'true',
|
| + 'state after enable()');
|
| return np.disable();
|
| })
|
| .then(result => {
|
| @@ -49,7 +46,8 @@ promise_test(t => {
|
| return np.getState();
|
| })
|
| .then(state => {
|
| - expect_state(state, false, 'true', 'state after disable()');
|
| + expect_navigation_preload_state(state, false, 'true',
|
| + 'state after disable()');
|
| return np.setHeaderValue('dreams that cannot be');
|
| })
|
| .then(result => {
|
| @@ -58,16 +56,18 @@ promise_test(t => {
|
| return np.getState();
|
| })
|
| .then(state => {
|
| - expect_state(state, false, 'dreams that cannot be',
|
| - 'state after setHeaderValue()');
|
| + expect_navigation_preload_state(state, false, 'dreams that cannot be',
|
| + 'state after setHeaderValue()');
|
| return np.setHeaderValue('').then(() => np.getState());
|
| })
|
| .then(state => {
|
| - expect_state(state, false, '', 'after setHeaderValue to empty string');
|
| + expect_navigation_preload_state(state, false, '',
|
| + 'after setHeaderValue to empty string');
|
| return np.setHeaderValue(null).then(() => np.getState());
|
| })
|
| .then(state => {
|
| - expect_state(state, false, 'null', 'after setHeaderValue to null');
|
| + expect_navigation_preload_state(state, false, 'null',
|
| + 'after setHeaderValue to null');
|
| return promise_rejects(t,
|
| new TypeError,
|
| np.setHeaderValue('what\uDC00\uD800this'),
|
| @@ -91,9 +91,16 @@ promise_test(t => {
|
| np.setHeaderValue('newline\n'),
|
| 'setHeaderValue() should throw if passed \\n');
|
| })
|
| + .then(() => {
|
| + return promise_rejects(t,
|
| + new TypeError,
|
| + np.setHeaderValue(),
|
| + 'setHeaderValue() should throw if passed undefined');
|
| + })
|
| .then(() => np.enable().then(() => np.getState()))
|
| .then(state => {
|
| - expect_state(state, true, 'null', 'enable() should not change header');
|
| + expect_navigation_preload_state(state, true, 'null',
|
| + 'enable() should not change header');
|
| });
|
| }, 'getState');
|
|
|
| @@ -111,6 +118,9 @@ promise_test(t => {
|
| registration = r;
|
| add_completion_callback(() => registration.unregister());
|
| worker = registration.installing;
|
| + return wait_for_state(t, worker, 'activated');
|
| + })
|
| + .then(() => {
|
| // Call getState().
|
| return post_and_wait_for_reply(worker, 'getState');
|
| })
|
| @@ -118,10 +128,10 @@ promise_test(t => {
|
| return Promise.all([data, registration.navigationPreload.getState()]);
|
| })
|
| .then(states => {
|
| - expect_state(states[0], false, 'true',
|
| - 'default state (from worker)');
|
| - expect_state(states[1], false, 'true',
|
| - 'default state (from page)');
|
| + expect_navigation_preload_state(states[0], false, 'true',
|
| + 'default state (from worker)');
|
| + expect_navigation_preload_state(states[1], false, 'true',
|
| + 'default state (from page)');
|
| // Call enable() and then getState().
|
| return post_and_wait_for_reply(worker, 'enable');
|
| })
|
| @@ -133,10 +143,10 @@ promise_test(t => {
|
| ]);
|
| })
|
| .then(states => {
|
| - expect_state(states[0], true, 'true',
|
| - 'state after enable() (from worker)');
|
| - expect_state(states[1], true, 'true',
|
| - 'state after enable() (from page)');
|
| + expect_navigation_preload_state(states[0], true, 'true',
|
| + 'state after enable() (from worker)');
|
| + expect_navigation_preload_state(states[1], true, 'true',
|
| + 'state after enable() (from page)');
|
| // Call disable() and then getState().
|
| return post_and_wait_for_reply(worker, 'disable');
|
| })
|
| @@ -149,10 +159,10 @@ promise_test(t => {
|
| ]);
|
| })
|
| .then(states => {
|
| - expect_state(states[0], false, 'true',
|
| - 'state after disable() (from worker)');
|
| - expect_state(states[1], false, 'true',
|
| - 'state after disable() (from page)');
|
| + expect_navigation_preload_state(states[0], false, 'true',
|
| + 'state after disable() (from worker)');
|
| + expect_navigation_preload_state(states[1], false, 'true',
|
| + 'state after disable() (from page)');
|
| return post_and_wait_for_reply(worker, 'setHeaderValue');
|
| })
|
| .then(data => {
|
| @@ -163,11 +173,45 @@ promise_test(t => {
|
| registration.navigationPreload.getState()]);
|
| })
|
| .then(states => {
|
| - expect_state(states[0], false, 'insightful',
|
| - 'state after setHeaderValue() (from worker)');
|
| - expect_state(states[1], false, 'insightful',
|
| - 'state after setHeaderValue() (from page)');
|
| + expect_navigation_preload_state(
|
| + states[0], false, 'insightful',
|
| + 'state after setHeaderValue() (from worker)');
|
| + expect_navigation_preload_state(
|
| + states[1], false, 'insightful',
|
| + 'state after setHeaderValue() (from page)');
|
| });
|
| }, 'getState from a worker');
|
| +
|
| +// This tests navigation preload API when there is no active worker. It calls
|
| +// the API from the main page and then from the worker itself.
|
| +promise_test(t => {
|
| + const scope = 'resources/wait-for-activate-worker';
|
| + const script = 'resources/wait-for-activate-worker.js';
|
| + var registration;
|
| + var np;
|
| + return service_worker_unregister_and_register(t, script, scope)
|
| + .then(r => {
|
| + registration = r;
|
| + np = registration.navigationPreload;
|
| + add_completion_callback(() => registration.unregister());
|
| + return Promise.all([
|
| + promise_rejects(
|
| + t, 'InvalidStateError', np.enable(),
|
| + 'enable should reject if there is no active worker'),
|
| + promise_rejects(
|
| + t, 'InvalidStateError', np.disable(),
|
| + 'disable should reject if there is no active worker'),
|
| + promise_rejects(
|
| + t, 'InvalidStateError', np.setHeaderValue('umm'),
|
| + 'setHeaderValue should reject if there is no active worker')]);
|
| + })
|
| + .then(() => np.getState())
|
| + .then(state => {
|
| + expect_navigation_preload_state(state, false, 'true',
|
| + 'state before activation');
|
| + return post_and_wait_for_reply(registration.installing, 'ping');
|
| + })
|
| + .then(result => assert_equals(result, 'PASS'));
|
| + }, 'no active worker');
|
| </script>
|
| </body>
|
|
|