Bug 1335442 - update wording of automigration notification bar and add tests, r=jaws
MozReview-Commit-ID: EkuOQmRjqOF
--- a/browser/components/migration/AutoMigrate.jsm
+++ b/browser/components/migration/AutoMigrate.jsm
@@ -7,16 +7,17 @@
this.EXPORTED_SYMBOLS = ["AutoMigrate"];
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
const kAutoMigrateEnabledPref = "browser.migrate.automigrate.enabled";
const kUndoUIEnabledPref = "browser.migrate.automigrate.ui.enabled";
const kAutoMigrateBrowserPref = "browser.migrate.automigrate.browser";
+const kAutoMigrateImportedItemIds = "browser.migrate.automigrate.imported-items";
const kAutoMigrateLastUndoPromptDateMsPref = "browser.migrate.automigrate.lastUndoPromptDateMs";
const kAutoMigrateDaysToOfferUndoPref = "browser.migrate.automigrate.daysToOfferUndo";
const kAutoMigrateUndoSurveyPref = "browser.migrate.automigrate.undo-survey";
const kAutoMigrateUndoSurveyLocalePref = "browser.migrate.automigrate.undo-survey-locales";
const kNotificationId = "automigration-undo";
@@ -34,16 +35,21 @@ XPCOMUtils.defineLazyModuleGetter(this,
"resource://gre/modules/NewTabUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
"resource://gre/modules/TelemetryStopwatch.jsm");
+XPCOMUtils.defineLazyGetter(this, "gBrandBundle", function() {
+ const kBrandBundle = "chrome://branding/locale/brand.properties";
+ return Services.strings.createBundle(kBrandBundle);
+});
+
Cu.importGlobalProperties(["URL"]);
/* globals kUndoStateFullPath */
XPCOMUtils.defineLazyGetter(this, "kUndoStateFullPath", function() {
return OS.Path.join(OS.Constants.Path.profileDir, "initialMigrationMetadata.jsonlz4");
});
const AutoMigrate = {
@@ -304,16 +310,22 @@ const AutoMigrate = {
getBrowserUsedForMigration() {
let browserId = Services.prefs.getCharPref(kAutoMigrateBrowserPref);
if (browserId) {
return MigrationUtils.getBrowserName(browserId);
}
return null;
},
+ /**
+ * Show the user a notification bar indicating we automatically imported
+ * their data and offering them the possibility of removing it.
+ * @param target (xul:browser)
+ * The browser in which we should show the notification.
+ */
maybeShowUndoNotification: Task.async(function* (target) {
if (!(yield this.canUndo())) {
return;
}
// The tab might have navigated since we requested the undo state:
let canUndoFromThisPage = ["about:home", "about:newtab"].includes(target.currentURI.spec);
if (!canUndoFromThisPage ||
@@ -332,36 +344,37 @@ const AutoMigrate = {
// return false from now on.):
if (!this.shouldStillShowUndoPrompt()) {
this._purgeUndoState(this.UNDO_REMOVED_REASON_OFFER_EXPIRED);
this._removeNotificationBars();
return;
}
let browserName = this.getBrowserUsedForMigration();
- let message;
- if (browserName) {
- message = MigrationUtils.getLocalizedString("automigration.undo.message",
- [browserName]);
- } else {
- message = MigrationUtils.getLocalizedString("automigration.undo.unknownBrowserMessage");
+ if (!browserName) {
+ browserName = MigrationUtils.getLocalizedString("automigration.undo.unknownbrowser");
}
+ const kMessageId = "automigration.undo.message." +
+ Preferences.get(kAutoMigrateImportedItemIds, "all");
+ const kBrandShortName = gBrandBundle.GetStringFromName("brandShortName");
+ let message = MigrationUtils.getLocalizedString(kMessageId,
+ [browserName, kBrandShortName]);
let buttons = [
{
- label: MigrationUtils.getLocalizedString("automigration.undo.keep.label"),
- accessKey: MigrationUtils.getLocalizedString("automigration.undo.keep.accesskey"),
+ label: MigrationUtils.getLocalizedString("automigration.undo.keep2.label"),
+ accessKey: MigrationUtils.getLocalizedString("automigration.undo.keep2.accesskey"),
callback: () => {
this._purgeUndoState(this.UNDO_REMOVED_REASON_OFFER_REJECTED);
this._removeNotificationBars();
},
},
{
- label: MigrationUtils.getLocalizedString("automigration.undo.dontkeep.label"),
- accessKey: MigrationUtils.getLocalizedString("automigration.undo.dontkeep.accesskey"),
+ label: MigrationUtils.getLocalizedString("automigration.undo.dontkeep2.label"),
+ accessKey: MigrationUtils.getLocalizedString("automigration.undo.dontkeep2.accesskey"),
callback: () => {
this._maybeOpenUndoSurveyTab(win);
this.undo();
},
},
];
notificationBox.appendNotification(
message, kNotificationId, null, notificationBox.PRIORITY_INFO_HIGH, buttons
@@ -425,29 +438,65 @@ const AutoMigrate = {
}
return new Map([
["bookmarks", state.bookmarks],
["logins", state.logins],
["visits", state.visits],
]);
},
+ /**
+ * Store the items we've saved into a pref. We use this to be able to show
+ * a detailed message to the user indicating what we've imported.
+ * @param state (Map)
+ * The 'undo' state for the import, which contains info about
+ * how many items of each kind we've (tried to) import.
+ */
+ _setImportedItemPrefFromState(state) {
+ let itemsWithData = [];
+ if (state) {
+ for (let itemType of state.keys()) {
+ if (state.get(itemType).length) {
+ itemsWithData.push(itemType);
+ }
+ }
+ }
+ if (itemsWithData.length == 3) {
+ itemsWithData = "all";
+ } else {
+ itemsWithData = itemsWithData.sort().join(".");
+ }
+ if (itemsWithData) {
+ Preferences.set(kAutoMigrateImportedItemIds, itemsWithData);
+ }
+ },
+
+ /**
+ * Used for the shutdown blocker's information field.
+ */
_saveUndoStateTrackerForShutdown: "not running",
+ /**
+ * Store the information required for using 'undo' of the automatic
+ * migration in the user's profile.
+ */
saveUndoState: Task.async(function* () {
let resolveSavingPromise;
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 = "saving imported item list";
+ this._setImportedItemPrefFromState(state);
+
this._saveUndoStateTrackerForShutdown = "writing undo history";
this._undoSavePromise = OS.File.writeAtomic(
kUndoStateFullPath, this._jsonifyUndoState(state), {
encoding: "utf-8",
compression: "lz4",
tmpPath: kUndoStateFullPath + ".tmp",
});
this._undoSavePromise.then(
--- a/browser/components/migration/tests/browser/browser.ini
+++ b/browser/components/migration/tests/browser/browser.ini
@@ -1,2 +1,3 @@
[browser_undo_notification.js]
+[browser_undo_notification_wording.js]
[browser_undo_notification_multiple_dismissal.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/browser/browser_undo_notification_wording.js
@@ -0,0 +1,67 @@
+"use strict";
+
+let scope = {};
+Cu.import("resource:///modules/AutoMigrate.jsm", scope);
+let oldCanUndo = scope.AutoMigrate.canUndo;
+registerCleanupFunction(function() {
+ scope.AutoMigrate.canUndo = oldCanUndo;
+});
+
+const kExpectedNotificationId = "automigration-undo";
+
+add_task(function* autoMigrationUndoNotificationShows() {
+ let getNotification = browser =>
+ gBrowser.getNotificationBox(browser).getNotificationWithValue(kExpectedNotificationId);
+ let localizedVersionOf = str => {
+ if (str == "logins") {
+ return "passwords";
+ }
+ if (str == "visits") {
+ return "history";
+ }
+ return str;
+ };
+
+ scope.AutoMigrate.canUndo = () => true;
+ let url = "about:newtab";
+ Services.prefs.setCharPref("browser.migrate.automigrate.browser", "someunknownbrowser");
+ const kSubsets = [
+ ["bookmarks", "logins", "visits"],
+ ["bookmarks", "logins"],
+ ["bookmarks", "visits"],
+ ["logins", "visits"],
+ ["bookmarks"],
+ ["logins"],
+ ["visits"],
+ ];
+ const kAllItems = ["bookmarks", "logins", "visits"];
+ for (let subset of kSubsets) {
+ let state = new Map(subset.map(item => [item, [{}]]));
+ scope.AutoMigrate._setImportedItemPrefFromState(state);
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url, false);
+ let browser = tab.linkedBrowser;
+
+ if (!getNotification(browser)) {
+ info(`Notification for ${url} not immediately present, waiting for it.`);
+ yield BrowserTestUtils.waitForNotificationBar(gBrowser, browser, kExpectedNotificationId);
+ }
+
+ ok(true, `Got notification for ${url}`);
+ let notification = getNotification(browser);
+ let notificationText = document.getAnonymousElementByAttribute(notification, "class", "messageText");
+ notificationText = notificationText.textContent;
+ for (let potentiallyImported of kAllItems) {
+ let localizedImportItem = localizedVersionOf(potentiallyImported);
+ if (subset.includes(potentiallyImported)) {
+ ok(notificationText.includes(localizedImportItem),
+ "Expected notification to contain " + localizedImportItem);
+ } else {
+ ok(!notificationText.includes(localizedImportItem),
+ "Expected notification not to contain " + localizedImportItem);
+ }
+ }
+
+ yield BrowserTestUtils.removeTab(tab);
+ }
+});
+
--- a/browser/locales/en-US/chrome/browser/migration/migration.properties
+++ b/browser/locales/en-US/chrome/browser/migration/migration.properties
@@ -67,14 +67,21 @@ 64_edge=Other Data
64_safari=Other Data
64_chrome=Other Data
64_firefox_other=Other Data
64_360se=Other Data
128_firefox=Windows and Tabs
# Automigration undo notification.
-automigration.undo.message = We automatically imported your data from %S. Would you like to keep it?
-automigration.undo.unknownBrowserMessage = We automatically imported your data from another browser. Would you like to keep it?
-automigration.undo.keep.label = Keep
-automigration.undo.keep.accesskey = K
-automigration.undo.dontkeep.label = Don’t Keep
-automigration.undo.dontkeep.accesskey = D
+# %1$S will be replaced with the name of the browser we imported from, %2$S will be replaced with brandShortName
+automigration.undo.message.all = Pick up where you left off. We’ve imported these sites and your bookmarks, history and passwords from %1$S into %2$S.
+automigration.undo.message.bookmarks = Pick up where you left off. We’ve imported these sites and your bookmarks from %1$S into %2$S.
+automigration.undo.message.bookmarks.logins = Pick up where you left off. We’ve imported these sites and your bookmarks and passwords from %1$S into %2$S.
+automigration.undo.message.bookmarks.visits = Pick up where you left off. We’ve imported these sites and your bookmarks and history from %1$S into %2$S.
+automigration.undo.message.logins = Pick up where you left off. We’ve imported your passwords from %1$S into %2$S.
+automigration.undo.message.logins.visits = Pick up where you left off. We’ve imported these sites and your history and passwords from %1$S into %2$S.
+automigration.undo.message.visits = Pick up where you left off. We’ve imported these sites and your history from %1$S into %2$S.
+automigration.undo.keep2.label = OK, Got it
+automigration.undo.keep2.accesskey = O
+automigration.undo.dontkeep2.label = No Thanks
+automigration.undo.dontkeep2.accesskey = N
+automigration.undo.unknownbrowser = Unknown Browser