Bug 1917462 - IDB: Create a new module for testing; r=dom-storage-reviewers,jari

Differential Revision: https://phabricator.services.mozilla.com/D219628
This commit is contained in:
Jan Varga 2024-09-16 22:17:05 +00:00
Родитель 0ca28d9582
Коммит 2877178ce9
3 изменённых файлов: 54 добавлений и 1 удалений

Просмотреть файл

@ -24,7 +24,7 @@ XPCSHELL_TESTS_MANIFESTS += [
"test/unit/xpcshell-parent-process.toml",
]
TEST_DIRS += ["test/gtest"]
TEST_DIRS += ["test"]
XPIDL_SOURCES += [
"nsIIndexedDatabaseManager.idl",

Просмотреть файл

@ -0,0 +1,42 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
export const IndexedDBUtils = {
/**
* Handles the completion of a request, awaiting either the `onsuccess` or
* `onerror` event before proceeding.
*
* This function is designed to handle requests of the types:
* - `IDBRequest`
* - `IDBOpenDBRequest`
*
* These requests are typically returned by IndexedDB API.
*
* @param {IDBRequest|IDBOpenDBRequest} request
* The request object, which must have `onsuccess` and `onerror` event
* handlers, as well as result and error properties.
* @returns {Promise}
* Resolves with the request's result when the operation is successful.
* @throws {Error}
* If the request encounters an error, this function throws the request's
* `error` property.
*/
async requestFinished(request) {
await new Promise(function (resolve) {
request.onerror = function () {
resolve();
};
request.onsuccess = function () {
resolve();
};
});
if (request.error) {
throw request.error;
}
return request.result;
},
};

Просмотреть файл

@ -0,0 +1,11 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
TEST_DIRS += ["gtest"]
TESTING_JS_MODULES.dom.indexedDB.test.modules += [
"modules/system/IndexedDBUtils.sys.mjs",
]