Bug 1919428 - SDB: Add a new testing only notification for database work starting; r=dom-storage-reviewers,jari

Differential Revision: https://phabricator.services.mozilla.com/D220107
This commit is contained in:
Jan Varga 2024-09-30 17:01:49 +00:00
parent 64442a38cd
commit c963354f7a
6 changed files with 80 additions and 0 deletions

View File

@ -48,6 +48,7 @@
#include "mozilla/ipc/PBackgroundParent.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "NotifyUtils.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsError.h"
@ -1162,6 +1163,8 @@ nsresult OpenOp::SendToIOThread() {
return rv;
}
simpledb::NotifyDatabaseWorkStarted();
return NS_OK;
}

View File

@ -0,0 +1,22 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "NotifyUtils.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/dom/quota/NotifyUtilsCommon.h"
namespace mozilla::dom::simpledb {
void NotifyDatabaseWorkStarted() {
if (!StaticPrefs::dom_quotaManager_testing()) {
return;
}
quota::NotifyObserversOnMainThread("SimpleDB::DatabaseWorkStarted");
}
} // namespace mozilla::dom::simpledb

View File

@ -0,0 +1,16 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef DOM_SIMPLEDB_NOTIFYUTILS_H_
#define DOM_SIMPLEDB_NOTIFYUTILS_H_
namespace mozilla::dom::simpledb {
void NotifyDatabaseWorkStarted();
} // namespace mozilla::dom::simpledb
#endif // DOM_SIMPLEDB_NOTIFYUTILS_H_

View File

@ -26,6 +26,7 @@ EXPORTS.mozilla.dom += [
UNIFIED_SOURCES += [
"ActorsChild.cpp",
"ActorsParent.cpp",
"NotifyUtils.cpp",
"SDBConnection.cpp",
"SDBRequest.cpp",
"SDBResults.cpp",

View File

@ -0,0 +1,36 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const { PrincipalUtils } = ChromeUtils.importESModule(
"resource://testing-common/dom/quota/test/modules/PrincipalUtils.sys.mjs"
);
const { SimpleDBUtils } = ChromeUtils.importESModule(
"resource://testing-common/dom/simpledb/test/modules/SimpleDBUtils.sys.mjs"
);
const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
add_task(async function testSteps() {
const principal = PrincipalUtils.createPrincipal("https://example.com");
const name = "test_databaseWorkStarted.js";
info("Starting database opening");
const openPromise = (async function () {
const connection = SimpleDBUtils.createConnection(principal);
const request = connection.open(name);
const promise = SimpleDBUtils.requestFinished(request);
return promise;
})();
info("Waiting for database work to start");
await TestUtils.topicObserved("SimpleDB::DatabaseWorkStarted");
info("Waiting for database to finish opening");
await openPromise;
});

View File

@ -1,4 +1,6 @@
[DEFAULT]
head = "head.js"
["test_databaseWorkStarted.js"]
["test_slowStorageInitialization.js"]