| 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..2696d4eb1667d430d45ad43e2947e403dafd74d1 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,8 +23,9 @@ 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');
|
| return np.enable();
|
| @@ -91,6 +87,12 @@ 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');
|
| @@ -111,6 +113,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');
|
| })
|
| @@ -169,5 +174,36 @@ promise_test(t => {
|
| '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_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>
|
|
|