Bug 1917453 - Use a common helper for observing notifications in tests; r=dom-storage-reviewers,jari

Differential Revision: https://phabricator.services.mozilla.com/D219515
This commit is contained in:
Jan Varga 2024-09-13 12:24:11 +00:00
parent a7b9d641d9
commit 1f464aab35
2 changed files with 15 additions and 25 deletions

View File

@ -3,6 +3,10 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
/* exported testSteps */
async function testSteps() {
info("Sending fake 'idle-daily' notification to QuotaManager");
@ -13,10 +17,5 @@ async function testSteps() {
info("Waiting for maintenance to start");
await new Promise(function (resolve) {
Services.obs.addObserver(function observer(subject, topic) {
Services.obs.removeObserver(observer, topic);
resolve();
}, "QuotaManager::MaintenanceStarted");
});
await TestUtils.topicObserved("QuotaManager::MaintenanceStarted");
}

View File

@ -10,27 +10,18 @@
* below the global usage.
*/
const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
loadScript("dom/quota/test/common/file.js");
function awaitStoragePressure() {
let promise_resolve;
let promise = new Promise(function (resolve) {
promise_resolve = resolve;
});
function observer(subject, topic) {
ok(true, "Got the storage pressure event");
Services.obs.removeObserver(observer, topic);
let usage = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
promise_resolve(usage);
}
Services.obs.addObserver(observer, "QuotaManager::StoragePressure");
return promise;
async function awaitStoragePressure() {
const [subject] = await TestUtils.topicObserved(
"QuotaManager::StoragePressure"
);
const usage = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
return usage;
}
async function testSteps() {