зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1608025 - Add tests for the removal of old indexedDB/ and storage/persistent/ directories; r=asuth
This patch also refactors relevant upgrade methods to do the removal directly. Differential Revision: https://phabricator.services.mozilla.com/D59702 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
68e8c0c78c
Коммит
37fc02fdf4
|
@ -5288,7 +5288,13 @@ QuotaManager::MaybeUpgradeFromIndexedDBDirectoryToPersistentStorageDirectory() {
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
NS_WARNING("indexedDB directory shouldn't exist after the upgrade!");
|
QM_WARNING("Deleting old <profile>/indexedDB directory!");
|
||||||
|
|
||||||
|
rv = indexedDBDir->Remove(/* aRecursive */ true);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5361,7 +5367,13 @@ nsresult QuotaManager::
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
NS_WARNING("storage/persistent shouldn't exist after the upgrade!");
|
QM_WARNING("Deleting old <profile>/storage/persistent directory!");
|
||||||
|
|
||||||
|
rv = persistentStorageDir->Remove(/* aRecursive */ true);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5419,61 +5431,6 @@ nsresult QuotaManager::
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult QuotaManager::MaybeRemoveOldDirectories() {
|
|
||||||
AssertIsOnIOThread();
|
|
||||||
|
|
||||||
nsCOMPtr<nsIFile> indexedDBDir;
|
|
||||||
nsresult rv =
|
|
||||||
NS_NewLocalFile(mIndexedDBPath, false, getter_AddRefs(indexedDBDir));
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool exists;
|
|
||||||
rv = indexedDBDir->Exists(&exists);
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exists) {
|
|
||||||
QM_WARNING("Deleting old <profile>/indexedDB directory!");
|
|
||||||
|
|
||||||
rv = indexedDBDir->Remove(/* aRecursive */ true);
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIFile> persistentStorageDir;
|
|
||||||
rv = NS_NewLocalFile(mStoragePath, false,
|
|
||||||
getter_AddRefs(persistentStorageDir));
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = persistentStorageDir->Append(
|
|
||||||
NS_LITERAL_STRING(PERSISTENT_DIRECTORY_NAME));
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = persistentStorageDir->Exists(&exists);
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exists) {
|
|
||||||
QM_WARNING("Deleting old <profile>/storage/persistent directory!");
|
|
||||||
|
|
||||||
rv = persistentStorageDir->Remove(/* aRecursive */ true);
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Helper>
|
template <typename Helper>
|
||||||
nsresult QuotaManager::UpgradeStorage(const int32_t aOldVersion,
|
nsresult QuotaManager::UpgradeStorage(const int32_t aOldVersion,
|
||||||
const int32_t aNewVersion,
|
const int32_t aNewVersion,
|
||||||
|
@ -6340,11 +6297,6 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = MaybeRemoveOldDirectories();
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<mozIStorageService> ss =
|
nsCOMPtr<mozIStorageService> ss =
|
||||||
|
|
|
@ -509,8 +509,6 @@ class QuotaManager final : public BackgroundThreadObject {
|
||||||
nsresult
|
nsresult
|
||||||
MaybeUpgradeFromPersistentStorageDirectoryToDefaultStorageDirectory();
|
MaybeUpgradeFromPersistentStorageDirectoryToDefaultStorageDirectory();
|
||||||
|
|
||||||
nsresult MaybeRemoveOldDirectories();
|
|
||||||
|
|
||||||
template <typename Helper>
|
template <typename Helper>
|
||||||
nsresult UpgradeStorage(const int32_t aOldVersion, const int32_t aNewVersion,
|
nsresult UpgradeStorage(const int32_t aOldVersion, const int32_t aNewVersion,
|
||||||
mozIStorageConnection* aConnection);
|
mozIStorageConnection* aConnection);
|
||||||
|
|
Двоичные данные
dom/quota/test/unit/upgrades/indexedDBAndPersistentStorageDirectory_profile.zip
Normal file
Двоичные данные
dom/quota/test/unit/upgrades/indexedDBAndPersistentStorageDirectory_profile.zip
Normal file
Двоичный файл не отображается.
Двоичные данные
dom/quota/test/unit/upgrades/persistentAndDefaultStorageDirectory_profile.zip
Normal file
Двоичные данные
dom/quota/test/unit/upgrades/persistentAndDefaultStorageDirectory_profile.zip
Normal file
Двоичный файл не отображается.
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test is mainly to verify that the old directory is removed in
|
||||||
|
* MaybeUpgradeFromIndexedDBDirectoryToPersistentStorageDirectory method.
|
||||||
|
*/
|
||||||
|
|
||||||
|
async function testSteps() {
|
||||||
|
const url = "http://www.mozilla.org";
|
||||||
|
const persistence = "default";
|
||||||
|
|
||||||
|
info("Clearing");
|
||||||
|
|
||||||
|
let request = clear();
|
||||||
|
await requestFinished(request);
|
||||||
|
|
||||||
|
info("Installing package");
|
||||||
|
|
||||||
|
// Storage used by FF 26-35 (storage/persistent/ directory and re-created
|
||||||
|
// indexedDB directory by an older FF).
|
||||||
|
installPackage("indexedDBAndPersistentStorageDirectory_profile");
|
||||||
|
|
||||||
|
info("Checking directories");
|
||||||
|
|
||||||
|
let indexedDBDir = getRelativeFile("indexedDB");
|
||||||
|
let exists = indexedDBDir.exists();
|
||||||
|
ok(exists, "IndexedDB directory does exist");
|
||||||
|
|
||||||
|
let persistentStorageDir = getRelativeFile("storage/persistent");
|
||||||
|
exists = persistentStorageDir.exists();
|
||||||
|
ok(exists, "Persistent storage directory does exist");
|
||||||
|
|
||||||
|
info("Initializing");
|
||||||
|
|
||||||
|
request = init();
|
||||||
|
await requestFinished(request);
|
||||||
|
|
||||||
|
info("Checking directories");
|
||||||
|
|
||||||
|
indexedDBDir = getRelativeFile("indexedDB");
|
||||||
|
exists = indexedDBDir.exists();
|
||||||
|
ok(!exists, "IndexedDB directory doesn't exist");
|
||||||
|
|
||||||
|
// FF 36 renamed storage/persistent/ to storage/default/ so it can't exist
|
||||||
|
// either.
|
||||||
|
persistentStorageDir = getRelativeFile("storage/persistent");
|
||||||
|
exists = persistentStorageDir.exists();
|
||||||
|
ok(!exists, "Persistent storage directory doesn't exist");
|
||||||
|
|
||||||
|
info("Initializing origin");
|
||||||
|
|
||||||
|
request = initStorageAndOrigin(getPrincipal(url), persistence);
|
||||||
|
await requestFinished(request);
|
||||||
|
|
||||||
|
ok(!request.result, "Origin directory wasn't created");
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
/**
|
||||||
|
* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test is mainly to verify that the old directory is removed in
|
||||||
|
* MaybeUpgradeFromPersistentStorageDirectoryToDefaultStorageDirectory method.
|
||||||
|
*/
|
||||||
|
|
||||||
|
async function testSteps() {
|
||||||
|
const url = "http://www.mozilla.org";
|
||||||
|
const persistence = "default";
|
||||||
|
const lastAccessed = 0x0005330925e07841;
|
||||||
|
|
||||||
|
info("Clearing");
|
||||||
|
|
||||||
|
let request = clear();
|
||||||
|
await requestFinished(request);
|
||||||
|
|
||||||
|
info("Installing package");
|
||||||
|
|
||||||
|
// Storage used by FF 36-48 (storage/default/ directory and re-created
|
||||||
|
// storage/persistent/ directory by an older FF).
|
||||||
|
installPackage("persistentAndDefaultStorageDirectory_profile");
|
||||||
|
|
||||||
|
info("Checking directories");
|
||||||
|
|
||||||
|
let persistentStorageDir = getRelativeFile("storage/persistent");
|
||||||
|
let exists = persistentStorageDir.exists();
|
||||||
|
ok(exists, "Persistent storage directory does exist");
|
||||||
|
|
||||||
|
let defaultStorageDir = getRelativeFile("storage/default");
|
||||||
|
exists = defaultStorageDir.exists();
|
||||||
|
ok(exists, "Default storage directory does exist");
|
||||||
|
|
||||||
|
info("Initializing");
|
||||||
|
|
||||||
|
request = init();
|
||||||
|
await requestFinished(request);
|
||||||
|
|
||||||
|
info("Checking directories");
|
||||||
|
|
||||||
|
persistentStorageDir = getRelativeFile("storage/persistent");
|
||||||
|
exists = persistentStorageDir.exists();
|
||||||
|
ok(!exists, "Persistent storage directory doesn't exist");
|
||||||
|
|
||||||
|
defaultStorageDir = getRelativeFile("storage/default");
|
||||||
|
exists = defaultStorageDir.exists();
|
||||||
|
ok(exists, "Default storage directory does exist");
|
||||||
|
|
||||||
|
info("Initializing origin");
|
||||||
|
|
||||||
|
request = initStorageAndOrigin(getPrincipal(url), persistence);
|
||||||
|
await requestFinished(request);
|
||||||
|
|
||||||
|
ok(!request.result, "Origin directory wasn't created");
|
||||||
|
|
||||||
|
info("Getting usage");
|
||||||
|
|
||||||
|
request = getUsage(function() {}, /* getAll */ true);
|
||||||
|
await requestFinished(request);
|
||||||
|
|
||||||
|
info("Verifying result");
|
||||||
|
|
||||||
|
const result = request.result;
|
||||||
|
is(result.length, 1, "Correct number of usage results");
|
||||||
|
|
||||||
|
info("Verifying usage result");
|
||||||
|
|
||||||
|
const usageResult = result[0];
|
||||||
|
ok(usageResult.origin == url, "Origin equals");
|
||||||
|
ok(usageResult.lastAccessed == lastAccessed, "LastAccessed equals");
|
||||||
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
head = head.js
|
head = head.js
|
||||||
support-files =
|
support-files =
|
||||||
|
indexedDBAndPersistentStorageDirectory_profile.zip
|
||||||
indexedDBDirectory_flatOriginDirectories_profile.zip
|
indexedDBDirectory_flatOriginDirectories_profile.zip
|
||||||
indexedDBDirectory_profile.zip
|
indexedDBDirectory_profile.zip
|
||||||
localStorageArchive1upgrade_profile.zip
|
localStorageArchive1upgrade_profile.zip
|
||||||
|
@ -13,6 +14,7 @@ support-files =
|
||||||
morgueCleanup_profile.zip
|
morgueCleanup_profile.zip
|
||||||
obsoleteOriginAttributes_profile.zip
|
obsoleteOriginAttributes_profile.zip
|
||||||
originAttributesUpgrade_profile.zip
|
originAttributesUpgrade_profile.zip
|
||||||
|
persistentAndDefaultStorageDirectory_profile.zip
|
||||||
persistentStorageDirectory_flatOriginDirectories_profile.zip
|
persistentStorageDirectory_flatOriginDirectories_profile.zip
|
||||||
persistentStorageDirectory_originDirectories_profile.zip
|
persistentStorageDirectory_originDirectories_profile.zip
|
||||||
persistentStorageDirectory_profile.zip
|
persistentStorageDirectory_profile.zip
|
||||||
|
@ -27,7 +29,9 @@ support-files =
|
||||||
[test_obsoleteOrigins.js]
|
[test_obsoleteOrigins.js]
|
||||||
[test_originAttributesUpgrade.js]
|
[test_originAttributesUpgrade.js]
|
||||||
[test_upgradeFromIndexedDBDirectory.js]
|
[test_upgradeFromIndexedDBDirectory.js]
|
||||||
|
[test_upgradeFromIndexedDBDirectory_removeOldDirectory.js]
|
||||||
[test_upgradeFromFlatOriginDirectories.js]
|
[test_upgradeFromFlatOriginDirectories.js]
|
||||||
[test_upgradeFromPersistentStorageDirectory.js]
|
[test_upgradeFromPersistentStorageDirectory.js]
|
||||||
|
[test_upgradeFromPersistentStorageDirectory_removeOldDirectory.js]
|
||||||
[test_upgradeFromPersistentStorageDirectory_upgradeOriginDirectories.js]
|
[test_upgradeFromPersistentStorageDirectory_upgradeOriginDirectories.js]
|
||||||
[test_version2_1upgrade.js]
|
[test_version2_1upgrade.js]
|
||||||
|
|
Загрузка…
Ссылка в новой задаче