Bug 1433324 - Part 2. Get auto migration tests running with activity stream enabled. r?Gijs
MozReview-Commit-ID: AOItGs3ca5v
--- a/browser/components/migration/tests/browser/browser.ini
+++ b/browser/components/migration/tests/browser/browser.ini
@@ -1,8 +1,10 @@
[DEFAULT]
prefs =
- browser.newtabpage.activity-stream.enabled=false
browser.newtabpage.preload=false
+support-files =
+ head.js
[browser_undo_notification.js]
[browser_undo_notification_wording.js]
[browser_undo_notification_multiple_dismissal.js]
+skip-if = os == "linux" && debug # Bug 1433324
--- a/browser/components/migration/tests/browser/browser_undo_notification.js
+++ b/browser/components/migration/tests/browser/browser_undo_notification.js
@@ -1,59 +1,35 @@
"use strict";
-let scope = {};
-ChromeUtils.import("resource:///modules/AutoMigrate.jsm", scope);
-let oldCanUndo = scope.AutoMigrate.canUndo;
-let oldUndo = scope.AutoMigrate.undo;
-registerCleanupFunction(function() {
- scope.AutoMigrate.canUndo = oldCanUndo;
- scope.AutoMigrate.undo = oldUndo;
-});
-
-const kExpectedNotificationId = "automigration-undo";
-
add_task(async 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 = await BrowserTestUtils.openNewForegroundTab(gBrowser, url, false);
let browser = tab.linkedBrowser;
- if (!getNotification(browser)) {
- info(`Notification for ${url} not immediately present, waiting for it.`);
- await BrowserTestUtils.waitForNotificationBar(gBrowser, browser, kExpectedNotificationId);
- }
-
+ let notification = await getOrWaitForNotification(browser, url);
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");
await BrowserTestUtils.removeTab(tab);
undoCalled = false;
Services.prefs.setCharPref("browser.migrate.automigrate.browser", "chrome");
tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url, false);
browser = tab.linkedBrowser;
- if (!getNotification(browser)) {
- info(`Notification for ${url} not immediately present, waiting for it.`);
- await BrowserTestUtils.waitForNotificationBar(gBrowser, browser, kExpectedNotificationId);
- }
-
+ notification = await getOrWaitForNotification(browser, url);
ok(true, `Got notification for ${url}`);
- notification = getNotification(browser);
notificationBox = notification.parentNode;
// Set up the survey:
await SpecialPowers.pushPrefEnv({set: [
["browser.migrate.automigrate.undo-survey", "https://example.com/?browser=%IMPORTEDBROWSER%"],
["browser.migrate.automigrate.undo-survey-locales", "en-US"],
]});
let tabOpenedPromise = BrowserTestUtils.waitForNewTab(gBrowser, "https://example.com/?browser=Google%20Chrome");
notification.querySelector("button:not(.notification-button-default)").click();
--- a/browser/components/migration/tests/browser/browser_undo_notification_multiple_dismissal.js
+++ b/browser/components/migration/tests/browser/browser_undo_notification_multiple_dismissal.js
@@ -1,24 +1,19 @@
"use strict";
-
-const kExpectedNotificationId = "automigration-undo";
-
/**
* Pretend we can undo something, trigger a notification, pick the undo option,
* and verify that the notifications are all dismissed immediately.
*/
add_task(async function checkNotificationsDismissed() {
await SpecialPowers.pushPrefEnv({set: [
["browser.migrate.automigrate.enabled", true],
["browser.migrate.automigrate.ui.enabled", true],
]});
- let getNotification = browser =>
- gBrowser.getNotificationBox(browser).getNotificationWithValue(kExpectedNotificationId);
Services.prefs.setCharPref("browser.migrate.automigrate.browser", "someunknownbrowser");
let {guid, lastModified} = await PlacesUtils.bookmarks.insert(
{title: "Some imported bookmark", parentGuid: PlacesUtils.bookmarks.toolbarGuid, url: "http://www.example.com"}
);
let testUndoData = {
@@ -32,25 +27,19 @@ add_task(async function checkNotificatio
});
await OS.File.writeAtomic(path, JSON.stringify(testUndoData), {
encoding: "utf-8",
compression: "lz4",
tmpPath: path + ".tmp",
});
let firstTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home", false);
- if (!getNotification(firstTab.linkedBrowser)) {
- info(`Notification not immediately present on first tab, waiting for it.`);
- await BrowserTestUtils.waitForNotificationBar(gBrowser, firstTab.linkedBrowser, kExpectedNotificationId);
- }
+ let firstNotification = await getOrWaitForNotification(firstTab.linkedBrowser, "first tab");
let secondTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home", false);
- if (!getNotification(secondTab.linkedBrowser)) {
- info(`Notification not immediately present on second tab, waiting for it.`);
- await BrowserTestUtils.waitForNotificationBar(gBrowser, secondTab.linkedBrowser, kExpectedNotificationId);
- }
+ let secondNotification = await getOrWaitForNotification(secondTab.linkedBrowser, "second tab");
// Create a listener for the removal in the first tab, and a listener for bookmarks removal,
// then click 'Don't keep' in the second tab, and verify that the notification is removed
// before we start removing bookmarks.
let haveRemovedBookmark = false;
let bmObserver;
let bookmarkRemovedPromise = new Promise(resolve => {
bmObserver = {
@@ -61,17 +50,17 @@ add_task(async function checkNotificatio
}
},
};
PlacesUtils.bookmarks.addObserver(bmObserver);
registerCleanupFunction(() => PlacesUtils.bookmarks.removeObserver(bmObserver));
});
let firstTabNotificationRemovedPromise = new Promise(resolve => {
- let notification = getNotification(firstTab.linkedBrowser);
+ let notification = firstNotification;
// Save this reference because notification.parentNode will be null once it's removed.
let notificationBox = notification.parentNode;
let mut = new MutationObserver(mutations => {
// Yucky, but we have to detect either the removal via animation (with marginTop)
// or when the element is removed. We can't just detect the element being removed
// because this happens asynchronously (after the animation) and so it'd race
// with the rest of the undo happening.
for (let mutation of mutations) {
@@ -102,17 +91,17 @@ add_task(async function checkNotificatio
ok(!Services.prefs.prefHasUserValue(kObservedPref),
"Pref should have been reset");
resolve();
};
Services.prefs.addObserver(kObservedPref, obs);
});
// Click "Don't keep" button:
- let notificationToActivate = getNotification(secondTab.linkedBrowser);
+ let notificationToActivate = secondNotification;
notificationToActivate.querySelector("button:not(.notification-button-default)").click();
info("Waiting for notification to be removed in first (background) tab");
await firstTabNotificationRemovedPromise;
info("Waiting for bookmark to be removed");
await bookmarkRemovedPromise;
info("Waiting for prefs to be reset");
await prefResetPromise;
--- a/browser/components/migration/tests/browser/browser_undo_notification_wording.js
+++ b/browser/components/migration/tests/browser/browser_undo_notification_wording.js
@@ -1,22 +1,11 @@
"use strict";
-let scope = {};
-ChromeUtils.import("resource:///modules/AutoMigrate.jsm", scope);
-let oldCanUndo = scope.AutoMigrate.canUndo;
-registerCleanupFunction(function() {
- scope.AutoMigrate.canUndo = oldCanUndo;
-});
-
-const kExpectedNotificationId = "automigration-undo";
-
add_task(async 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;
@@ -36,23 +25,18 @@ add_task(async function autoMigrationUnd
];
const kAllItems = ["bookmarks", "logins", "visits"];
for (let subset of kSubsets) {
let state = new Map(subset.map(item => [item, [{}]]));
scope.AutoMigrate._setImportedItemPrefFromState(state);
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url, false);
let browser = tab.linkedBrowser;
- if (!getNotification(browser)) {
- info(`Notification for ${url} not immediately present, waiting for it.`);
- await BrowserTestUtils.waitForNotificationBar(gBrowser, browser, kExpectedNotificationId);
- }
-
+ let notification = await getOrWaitForNotification(browser, url);
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 {
new file mode 100644
--- /dev/null
+++ b/browser/components/migration/tests/browser/head.js
@@ -0,0 +1,42 @@
+"use strict";
+
+/* exported getOrWaitForNotification */
+
+// Import AutoMigrate and save/restore methods to allow stubbing
+const scope = {};
+ChromeUtils.import("resource:///modules/AutoMigrate.jsm", scope);
+const oldCanUndo = scope.AutoMigrate.canUndo;
+const oldUndo = scope.AutoMigrate.undo;
+registerCleanupFunction(function() {
+ scope.AutoMigrate.canUndo = oldCanUndo;
+ scope.AutoMigrate.undo = oldUndo;
+});
+
+const kExpectedNotificationId = "automigration-undo";
+
+/**
+ * Helper to get the undo notification bar.
+ */
+function getNotification(browser) {
+ const box = gBrowser.getNotificationBox(browser).getNotificationWithValue(kExpectedNotificationId);
+ // Before activity stream, the page itself would trigger the notification bar.
+ // Until bug 1438305 to decide on how to handle migration, keep integration
+ // tests running by triggering the notification bar directly via tests.
+ if (!box) {
+ executeSoon(() => scope.AutoMigrate.showUndoNotificationBar(browser));
+ }
+ return box;
+}
+
+/**
+ * Helper to get or wait for the undo notification bar.
+ */
+function getOrWaitForNotification(browser, description) {
+ const notification = getNotification(browser);
+ if (notification) {
+ return notification;
+ }
+
+ info(`Notification for ${description} not immediately present, waiting for it.`);
+ return BrowserTestUtils.waitForNotificationBar(gBrowser, browser, kExpectedNotificationId);
+}