Bug 1919507 - Cache: Add a new testing only notification for database work starting; r=dom-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D220260
This commit is contained in:
Jan Varga
2024-10-02 10:34:26 +00:00
parent 76ff5384e2
commit ad672752b7
6 changed files with 79 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
#include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/Maybe.h"
#include "mozIStorageConnection.h"
#include "NotifyUtils.h"
#include "nsIPrincipal.h"
#include "nsIRunnable.h"
#include "nsIThread.h"
@@ -253,6 +254,8 @@ void Context::QuotaInitRunnable::DirectoryLockAcquired(DirectoryLock* aLock) {
Complete(rv);
return;
}
NotifyDatabaseWorkStarted();
}
void Context::QuotaInitRunnable::DirectoryLockFailed() {

22
dom/cache/NotifyUtils.cpp vendored Normal file
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::cache {
void NotifyDatabaseWorkStarted() {
if (!StaticPrefs::dom_caches_testing_enabled()) {
return;
}
quota::NotifyObserversOnMainThread("CacheAPI::DatabaseWorkStarted");
}
} // namespace mozilla::dom::cache

16
dom/cache/NotifyUtils.h vendored Normal file
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_CACHE_NOTIFYUTILS_H_
#define DOM_CACHE_NOTIFYUTILS_H_
namespace mozilla::dom::cache {
void NotifyDatabaseWorkStarted();
} // namespace mozilla::dom::cache
#endif // DOM_CACHE_NOTIFYUTILS_H_

1
dom/cache/moz.build vendored
View File

@@ -66,6 +66,7 @@ UNIFIED_SOURCES += [
"FileUtils.cpp",
"Manager.cpp",
"ManagerId.cpp",
"NotifyUtils.cpp",
"PrincipalVerifier.cpp",
"QuotaClient.cpp",
"ReadStream.cpp",

View File

@@ -0,0 +1,35 @@
/**
* 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 { 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 = new Promise(function (resolve, reject) {
const sandbox = new Cu.Sandbox(principal, {
wantGlobalProperties: ["caches"],
});
sandbox.resolve = resolve;
sandbox.reject = reject;
Cu.evalInSandbox(`caches.open("${name}").then(resolve, reject);`, sandbox);
});
info("Waiting for database work to start");
await TestUtils.topicObserved("CacheAPI::DatabaseWorkStarted");
info("Waiting for database to finish opening");
await openPromise;
});

View File

@@ -12,6 +12,8 @@ skip-if = ["true"]
["test_bug1425146.js"]
["test_databaseWorkStarted.js"]
["test_empty_directories.js"]
["test_migration.js"]