Bug 925101 - Remove legacy signons.txt files. r=dolske

MozReview-Commit-ID: ICZADhIeKiB

--HG--
extra : transplant_source : c%C5%92S%F1%7B%7E%9C%B6%F0%91%E1%C9T%F6%F5I%A23%B0
This commit is contained in:
Ray Lin 2016-04-19 17:28:01 +08:00
Родитель 3a08f86d74
Коммит faf52b7a40
4 изменённых файлов: 105 добавлений и 1 удалений

Просмотреть файл

@ -108,6 +108,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "AsyncShutdown",
XPCOMUtils.defineLazyModuleGetter(this, "LoginManagerParent",
"resource://gre/modules/LoginManagerParent.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "LoginHelper",
"resource://gre/modules/LoginHelper.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "SimpleServiceDiscovery",
"resource://gre/modules/SimpleServiceDiscovery.jsm");
@ -1831,7 +1834,7 @@ BrowserGlue.prototype = {
},
_migrateUI: function BG__migrateUI() {
const UI_VERSION = 37;
const UI_VERSION = 38;
const BROWSER_DOCURL = "chrome://browser/content/browser.xul";
let currentUIVersion;
@ -2197,6 +2200,9 @@ BrowserGlue.prototype = {
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
}
if (currentUIVersion < 38) {
LoginHelper.removeLegacySignonFiles();
}
// Update the migration version.
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
},

Просмотреть файл

@ -450,5 +450,32 @@ this.LoginHelper = {
*/
vanillaObjectsToLogins(logins) {
return logins.map(this.vanillaObjectToLogin);
},
removeLegacySignonFiles() {
const {Constants, Path, File} = Cu.import("resource://gre/modules/osfile.jsm").OS;
const profileDir = Constants.Path.profileDir;
const defaultSignonFilePrefs = new Map([
["signon.SignonFileName", "signons.txt"],
["signon.SignonFileName2", "signons2.txt"],
["signon.SignonFileName3", "signons3.txt"]
]);
const toDeletes = new Set();
for (let [pref, val] of defaultSignonFilePrefs.entries()) {
toDeletes.add(Path.join(profileDir, val));
try {
let signonFile = Services.prefs.getCharPref(pref);
toDeletes.add(Path.join(profileDir, signonFile));
Services.prefs.clearUserPref(pref);
} catch (e) {}
}
for (let file of toDeletes) {
File.remove(file);
}
}
};

Просмотреть файл

@ -0,0 +1,69 @@
/**
* Tests the LoginHelper object.
*/
"use strict";
Cu.import("resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "LoginHelper",
"resource://gre/modules/LoginHelper.jsm");
function* createSignonFile(singon) {
let {file, pref} = singon;
if (pref) {
Services.prefs.setCharPref(pref, file);
}
yield OS.File.writeAtomic(
OS.Path.join(OS.Constants.Path.profileDir, file), new Uint8Array(1));
}
function* isSignonClear(singon) {
const {file, pref} = singon;
const fileExists = yield OS.File.exists(
OS.Path.join(OS.Constants.Path.profileDir, file));
if (pref) {
try {
Services.prefs.getCharPref(pref);
return false;
} catch (e) {}
}
return !fileExists;
}
add_task(function* test_remove_lagecy_signonfile() {
// In the last test case, signons3.txt being deleted even when
// it doesn't exist.
const signonsSettings = [[
{ file: "signons.txt" },
{ file: "signons2.txt" },
{ file: "signons3.txt" }
], [
{ file: "signons.txt", pref: "signon.SignonFileName" },
{ file: "signons2.txt", pref: "signon.SignonFileName2" },
{ file: "signons3.txt", pref: "signon.SignonFileName3" }
], [
{ file: "signons2.txt" },
{ file: "singons.txt", pref: "signon.SignonFileName" },
{ file: "customized2.txt", pref: "signon.SignonFileName2" },
{ file: "customized3.txt", pref: "signon.SignonFileName3" }
]];
for (let setting of signonsSettings) {
for (let singon of setting) {
yield createSignonFile(singon);
}
LoginHelper.removeLegacySignonFiles();
for (let singon of setting) {
equal(yield isSignonClear(singon), true);
}
}
});

Просмотреть файл

@ -9,6 +9,8 @@ support-files = data/**
skip-if = os == "android"
[test_module_LoginStore.js]
skip-if = os == "android"
[test_removeLegacySignonFiles.js]
skip-if = os == "android"
# Test SQLite database backup and migration, applicable to Android only.
[test_storage_mozStorage.js]