Bug 1322730 - display undo migration message on about:newtab, r=dolske
MozReview-Commit-ID: 8nIGdD9XyFH
--- a/browser/base/content/newtab/page.js
+++ b/browser/base/content/newtab/page.js
@@ -251,16 +251,18 @@ var gPage = {
} else {
addEventListener("load", this);
}
},
onPageVisibleAndLoaded() {
// Send the index of the last visible tile.
this.reportLastVisibleTileIndex();
+ // Maybe tell the user they can undo an initial automigration
+ this.maybeShowAutoMigrationUndoNotification();
},
reportLastVisibleTileIndex() {
let cwu = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
let rect = cwu.getBoundsWithoutFlushing(gGrid.node);
let nodes = cwu.nodesFromRect(rect.left, rect.top, 0, rect.width,
@@ -278,10 +280,14 @@ var gPage = {
// record that suggested tile is shown to use suggested-tiles-histogram
this._suggestedTilePresent = true;
}
}
}
}
DirectoryLinksProvider.reportSitesAction(sites, "view", lastIndex);
- }
+ },
+
+ maybeShowAutoMigrationUndoNotification() {
+ sendAsyncMessage("NewTab:MaybeShowAutoMigrationUndoNotification");
+ },
};
--- a/browser/components/migration/AutoMigrate.jsm
+++ b/browser/components/migration/AutoMigrate.jsm
@@ -11,17 +11,17 @@ const { classes: Cc, interfaces: Ci, res
const kAutoMigrateEnabledPref = "browser.migrate.automigrate.enabled";
const kUndoUIEnabledPref = "browser.migrate.automigrate.ui.enabled";
const kAutoMigrateBrowserPref = "browser.migrate.automigrate.browser";
const kAutoMigrateLastUndoPromptDateMsPref = "browser.migrate.automigrate.lastUndoPromptDateMs";
const kAutoMigrateDaysToOfferUndoPref = "browser.migrate.automigrate.daysToOfferUndo";
-const kNotificationId = "abouthome-automigration-undo";
+const kNotificationId = "automigration-undo";
Cu.import("resource:///modules/MigrationUtils.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AsyncShutdown",
"resource://gre/modules/AsyncShutdown.jsm");
@@ -250,24 +250,25 @@ const AutoMigrate = {
},
maybeShowUndoNotification: Task.async(function* (target) {
if (!(yield this.canUndo())) {
return;
}
// The tab might have navigated since we requested the undo state:
- if (target.currentURI.spec != "about:home" ||
+ let canUndoFromThisPage = ["about:home", "about:newtab"].includes(target.currentURI.spec);
+ if (!canUndoFromThisPage ||
!Preferences.get(kUndoUIEnabledPref, false)) {
return;
}
let win = target.ownerGlobal;
let notificationBox = win.gBrowser.getNotificationBox(target);
- if (!notificationBox || notificationBox.getNotificationWithValue("abouthome-automigration-undo")) {
+ if (!notificationBox || notificationBox.getNotificationWithValue(kNotificationId)) {
return;
}
// At this stage we're committed to show the prompt - unless we shouldn't,
// in which case we remove the undo prefs (which will cause canUndo() to
// return false from now on.):
if (!this.shouldStillShowUndoPrompt()) {
this.removeUndoOption(this.UNDO_REMOVED_REASON_OFFER_EXPIRED);
--- a/browser/components/migration/moz.build
+++ b/browser/components/migration/moz.build
@@ -3,16 +3,18 @@
# 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/.
XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
MARIONETTE_UNIT_MANIFESTS += ['tests/marionette/manifest.ini']
+BROWSER_CHROME_MANIFESTS += [ 'tests/browser/browser.ini']
+
JAR_MANIFESTS += ['jar.mn']
XPIDL_SOURCES += [
'nsIBrowserProfileMigrator.idl',
]
XPIDL_MODULE = 'migration'
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/browser/.eslintrc.js
@@ -0,0 +1,9 @@
+"use strict";
+
+module.exports = {
+ "extends": [
+ "../../../../../testing/mochitest/browser.eslintrc.js",
+ "../../../../../testing/mochitest/mochitest.eslintrc.js",
+ ]
+};
+
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/browser/browser.ini
@@ -0,0 +1,1 @@
+[browser_undo_notification.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/browser/browser_undo_notification.js
@@ -0,0 +1,60 @@
+"use strict";
+
+let scope = {};
+Cu.import("resource:///modules/AutoMigrate.jsm", scope);
+let oldCanUndo = scope.AutoMigrate.canUndo;
+let oldUndo = scope.AutoMigrate.undo;
+registerCleanupFunction(function() {
+ Cu.reportError("Cleaning up");
+ scope.AutoMigrate.canUndo = oldCanUndo;
+ scope.AutoMigrate.undo = oldUndo;
+ Cu.reportError("Cleaned up");
+});
+
+const kExpectedNotificationId = "automigration-undo";
+
+add_task(function* autoMigrationUndoNotificationShows() {
+ let getNotification = browser =>
+ gBrowser.getNotificationBox(browser).getNotificationWithValue(kExpectedNotificationId);
+
+ scope.AutoMigrate.canUndo = () => true;
+ let undoCalled;
+ scope.AutoMigrate.undo = () => { undoCalled = true };
+ for (let url of ["about:newtab", "about:home"]) {
+ undoCalled = false;
+ // Can't use pushPrefEnv because of bug 1323779
+ Services.prefs.setCharPref("browser.migrate.automigrate.browser", "someunknownbrowser");
+ 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 notificationBox = notification.parentNode;
+ notification.querySelector("button.notification-button-default").click();
+ ok(!undoCalled, "Undo should not be called when clicking the default button");
+ is(notification, notificationBox._closedNotification, "Notification should be closing");
+ yield BrowserTestUtils.removeTab(tab);
+
+ undoCalled = false;
+ Services.prefs.setCharPref("browser.migrate.automigrate.browser", "someunknownbrowser");
+ tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url, false);
+ 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}`);
+ notification = getNotification(browser);
+ notificationBox = notification.parentNode;
+ notification.querySelector("button:not(.notification-button-default)").click();
+ ok(undoCalled, "Undo should be called when clicking the non-default (Don't Keep) button");
+ is(notification, notificationBox._closedNotification, "Notification should be closing");
+ yield BrowserTestUtils.removeTab(tab);
+ }
+});
+
--- a/browser/modules/AboutNewTab.jsm
+++ b/browser/modules/AboutNewTab.jsm
@@ -8,28 +8,32 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
this.EXPORTED_SYMBOLS = [ "AboutNewTab" ];
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AutoMigrate",
+ "resource:///modules/AutoMigrate.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
+ "resource://gre/modules/NewTabUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "RemotePages",
"resource://gre/modules/RemotePageManager.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
- "resource://gre/modules/NewTabUtils.jsm");
var AboutNewTab = {
pageListener: null,
init() {
this.pageListener = new RemotePages("about:newtab");
this.pageListener.addMessageListener("NewTab:Customize", this.customize.bind(this));
+ this.pageListener.addMessageListener("NewTab:MaybeShowAutoMigrationUndoNotification",
+ (msg) => AutoMigrate.maybeShowUndoNotification(msg.target.browser));
},
customize(message) {
NewTabUtils.allPages.enabled = message.data.enabled;
NewTabUtils.allPages.enhanced = message.data.enhanced;
},
uninit() {