author | Blink WPT Bot <blink-w3c-test-autoroller@chromium.org> |
Wed, 26 Aug 2020 08:55:45 +0000 | |
changeset 546506 | 510688acfbadbc3d5b0f088aa6b421f9e50f07fb |
parent 546505 | e79096f7efbf773f5d9efe109bd763d064dbd7ff |
child 546507 | e90a613d62fe6a255bf01ae9af5786d49f09f7dd |
push id | 37735 |
push user | abutkovits@mozilla.com |
push date | Thu, 27 Aug 2020 21:29:40 +0000 |
treeherder | mozilla-central@109f3a4de567 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | testonly |
bugs | 1658246, 24933, 1000544, 2344440, 799561 |
milestone | 82.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
testing/web-platform/tests/service-workers/service-worker/resources/test-helpers.sub.js | file | annotate | diff | comparison | revisions |
--- a/testing/web-platform/tests/service-workers/service-worker/resources/test-helpers.sub.js +++ b/testing/web-platform/tests/service-workers/service-worker/resources/test-helpers.sub.js @@ -87,66 +87,76 @@ function wait_for_update(test, registrat var handler = test.step_func(function() { registration.removeEventListener('updatefound', handler); resolve(registration.installing); }); registration.addEventListener('updatefound', handler); })); } -function wait_for_state(test, worker, state) { - if (!worker || worker.state == undefined) { - return Promise.reject(new Error( - 'wait_for_state must be passed a ServiceWorker')); - } - if (worker.state === state) - return Promise.resolve(state); - - if (state === 'installing') { - switch (worker.state) { +// Return true if |state_a| is more advanced than |state_b|. +function is_state_advanced(state_a, state_b) { + if (state_b === 'installing') { + switch (state_a) { case 'installed': case 'activating': case 'activated': case 'redundant': - return Promise.reject(new Error( - 'worker is ' + worker.state + ' but waiting for ' + state)); + return true; } } - if (state === 'installed') { - switch (worker.state) { + if (state_b === 'installed') { + switch (state_a) { case 'activating': case 'activated': case 'redundant': - return Promise.reject(new Error( - 'worker is ' + worker.state + ' but waiting for ' + state)); + return true; + } + } + + if (state_b === 'activating') { + switch (state_a) { + case 'activated': + case 'redundant': + return true; } } - if (state === 'activating') { - switch (worker.state) { - case 'activated': + if (state_b === 'activated') { + switch (state_a) { case 'redundant': - return Promise.reject(new Error( - 'worker is ' + worker.state + ' but waiting for ' + state)); + return true; } } + return false; +} - if (state === 'activated') { - switch (worker.state) { - case 'redundant': - return Promise.reject(new Error( - 'worker is ' + worker.state + ' but waiting for ' + state)); - } +function wait_for_state(test, worker, state) { + if (!worker || worker.state == undefined) { + return Promise.reject(new Error( + 'wait_for_state needs a ServiceWorker object to be passed.')); } + if (worker.state === state) + return Promise.resolve(state); - return new Promise(test.step_func(function(resolve) { + if (is_state_advanced(worker.state, state)) { + return Promise.reject(new Error( + `Waiting for ${state} but the worker is already ${worker.state}.`)); + } + return new Promise(test.step_func(function(resolve, reject) { worker.addEventListener('statechange', test.step_func(function() { if (worker.state === state) resolve(state); + + if (is_state_advanced(worker.state, state)) { + reject(new Error( + `The state of the worker becomes ${worker.state} while waiting` + + `for ${state}.`)); + } })); })); } // Declare a test that runs entirely in the ServiceWorkerGlobalScope. The |url| // is the service worker script URL. This function: // - Instantiates a new test with the description specified in |description|. // The test will succeed if the specified service worker can be successfully