Files
sousa-gecko/testing/web-platform/tests/web-extensions/resources/bookmarks/background.js
T
Justin Lulejian 7f2a0c009c Bug 2052938 [wpt PR 61096] - [Extensions] Add WPT tests for alarms, bookmarks, and browsingData APIs., a=testonly
Automatic update from web-platform-tests
[Extensions] Add WPT tests for alarms, bookmarks, and browsingData APIs.

Previously, there were no Web Platform Tests (WPT) for the
chrome.alarms, chrome.bookmarks, and chrome.browsingData APIs in the
web-extensions suite.

This CL adds WPT tests for these three APIs to verify
their presence and basic functionality.

We implemented:
- browser.alarms.extension.js: Tests create, get, getAll, clear,
  clearAll, onAlarm listener registration, and error cases.
- browser.bookmarks.extension.js: Tests create, get, update, search,
  getTree, remove, and error cases.
- browser.browsingData.extension.js: Tests settings, removeCache,
  removeCookies, and error cases.

The tests are added to TestExpectations as [ Failure ] in chromium
since pending changes in web-extensions-helper.js (introduced in
github.com/web-platform-tests/wpt/pull/60872) have not been synced to
chromium/src due to a temporary WPT importer error (see
crbug.com/528388519).

TAG=agy
CONV=13c67052-fc49-4c0d-808e-ae6eaf3802cd

Bug: 527385398
Change-Id: I6923061814f76bfd60e3ab5dd87924c282c714b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8033104
Reviewed-by: Oliver Dunk <oliverdunk@chromium.org>
Auto-Submit: Justin Lulejian <jlulejian@chromium.org>
Commit-Queue: Justin Lulejian <jlulejian@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1657498}

--

wpt-commits: 2ac8a782bce6e2b15be340fb154f04090d31669d
wpt-pr: 61096
2026-07-12 11:55:30 +00:00

114 lines
3.8 KiB
JavaScript

const testTitle = 'WPT Test Bookmark';
const testUrl = 'https://example.com/';
browser.test.runTests([
/**
* Tests presence of `browser.bookmarks.ROOT_NODE_ID`.
*/
function testBookmarksRootNodeId() {
browser.test.assertTrue(
'ROOT_NODE_ID' in browser.bookmarks,
'browser.bookmarks should contain ROOT_NODE_ID property');
browser.test.assertEq(typeof browser.bookmarks.ROOT_NODE_ID, 'string',
'browser.bookmarks.ROOT_NODE_ID should be a string');
},
/**
* Tests `browser.bookmarks.create` and `browser.bookmarks.get`.
*/
async function testBookmarksCreateAndGet() {
const node = await browser.bookmarks.create({
title: testTitle,
url: testUrl,
});
browser.test.assertEq(typeof node.id, 'string',
'Created bookmark ID should be a string');
browser.test.assertEq(node.title, testTitle, 'Bookmark title should match');
browser.test.assertEq(node.url, testUrl, 'Bookmark URL should match');
const retrievedNodes = await browser.bookmarks.get(node.id);
browser.test.assertEq(retrievedNodes.length, 1,
'get should return array with 1 node');
browser.test.assertEq(retrievedNodes[0].id, node.id,
'Retrieved ID should match');
browser.test.assertEq(retrievedNodes[0].title, testTitle,
'Retrieved title should match');
await browser.bookmarks.remove(node.id);
},
/**
* Tests `browser.bookmarks.update`.
*/
async function testBookmarksUpdate() {
const node = await browser.bookmarks.create({
title: testTitle,
url: testUrl,
});
const updatedTitle = 'WPT Test Bookmark Updated';
const updatedNode = await browser.bookmarks.update(node.id, {
title: updatedTitle,
});
browser.test.assertEq(updatedNode.id, node.id,
'Updated node ID should match');
browser.test.assertEq(updatedNode.title, updatedTitle,
'Updated title should match');
await browser.bookmarks.remove(node.id);
},
/**
* Tests `browser.bookmarks.search`.
*/
async function testBookmarksSearch() {
const node = await browser.bookmarks.create({
title: testTitle,
url: testUrl,
});
const searchResults = await browser.bookmarks.search({url: testUrl});
browser.test.assertTrue(searchResults.length > 0,
'Search by URL should return results');
const match = searchResults.find((r) => r.id === node.id);
browser.test.assertTrue(
Boolean(match),
'Search results should include the created bookmark ID');
browser.test.assertEq(match.title, testTitle,
'Search result title should match');
await browser.bookmarks.remove(node.id);
},
/**
* Tests `browser.bookmarks.getTree`.
*/
async function testBookmarksGetTree() {
const tree = await browser.bookmarks.getTree();
browser.test.assertTrue(Array.isArray(tree),
'getTree should return an array');
browser.test.assertTrue(tree.length > 0,
'Bookmark tree should contain root nodes');
},
/**
* Tests `browser.bookmarks.remove`.
*/
async function testBookmarksRemove() {
const node = await browser.bookmarks.create({
title: testTitle,
url: testUrl,
});
await browser.bookmarks.remove(node.id);
try {
await browser.bookmarks.get(node.id);
browser.test.fail('get should reject for removed bookmark');
} catch (e) {
// Expected rejection.
}
},
/**
* Tests `browser.bookmarks.create` error cases.
*/
function testBookmarksErrorCases() {
// Verify `create` throws when passed invalid object types.
browser.test.assertThrows(() => browser.bookmarks.create('invalid'));
}
]);