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

Differential Revision: https://phabricator.services.mozilla.com/D220245
This commit is contained in:
Jan Varga
2024-10-01 17:35:56 +00:00
parent cce30474b6
commit b885ef1405
6 changed files with 80 additions and 0 deletions

View File

@@ -148,6 +148,7 @@
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/mozalloc.h"
#include "mozilla/storage/Variant.h"
#include "NotifyUtils.h"
#include "nsBaseHashtable.h"
#include "nsCOMPtr.h"
#include "nsClassHashtable.h"
@@ -14886,6 +14887,8 @@ nsresult FactoryOp::SendToIOThread() {
quotaManager->IOThread()->Dispatch(this, NS_DISPATCH_NORMAL)),
NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR, IDB_REPORT_INTERNAL_ERR_LAMBDA);
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::indexedDB {
void NotifyDatabaseWorkStarted() {
if (!StaticPrefs::dom_indexedDB_testing()) {
return;
}
quota::NotifyObserversOnMainThread("IndexedDB::DatabaseWorkStarted");
}
} // namespace mozilla::dom::indexedDB

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_INDEXEDDB_NOTIFYUTILS_H_
#define DOM_INDEXEDDB_NOTIFYUTILS_H_
namespace mozilla::dom::indexedDB {
void NotifyDatabaseWorkStarted();
} // namespace mozilla::dom::indexedDB
#endif // DOM_INDEXEDDB_NOTIFYUTILS_H_

View File

@@ -83,6 +83,7 @@ UNIFIED_SOURCES += [
"IndexedDatabaseManager.cpp",
"IndexedDBCommon.cpp",
"KeyPath.cpp",
"NotifyUtils.cpp",
"ProfilerHelpers.cpp",
"ReportInternalError.cpp",
"SchemaUpgrades.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 { IndexedDBUtils } = ChromeUtils.importESModule(
"resource://testing-common/dom/indexedDB/test/modules/IndexedDBUtils.sys.mjs"
);
const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
/* exported testSteps */
async function testSteps() {
const principal = PrincipalUtils.createPrincipal("https://example.com");
const name = "test_databaseWorkStarted.js";
info("Starting database opening");
const openPromise = (async function () {
const request = indexedDB.openForPrincipal(principal, name);
const promise = IndexedDBUtils.requestFinished(request);
return promise;
})();
info("Waiting for database work to start");
await TestUtils.topicObserved("IndexedDB::DatabaseWorkStarted");
info("Waiting for database to finish opening");
await openPromise;
}

View File

@@ -48,6 +48,8 @@ skip-if = ["tsan"]
["test_connection_idle_maintenance_stop.js"]
["test_databaseWorkStarted.js"]
["test_database_close_without_onclose.js"]
["test_database_onclose.js"]