From b885ef1405257655ab789a8dfabd9840cdd012f0 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Tue, 1 Oct 2024 17:35:56 +0000 Subject: [PATCH] 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 --- dom/indexedDB/ActorsParent.cpp | 3 ++ dom/indexedDB/NotifyUtils.cpp | 22 ++++++++++++ dom/indexedDB/NotifyUtils.h | 16 +++++++++ dom/indexedDB/moz.build | 1 + .../test/unit/test_databaseWorkStarted.js | 36 +++++++++++++++++++ .../test/unit/xpcshell-parent-process.toml | 2 ++ 6 files changed, 80 insertions(+) create mode 100644 dom/indexedDB/NotifyUtils.cpp create mode 100644 dom/indexedDB/NotifyUtils.h create mode 100644 dom/indexedDB/test/unit/test_databaseWorkStarted.js diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index a55770bd0034..dc39c41dbba1 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -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; } diff --git a/dom/indexedDB/NotifyUtils.cpp b/dom/indexedDB/NotifyUtils.cpp new file mode 100644 index 000000000000..c79a8d4da134 --- /dev/null +++ b/dom/indexedDB/NotifyUtils.cpp @@ -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 diff --git a/dom/indexedDB/NotifyUtils.h b/dom/indexedDB/NotifyUtils.h new file mode 100644 index 000000000000..45ee9faba123 --- /dev/null +++ b/dom/indexedDB/NotifyUtils.h @@ -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_ diff --git a/dom/indexedDB/moz.build b/dom/indexedDB/moz.build index a102f0254fda..151ed72ed6be 100644 --- a/dom/indexedDB/moz.build +++ b/dom/indexedDB/moz.build @@ -83,6 +83,7 @@ UNIFIED_SOURCES += [ "IndexedDatabaseManager.cpp", "IndexedDBCommon.cpp", "KeyPath.cpp", + "NotifyUtils.cpp", "ProfilerHelpers.cpp", "ReportInternalError.cpp", "SchemaUpgrades.cpp", diff --git a/dom/indexedDB/test/unit/test_databaseWorkStarted.js b/dom/indexedDB/test/unit/test_databaseWorkStarted.js new file mode 100644 index 000000000000..1ed2222c103a --- /dev/null +++ b/dom/indexedDB/test/unit/test_databaseWorkStarted.js @@ -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; +} diff --git a/dom/indexedDB/test/unit/xpcshell-parent-process.toml b/dom/indexedDB/test/unit/xpcshell-parent-process.toml index 0061e1774340..19ea2b0127f4 100644 --- a/dom/indexedDB/test/unit/xpcshell-parent-process.toml +++ b/dom/indexedDB/test/unit/xpcshell-parent-process.toml @@ -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"]