Files
tubestation/testing/web-platform/tests/content-index/content-index.https.window.js
Richard Knoll 7a9b2682fa Bug 1710142 [wpt PR 28906] - Fix content-index WPT tests on WebLayer, a=testonly
Automatic update from web-platform-tests
Fix content-index WPT tests on WebLayer

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 <mmoss@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Reviewed-by: Rayan Kanso <rayankans@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#881785}

--

wpt-commits: 13e6cb4144546d7fb4065f17f103d2fcbe982323
wpt-pr: 28906
2021-05-14 04:50:34 +00:00

101 lines
3.2 KiB
JavaScript

// META: script=/resources/test-only-api.js
// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
// META: script=resources.js
'use strict';
contentIndexTest(async (t, index) => {
// Exposure of the interface and method.
assert_own_property(window, 'ContentIndex');
assert_own_property(ContentIndex.prototype, 'add');
assert_idl_attribute(index, 'add');
assert_idl_attribute(index, 'delete');
assert_idl_attribute(index, 'getAll');
}, 'The Content Index API is exposed');
contentIndexTest(async (t, index) => {
await expectTypeError(
index.add(createDescription({category: 'fake-category'})));
await expectTypeError(
index.add(createDescription({iconUrl: 'file://some-local-file.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'})));
await index.add(createDescription({}));
}, 'index.add parameters are validated.');
contentIndexTest(async (t, index) => {
const description = createDescription({});
// Initially there are no descriptions.
assert_array_equals(await index.getAll(), []);
await index.add(description);
const descriptions = await index.getAll();
assert_equals(descriptions.length, 1);
assert_object_equals(descriptions[0], description);
}, 'index.getAll returns the same objects provided.');
contentIndexTest(async (t, index) => {
const description1 = createDescription({title: 'title1'});
const description2 = createDescription({title: 'title2'});
await index.add(description1);
await index.add(description2);
// There should be one description.
const descriptions = await index.getAll();
assert_equals(descriptions.length, 1);
assert_object_equals(descriptions[0], description2);
}, 'index.add with same ID overwrites existing entry.');
contentIndexTest(async (t, index) => {
const description1 = createDescription({id: 'id1'});
const description2 = createDescription({id: 'id2'});
await index.add(description1);
await index.add(description2);
// There should be two descriptions.
assert_equals((await index.getAll()).length, 2);
await index.delete('id1');
// There should be one description.
const descriptions = await index.getAll();
assert_equals(descriptions.length, 1);
assert_object_equals(descriptions[0], description2);
}, 'index.delete removes entry.');
contentIndexTest(async (t, index) => {
const descriptions = await index.getAll();
assert_equals(descriptions.length, 0);
await index.delete('id');
}, 'index.delete works on invalid ID.');