diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/content-index/resources.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/content-index/resources.js')
-rw-r--r-- | testing/web-platform/tests/content-index/resources.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/testing/web-platform/tests/content-index/resources.js b/testing/web-platform/tests/content-index/resources.js new file mode 100644 index 0000000000..cf96dd5390 --- /dev/null +++ b/testing/web-platform/tests/content-index/resources.js @@ -0,0 +1,57 @@ +'use strict'; + +const swUrl = 'resources/sw.js'; +const scope = 'resources/'; + +async function expectTypeError(promise) { + try { + await promise; + assert_unreached('Promise should have rejected'); + } catch (e) { + assert_equals(e.name, 'TypeError'); + } +} + +function createDescription({id = 'id', title = 'title', description = 'description', + category = 'homepage', iconUrl = '/images/green-256x256.png', + url = scope, includeIcons = true}) { + return {id, title, description, category, icons: includeIcons ? [{src: iconUrl}] : [], url}; +} + +// Creates a Promise test for |func| given the |description|. The |func| will be +// executed with the `index` object of an activated Service Worker Registration. +function contentIndexTest(func, description) { + promise_test(async t => { + const registration = await service_worker_unregister_and_register(t, swUrl, scope); + await wait_for_state(t, registration.installing, 'activated'); + return func(t, registration.index); + }, description); +} + +async function waitForMessageFromServiceWorker() { + return await new Promise(resolve => { + const listener = event => { + navigator.serviceWorker.removeEventListener('message', listener); + resolve(event.data); + }; + + navigator.serviceWorker.addEventListener('message', listener); + }); +} + +// Returns a promise if the chromium based browser fetches icons for +// content-index. +async function fetchesIconsChromium() { + const {fetchesIcons} = + await import('/resources/chromium/content-index-helpers.js'); + return fetchesIcons(); +} + +// Returns a promise if the browser fetches icons for content-index and should +// therefore validate them. +async function fetchesIcons() { + if (isChromiumBased) { + return fetchesIconsChromium(); + } + return false; +} |