зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1335442 - deal correctly with not importing anything, r=jaws
MozReview-Commit-ID: 3WZCxXV48Ms --HG-- extra : rebase_source : f4ac27b2d9e26b8d9330e7b4839ccd05286c1098
This commit is contained in:
Родитель
f9183caf54
Коммит
48f9baa59d
|
@ -417,6 +417,9 @@ const AutoMigrate = {
|
|||
|
||||
_dejsonifyUndoState(state) {
|
||||
state = JSON.parse(state);
|
||||
if (!state) {
|
||||
return new Map();
|
||||
}
|
||||
for (let bm of state.bookmarks) {
|
||||
bm.lastModified = new Date(bm.lastModified);
|
||||
}
|
||||
|
@ -433,6 +436,13 @@ const AutoMigrate = {
|
|||
this._saveUndoStateTrackerForShutdown = "processing undo history";
|
||||
this._savingPromise = new Promise(resolve => { resolveSavingPromise = resolve });
|
||||
let state = yield MigrationUtils.stopAndRetrieveUndoData();
|
||||
|
||||
if (!state || ![...state.values()].some(ary => ary.length > 0)) {
|
||||
// If we didn't import anything, abort now.
|
||||
resolveSavingPromise();
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
this._saveUndoStateTrackerForShutdown = "writing undo history";
|
||||
this._undoSavePromise = OS.File.writeAtomic(
|
||||
kUndoStateFullPath, this._jsonifyUndoState(state), {
|
||||
|
|
|
@ -144,6 +144,7 @@ add_task(function* checkIntegration() {
|
|||
* Test the undo preconditions and a no-op undo in the automigrator.
|
||||
*/
|
||||
add_task(function* checkUndoPreconditions() {
|
||||
let shouldAddData = false;
|
||||
gShimmedMigrator = {
|
||||
get sourceProfiles() {
|
||||
do_print("Read sourceProfiles");
|
||||
|
@ -155,6 +156,15 @@ add_task(function* checkUndoPreconditions() {
|
|||
},
|
||||
migrate(types, startup, profileToMigrate) {
|
||||
this._migrateArgs = [types, startup, profileToMigrate];
|
||||
if (shouldAddData) {
|
||||
// Insert a login and check that that worked.
|
||||
MigrationUtils.insertLoginWrapper({
|
||||
hostname: "www.mozilla.org",
|
||||
formSubmitURL: "http://www.mozilla.org",
|
||||
username: "user",
|
||||
password: "pass",
|
||||
});
|
||||
}
|
||||
TestUtils.executeSoon(function() {
|
||||
Services.obs.notifyObservers(null, "Migration:Ended", undefined);
|
||||
});
|
||||
|
@ -177,10 +187,35 @@ add_task(function* checkUndoPreconditions() {
|
|||
yield migrationFinishedPromise;
|
||||
Assert.ok(Preferences.has("browser.migrate.automigrate.browser"),
|
||||
"Should have set browser pref");
|
||||
Assert.ok((yield AutoMigrate.canUndo()), "Should be able to undo migration");
|
||||
Assert.ok(!(yield AutoMigrate.canUndo()), "Should not be able to undo migration, as there's no data");
|
||||
gShimmedMigrator._migrateArgs = null;
|
||||
gShimmedMigrator._getMigrateDataArgs = null;
|
||||
Preferences.reset("browser.migrate.automigrate.browser");
|
||||
shouldAddData = true;
|
||||
|
||||
AutoMigrate.migrate("startup");
|
||||
migrationFinishedPromise = TestUtils.topicObserved("Migration:Ended");
|
||||
Assert.strictEqual(gShimmedMigrator._getMigrateDataArgs, null,
|
||||
"getMigrateData called with 'null' as a profile");
|
||||
Assert.deepEqual(gShimmedMigrator._migrateArgs, [expectedTypes, "startup", null],
|
||||
"migrate called with 'null' as a profile");
|
||||
|
||||
yield migrationFinishedPromise;
|
||||
let storedLogins = Services.logins.findLogins({}, "www.mozilla.org",
|
||||
"http://www.mozilla.org", null);
|
||||
Assert.equal(storedLogins.length, 1, "Should have 1 login");
|
||||
|
||||
Assert.ok(Preferences.has("browser.migrate.automigrate.browser"),
|
||||
"Should have set browser pref");
|
||||
Assert.ok((yield AutoMigrate.canUndo()), "Should be able to undo migration, as now there's data");
|
||||
|
||||
yield AutoMigrate.undo();
|
||||
Assert.ok(true, "Should be able to finish an undo cycle.");
|
||||
|
||||
// Check that the undo removed the passwords:
|
||||
storedLogins = Services.logins.findLogins({}, "www.mozilla.org",
|
||||
"http://www.mozilla.org", null);
|
||||
Assert.equal(storedLogins.length, 0, "Should have no logins");
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче