diff --git a/content-index/content-index.https.window.js b/content-index/content-index.https.window.js index 56870707a986af..690b23176c42dc 100644 --- a/content-index/content-index.https.window.js +++ b/content-index/content-index.https.window.js @@ -1,3 +1,4 @@ +// META: script=/resources/test-only-api.js // META: script=/service-workers/service-worker/resources/test-helpers.sub.js // META: script=resources.js 'use strict'; @@ -19,8 +20,19 @@ contentIndexTest(async (t, index) => { await expectTypeError( index.add(createDescription({iconUrl: 'file://some-local-file.png'}))); - await expectTypeError(index.add(createDescription({iconUrl: '/non-existent-icon.png'}))); - await expectTypeError(index.add(createDescription({iconUrl: '/images/broken.png'}))); + + const isFetchingIcons = await fetchesIcons(); + if (isFetchingIcons) { + // If the browser will try to fetch these icons we expect it to fail. + await expectTypeError( + index.add(createDescription({iconUrl: '/non-existent-icon.png'}))); + await expectTypeError( + index.add(createDescription({iconUrl: '/images/broken.png'}))); + } else { + // If the browser will not try to fetch these icons this should succeed. + await index.add(createDescription({iconUrl: '/non-existent-icon.png'})); + await index.add(createDescription({iconUrl: '/images/broken.png'})); + } await expectTypeError(index.add(createDescription({url: 'https://other-domain.com/'}))); await expectTypeError(index.add(createDescription({url: '/different-scope'}))); diff --git a/content-index/resources.js b/content-index/resources.js index 51e98005b03701..cf96dd5390a0c4 100644 --- a/content-index/resources.js +++ b/content-index/resources.js @@ -38,3 +38,20 @@ async function waitForMessageFromServiceWorker() { 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; +} diff --git a/lint.ignore b/lint.ignore index bc3366648f5ee2..6d6edd60e97fa0 100644 --- a/lint.ignore +++ b/lint.ignore @@ -727,6 +727,7 @@ WEB-PLATFORM.TEST:web-bundle/subresource-loading/*.html # https://github.com/web-platform-tests/wpt/issues/16455 # Please consult with ecosystem-infra@chromium.org before adding more. MISSING DEPENDENCY: credential-management/support/otpcredential-helper.js +MISSING DEPENDENCY: resources/chromium/content-index-helpers.js MISSING DEPENDENCY: resources/chromium/contacts_manager_mock.js MISSING DEPENDENCY: resources/chromium/web-bluetooth-test.js MISSING DEPENDENCY: resources/chromium/webusb-test.js diff --git a/resources/chromium/content-index-helpers.js b/resources/chromium/content-index-helpers.js new file mode 100644 index 00000000000000..936fe84c9b10a2 --- /dev/null +++ b/resources/chromium/content-index-helpers.js @@ -0,0 +1,9 @@ +import {ContentIndexService} from '/gen/third_party/blink/public/mojom/content_index/content_index.mojom.m.js'; + +// Returns a promise if the chromium based browser fetches icons for +// content-index. +export async function fetchesIcons() { + const remote = ContentIndexService.getRemote(); + const {iconSizes} = await remote.getIconSizes(); + return iconSizes.length > 0; +};