Backed out changeset 6e87244c4b89 (bug 1541934) for failing xpcshell at test_removeDataFromDomain.js on a CLOSED TREE

This commit is contained in:
Andreea Pavel
2019-04-11 16:57:19 +03:00
parent 3c72d5649c
commit 6f27fe2b0d
14 changed files with 98 additions and 81 deletions

View File

@@ -50,10 +50,6 @@
static mozilla::StaticRefPtr<nsPermissionManager> gPermissionManager;
// Initially, |false|. Set to |true| once shutdown has started, to avoid
// reopening the database.
static bool gIsShuttingDown = false;
using namespace mozilla;
using namespace mozilla::dom;
@@ -289,6 +285,27 @@ already_AddRefed<nsIPrincipal> GetNextSubDomainPrincipal(
return principal.forget();
}
class ClearOriginDataObserver final : public nsIObserver {
~ClearOriginDataObserver() {}
public:
NS_DECL_ISUPPORTS
// nsIObserver implementation.
NS_IMETHOD
Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) override {
MOZ_ASSERT(!nsCRT::strcmp(aTopic, "clear-origin-attributes-data"));
nsCOMPtr<nsIPermissionManager> permManager =
do_GetService("@mozilla.org/permissionmanager;1");
return permManager->RemovePermissionsWithAttributes(
nsDependentString(aData));
}
};
NS_IMPL_ISUPPORTS(ClearOriginDataObserver, nsIObserver)
class MOZ_STACK_CLASS UpgradeHostToOriginHelper {
public:
virtual nsresult Insert(const nsACString& aOrigin, const nsCString& aType,
@@ -821,7 +838,7 @@ NS_IMETHODIMP
CloseDatabaseListener::Complete(nsresult, nsISupports*) {
// Help breaking cycles
RefPtr<nsPermissionManager> manager = mManager.forget();
if (mRebuildOnSuccess && !gIsShuttingDown) {
if (mRebuildOnSuccess && !manager->mIsShuttingDown) {
return manager->InitDB(true);
}
return NS_OK;
@@ -880,9 +897,12 @@ NS_IMETHODIMP DeleteFromMozHostListener::HandleCompletion(uint16_t aReason) {
}
/* static */
void nsPermissionManager::Startup() {
nsCOMPtr<nsIPermissionManager> permManager =
do_GetService("@mozilla.org/permissionmanager;1");
void nsPermissionManager::ClearOriginDataObserverInit() {
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
observerService->AddObserver(new ClearOriginDataObserver(),
"clear-origin-attributes-data",
/* ownsWeak= */ false);
}
////////////////////////////////////////////////////////////////////////////////
@@ -903,7 +923,7 @@ NS_IMPL_ISUPPORTS(nsPermissionManager, nsIPermissionManager, nsIObserver,
nsISupportsWeakReference)
nsPermissionManager::nsPermissionManager()
: mMemoryOnlyDB(false), mLargestID(0) {}
: mMemoryOnlyDB(false), mLargestID(0), mIsShuttingDown(false) {}
nsPermissionManager::~nsPermissionManager() {
// NOTE: Make sure to reject each of the promises in mPermissionKeyPromiseMap
@@ -929,10 +949,6 @@ nsPermissionManager::GetXPCOMSingleton() {
return do_AddRef(gPermissionManager);
}
if (gIsShuttingDown) {
return nullptr;
}
// Create a new singleton nsPermissionManager.
// We AddRef only once since XPCOM has rules about the ordering of module
// teardowns - by the time our module destructor is called, it's too late to
@@ -986,9 +1002,6 @@ nsresult nsPermissionManager::Init() {
if (observerService) {
observerService->AddObserver(this, "profile-before-change", true);
observerService->AddObserver(this, "profile-do-change", true);
observerService->AddObserver(this, "testonly-reload-permissions-from-disk",
true);
observerService->AddObserver(this, "clear-origin-attributes-data", true);
}
// ignore failure here, since it's non-fatal (we can run fine without
@@ -2674,25 +2687,12 @@ NS_IMETHODIMP nsPermissionManager::Observe(nsISupports* aSubject,
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
// The profile is about to change,
// or is going away because the application is shutting down.
gIsShuttingDown = true;
mIsShuttingDown = true;
RemoveAllFromMemory();
CloseDB(false);
} else if (!nsCRT::strcmp(aTopic, "profile-do-change")) {
// the profile has already changed; init the db from the new location
InitDB(false);
} else if (!nsCRT::strcmp(aTopic, "testonly-reload-permissions-from-disk")) {
// Testing mechanism to reload all permissions from disk. Because the
// permission manager automatically initializes itself at startup, tests
// that directly manipulate the permissions database need some way to reload
// the database for their changes to have any effect. This mechanism was
// introduced when moving the permissions manager from on-demand startup to
// always being initialized. This is not guarded by a pref because it's not
// dangerous to reload permissions from disk, just bad for performance.
RemoveAllFromMemory();
CloseDB(false);
InitDB(false);
} else if (!nsCRT::strcmp(aTopic, "clear-origin-attributes-data")) {
return RemovePermissionsWithAttributes(nsDependentString(someData));
}
return NS_OK;

View File

@@ -193,13 +193,12 @@ class nsPermissionManager final : public nsIPermissionManager,
}
/**
* Initialize the permission-manager service.
* The permission manager is always initialized at startup because when it was
* lazy-initialized on demand, it was possible for it to be created once
* shutdown had begun, resulting in the manager failing to correctly shutdown
* because it missed its shutdown observer notification.
* Initialize the "clear-origin-attributes-data" observing.
* Will create a nsPermissionManager instance if needed.
* That way, we can prevent have nsPermissionManager created at startup just
* to be able to clear data when an application is uninstalled.
*/
static void Startup();
static void ClearOriginDataObserverInit();
nsresult RemovePermissionsWithAttributes(
mozilla::OriginAttributesPattern& aAttrs);
@@ -519,6 +518,10 @@ class nsPermissionManager final : public nsIPermissionManager,
// a unique, monotonically increasing id used to identify each database entry
int64_t mLargestID;
// Initially, |false|. Set to |true| once shutdown has started, to avoid
// reopening the database.
bool mIsShuttingDown;
nsCOMPtr<nsIPrefBranch> mDefaultPrefBranch;
// NOTE: Ensure this is the last member since it has a large inline buffer.

View File

@@ -45,9 +45,7 @@ add_task(async function do_test() {
// Set the preference used by the permission manager so the file is read.
Services.prefs.setCharPref("permissions.manager.defaultsUrl", "file://" + file.path);
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
// initialize the permission manager service - it will read that default.
let pm = Cc["@mozilla.org/permissionmanager;1"].
getService(Ci.nsIPermissionManager);

View File

@@ -19,8 +19,6 @@ function run_test() {
Assert.ok(file.exists());
connection.schemaVersion = 3;
connection.executeSimpleSQL(
"DROP TABLE moz_hosts");
connection.executeSimpleSQL(
"CREATE TABLE moz_hosts (" +
" id INTEGER PRIMARY KEY" +
@@ -115,9 +113,6 @@ function run_test() {
);
}
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
let earliestNow = Number(Date.now());
// Initialize the permission manager service
var pm = Cc["@mozilla.org/permissionmanager;1"]

View File

@@ -20,8 +20,6 @@ add_task(async function test() {
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
db.schemaVersion = 4;
db.executeSimpleSQL("DROP TABLE moz_perms");
db.executeSimpleSQL("DROP TABLE moz_hosts");
db.executeSimpleSQL(
"CREATE TABLE moz_hosts (" +
@@ -161,9 +159,6 @@ add_task(async function test() {
await PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory"));
await PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory"));
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
// Force initialization of the nsPermissionManager
for (let permission of Services.perms.enumerator) {
let isExpected = false;

View File

@@ -56,8 +56,6 @@ add_task(function test() {
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
db.schemaVersion = 4;
db.executeSimpleSQL("DROP TABLE moz_perms");
db.executeSimpleSQL("DROP TABLE moz_hosts");
db.executeSimpleSQL(
"CREATE TABLE moz_hosts (" +
@@ -177,9 +175,6 @@ add_task(function test() {
let found = expected.map((it) => 0);
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
// Force initialization of the nsPermissionManager
for (let permission of Services.perms.enumerator) {
let isExpected = false;

View File

@@ -20,8 +20,6 @@ add_task(async function test() {
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
db.schemaVersion = 5;
db.executeSimpleSQL("DROP TABLE moz_perms");
db.executeSimpleSQL("DROP TABLE moz_hosts");
/*
* V5 table
@@ -220,9 +218,6 @@ add_task(async function test() {
await PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory"));
await PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory"));
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
// Force initialization of the nsPermissionManager
for (let permission of Services.perms.enumerator) {
let isExpected = false;

View File

@@ -20,8 +20,6 @@ add_task(function test() {
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
db.schemaVersion = 5;
db.executeSimpleSQL("DROP TABLE moz_perms");
db.executeSimpleSQL("DROP TABLE moz_hosts");
/*
* V5 table
@@ -102,9 +100,6 @@ add_task(function test() {
let found = expected.map((it) => 0);
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
// Force initialization of the nsPermissionManager
for (let permission of Services.perms.enumerator) {
let isExpected = false;

View File

@@ -20,8 +20,6 @@ add_task(async function test() {
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
db.schemaVersion = 6;
db.executeSimpleSQL("DROP TABLE moz_perms");
db.executeSimpleSQL("DROP TABLE moz_hosts");
/*
* V5 table
@@ -220,9 +218,6 @@ add_task(async function test() {
await PlacesTestUtils.addVisits(Services.io.newURI("https://foo.com/some/other/subdirectory"));
await PlacesTestUtils.addVisits(Services.io.newURI("ftp://some.subdomain.of.foo.com:8000/some/subdirectory"));
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
// Force initialization of the nsPermissionManager
for (let permission of Services.perms.enumerator) {
let isExpected = false;

View File

@@ -20,8 +20,6 @@ add_task(function test() {
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
db.schemaVersion = 6;
db.executeSimpleSQL("DROP TABLE moz_perms");
db.executeSimpleSQL("DROP TABLE moz_hosts");
/*
* V5 table
@@ -96,9 +94,6 @@ add_task(function test() {
let found = expected.map((it) => 0);
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
// Force initialization of the nsPermissionManager
for (let permission of Services.perms.enumerator) {
let isExpected = false;

View File

@@ -20,8 +20,6 @@ add_task(async function test() {
let db = Services.storage.openDatabase(GetPermissionsFile(profile));
db.schemaVersion = 7;
db.executeSimpleSQL("DROP TABLE moz_perms");
db.executeSimpleSQL("DROP TABLE moz_hosts");
/*
* V5 table
@@ -200,9 +198,6 @@ add_task(async function test() {
await PlacesTestUtils.addVisits(Services.io.newURI("ftp://127.0.0.1:8080"));
await PlacesTestUtils.addVisits(Services.io.newURI("https://localhost:8080"));
// This will force the permission-manager to reload the data.
Services.obs.notifyObservers(null, "testonly-reload-permissions-from-disk", "");
// Force initialization of the nsPermissionManager
for (let permission of Services.perms.enumerator) {
let isExpected = false;

View File

@@ -256,8 +256,7 @@ nsresult nsLayoutStatics::Initialize() {
ProcessPriorityManager::Init();
nsPermissionManager::Startup();
nsPermissionManager::ClearOriginDataObserverInit();
nsCookieService::AppClearDataObserverInit();
nsApplicationCacheService::AppClearDataObserverInit();

View File

@@ -11,6 +11,7 @@ UNIFIED_SOURCES += [
'test_binding_params.cpp',
'test_file_perms.cpp',
'test_mutex.cpp',
'test_service_init_background_thread.cpp',
'test_spinningSynchronousClose.cpp',
'test_statement_scoper.cpp',
'test_StatementCache.cpp',

View File

@@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim set:sw=2 ts=2 et lcs=trail\:.,tab\:>~ : */
/* 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 "storage_test_harness.h"
#include "nsThreadUtils.h"
/**
* This file tests that the storage service cannot be initialized off the main
* thread.
*/
////////////////////////////////////////////////////////////////////////////////
//// Helpers
class ServiceInitializer : public mozilla::Runnable {
public:
ServiceInitializer() : mozilla::Runnable("ServiceInitializer") {}
NS_IMETHOD Run() override {
// Use an explicit do_GetService instead of getService so that the check in
// getService doesn't blow up.
nsCOMPtr<mozIStorageService> service =
do_GetService("@mozilla.org/storage/service;1");
do_check_false(service);
return NS_OK;
}
};
////////////////////////////////////////////////////////////////////////////////
//// Test Functions
// HACK ALERT: this test fails if it runs after any of the other storage tests
// because the storage service will have been initialized and the
// do_GetService() call in ServiceInitializer::Run will succeed. So we need a
// way to force it to run before all the other storage gtests. As it happens,
// gtest has a concept of "death tests" that, among other things, run before
// all non-death tests. By merely using a "DeathTest" suffix here this becomes
// a death test -- even though it doesn't use any of the normal death test
// features -- which ensures this is the first storage test to run.
TEST(storage_service_init_background_thread_DeathTest, Test)
{
nsCOMPtr<nsIRunnable> event = new ServiceInitializer();
do_check_true(event);
nsCOMPtr<nsIThread> thread;
do_check_success(NS_NewNamedThread("StorageService", getter_AddRefs(thread)));
do_check_success(thread->Dispatch(event, NS_DISPATCH_NORMAL));
// Shutting down the thread will spin the event loop until all work in its
// event queue is completed. This will act as our thread synchronization.
do_check_success(thread->Shutdown());
}