Skip to content

Commit

Permalink
Fix content-index WPT tests on WebLayer
Browse files Browse the repository at this point in the history
WebLayer does not implement getIconSizes and therefore does not check if
icons are actually valid as they are never fetched. This is the same as
on Chrome desktop platforms. Only Chrome on Android and Content Shell do
currently download and verify content-index icons.
This now makes the WPT pass for both scenarios for Chromium based
browsers. Other browsers can add their own logic once they support the
content-index API.

Bug: 1177892
Change-Id: I06b908363e9e83b0d9207a5835e55214f1f01528
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2874562
Reviewed-by: Michael Moss <[email protected]>
Reviewed-by: Peter Beverloo <[email protected]>
Reviewed-by: Rayan Kanso <[email protected]>
Commit-Queue: Richard Knoll <[email protected]>
Cr-Commit-Position: refs/heads/master@{#881785}
  • Loading branch information
rknoll authored and chromium-wpt-export-bot committed May 12, 2021
1 parent 95eeb24 commit 13e6cb4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
16 changes: 14 additions & 2 deletions content-index/content-index.https.window.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'})));
Expand Down
17 changes: 17 additions & 0 deletions content-index/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ WEB-PLATFORM.TEST:web-bundle/subresource-loading/*.html
# https://github.com/web-platform-tests/wpt/issues/16455
# Please consult with [email protected] 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
Expand Down
9 changes: 9 additions & 0 deletions resources/chromium/content-index-helpers.js
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 13e6cb4

Please sign in to comment.