Bug 1444392 - Part 2 - Use test-only helpers for the main menu across the tree. r=Gijs
MozReview-Commit-ID: IpdYFaYxx4M
--- a/browser/base/content/test/performance/browser_appmenu.js
+++ b/browser/base/content/test/performance/browser_appmenu.js
@@ -1,11 +1,14 @@
"use strict";
/* global PanelUI */
+ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
+let gCUITestUtils = new CustomizableUITestUtils(window);
+
/**
* WHOA THERE: We should never be adding new things to
* EXPECTED_APPMENU_OPEN_REFLOWS. This is a whitelist that should slowly go
* away as we improve the performance of the front-end. Instead of adding more
* reflows to the whitelist, you should be modifying your code to avoid the reflow.
*
* See https://developer.mozilla.org/en-US/Firefox/Performance_best_practices_for_Firefox_fe_engineers
* for tips on how to do that.
@@ -66,23 +69,20 @@ add_task(async function() {
condition: r =>
r.x1 >= textBoxRect.left && r.x2 <= textBoxRect.right &&
r.y1 >= textBoxRect.top && r.y2 <= textBoxRect.bottom
}
]
};
// First, open the appmenu.
- await withPerfObserver(async function() {
- let popupShown =
- BrowserTestUtils.waitForEvent(PanelUI.panel, "popupshown");
- await PanelUI.show();
- await popupShown;
- }, {expectedReflows: EXPECTED_APPMENU_OPEN_REFLOWS,
- frames: frameExpectations});
+ await withPerfObserver(() => gCUITestUtils.openMainMenu(), {
+ expectedReflows: EXPECTED_APPMENU_OPEN_REFLOWS,
+ frames: frameExpectations,
+ });
// Now open a series of subviews, and then close the appmenu. We
// should not reflow during any of this.
await withPerfObserver(async function() {
// This recursive function will take the current main or subview,
// find all of the buttons that navigate to subviews inside it,
// and click each one individually. Upon entering the new view,
// we recurse. When the subviews within a view have been
@@ -117,13 +117,11 @@ add_task(async function() {
await BrowserTestUtils.waitForCondition(() => {
return !container.hasAttribute("width");
});
}
}
await openSubViewsRecursively(PanelUI.mainView);
- let hidden = BrowserTestUtils.waitForEvent(PanelUI.panel, "popuphidden");
- PanelUI.hide();
- await hidden;
+ await gCUITestUtils.hideMainMenu();
}, {expectedReflows: [], frames: frameExpectations});
});
--- a/browser/base/content/test/webextensions/browser_extension_sideloading.js
+++ b/browser/base/content/test/webextensions/browser_extension_sideloading.js
@@ -114,17 +114,17 @@ add_task(async function() {
ExtensionsUI._checkForSideloaded();
await changePromise;
// Check for the addons badge on the hamburger menu
let menuButton = document.getElementById("PanelUI-menu-button");
is(menuButton.getAttribute("badge-status"), "addon-alert", "Should have addon alert badge");
// Find the menu entries for sideloaded extensions
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
let addons = PanelUI.addonNotificationContainer;
is(addons.children.length, 4, "Have 4 menu entries for sideloaded extensions");
// Click the first sideloaded extension
let popupPromise = promisePopupNotificationShown("addon-webext-permissions");
addons.children[0].click();
@@ -154,17 +154,17 @@ add_task(async function() {
is(addon1.userDisabled, true, "Addon 1 should still be disabled");
is(addon2.userDisabled, true, "Addon 2 should still be disabled");
is(addon3.userDisabled, true, "Addon 3 should still be disabled");
is(addon4.userDisabled, true, "Addon 4 should still be disabled");
BrowserTestUtils.removeTab(gBrowser.selectedTab);
// Should still have 3 entries in the hamburger menu
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
addons = PanelUI.addonNotificationContainer;
is(addons.children.length, 3, "Have 3 menu entries for sideloaded extensions");
// Click the second sideloaded extension and wait for the notification
popupPromise = promisePopupNotificationShown("addon-webext-permissions");
addons.children[0].click();
panel = await popupPromise;
@@ -184,23 +184,23 @@ add_task(async function() {
[addon1, addon2, addon3, addon4] = await AddonManager.getAddonsByIDs([ID1, ID2, ID3, ID4]);
is(addon1.userDisabled, true, "Addon 1 should still be disabled");
is(addon2.userDisabled, false, "Addon 2 should now be enabled");
is(addon3.userDisabled, true, "Addon 3 should still be disabled");
is(addon4.userDisabled, true, "Addon 4 should still be disabled");
// Should still have 2 entries in the hamburger menu
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
addons = PanelUI.addonNotificationContainer;
is(addons.children.length, 2, "Have 2 menu entries for sideloaded extensions");
// Close the hamburger menu and go directly to the addons manager
- await PanelUI.hide();
+ await gCUITestUtils.hideMainMenu();
win = await BrowserOpenAddonsMgr(VIEW);
let list = win.document.getElementById("addon-list");
// Make sure XBL bindings are applied
list.clientHeight;
@@ -220,23 +220,23 @@ add_task(async function() {
// Accept the permissions
panel.button.click();
addon3 = await AddonManager.getAddonByID(ID3);
is(addon3.userDisabled, false, "Addon 3 should be enabled");
// Should still have 1 entry in the hamburger menu
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
addons = PanelUI.addonNotificationContainer;
is(addons.children.length, 1, "Have 1 menu entry for sideloaded extensions");
// Close the hamburger menu and go to the detail page for this addon
- await PanelUI.hide();
+ await gCUITestUtils.hideMainMenu();
win = await BrowserOpenAddonsMgr(`addons://detail/${encodeURIComponent(ID4)}`);
let button = win.document.getElementById("detail-enable-btn");
// When clicking enable we should see the permissions notification
popupPromise = promisePopupNotificationShown("addon-webext-permissions");
BrowserTestUtils.synthesizeMouseAtCenter(button, {},
gBrowser.selectedBrowser);
--- a/browser/base/content/test/webextensions/browser_extension_update_background.js
+++ b/browser/base/content/test/webextensions/browser_extension_update_background.js
@@ -74,17 +74,17 @@ async function backgroundUpdateTest(url,
let updatePromise = promiseInstallEvent(addon, "onDownloadEnded");
AddonManagerPrivate.backgroundUpdateCheck();
await updatePromise;
is(getBadgeStatus(), "addon-alert", "Should have addon alert badge");
// Find the menu entry for the update
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
let addons = PanelUI.addonNotificationContainer;
is(addons.children.length, 1, "Have a menu entry for the update");
// Click the menu item
let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:addons");
let popupPromise = promisePopupNotificationShown("addon-webext-permissions");
addons.children[0].click();
@@ -118,30 +118,30 @@ async function backgroundUpdateTest(url,
addon = await AddonManager.getAddonByID(id);
is(addon.version, "1.0", "Should still be running the old version");
BrowserTestUtils.removeTab(tab);
// Alert badge and hamburger menu items should be gone
is(getBadgeStatus(), "", "Addon alert badge should be gone");
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
addons = PanelUI.addonNotificationContainer;
is(addons.children.length, 0, "Update menu entries should be gone");
- await PanelUI.hide();
+ await gCUITestUtils.hideMainMenu();
// Re-check for an update
updatePromise = promiseInstallEvent(addon, "onDownloadEnded");
await AddonManagerPrivate.backgroundUpdateCheck();
await updatePromise;
is(getBadgeStatus(), "addon-alert", "Should have addon alert badge");
// Find the menu entry for the update
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
addons = PanelUI.addonNotificationContainer;
is(addons.children.length, 1, "Have a menu entry for the update");
// Click the menu item
tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:addons");
popupPromise = promisePopupNotificationShown("addon-webext-permissions");
addons.children[0].click();
--- a/browser/base/content/test/webextensions/browser_extension_update_background_noprompt.js
+++ b/browser/base/content/test/webextensions/browser_extension_update_background_noprompt.js
@@ -56,20 +56,20 @@ async function testNoPrompt(origUrl, id)
// Trigger an update check and wait for the update to be applied.
let updatePromise = waitForUpdate(addon);
AddonManagerPrivate.backgroundUpdateCheck();
await updatePromise;
// There should be no notifications about the update
is(getBadgeStatus(), "", "Should not have addon alert badge");
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
let addons = PanelUI.addonNotificationContainer;
is(addons.children.length, 0, "Have 0 updates in the PanelUI menu");
- await PanelUI.hide();
+ await gCUITestUtils.hideMainMenu();
ok(!sawPopup, "Should not have seen permissions notification");
addon = await AddonManager.getAddonByID(id);
is(addon.version, "2.0", "Update should have applied");
addon.uninstall();
await SpecialPowers.popPrefEnv();
--- a/browser/base/content/test/webextensions/head.js
+++ b/browser/base/content/test/webextensions/head.js
@@ -3,16 +3,18 @@ const BASE = getRootDirectory(gTestPath)
.replace("chrome://mochitests/content/", "https://example.com/");
ChromeUtils.import("resource:///modules/ExtensionsUI.jsm");
XPCOMUtils.defineLazyGetter(this, "Management", () => {
const {Management} = ChromeUtils.import("resource://gre/modules/Extension.jsm", {});
return Management;
});
+ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
+let gCUITestUtils = new CustomizableUITestUtils(window);
/**
* Wait for the given PopupNotification to display
*
* @param {string} name
* The name of the notification to wait for.
*
* @returns {Promise}
--- a/browser/components/places/tests/browser/browser_panelview_bookmarks_delete.js
+++ b/browser/components/places/tests/browser/browser_panelview_bookmarks_delete.js
@@ -1,32 +1,32 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
+ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
+let gCUITestUtils = new CustomizableUITestUtils(window);
+
const TEST_URL = "https://www.example.com/";
/**
* Checks that the Bookmarks subview is updated after deleting an item.
*/
add_task(async function test_panelview_bookmarks_delete() {
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: TEST_URL,
title: TEST_URL,
});
- let mainView = document.getElementById("appMenu-mainView");
- let promise = BrowserTestUtils.waitForEvent(mainView, "ViewShown");
- PanelUI.show();
- await promise;
+ await gCUITestUtils.openMainMenu();
let libraryView = document.getElementById("appMenu-libraryView");
- promise = BrowserTestUtils.waitForEvent(libraryView, "ViewShown");
+ let promise = BrowserTestUtils.waitForEvent(libraryView, "ViewShown");
document.getElementById("appMenu-library-button").click();
await promise;
let bookmarksView = document.getElementById("PanelUI-bookmarks");
promise = BrowserTestUtils.waitForEvent(bookmarksView, "ViewShown");
document.getElementById("appMenu-library-bookmarks-button").click();
await promise;
@@ -50,12 +50,10 @@ add_task(async function test_panelview_b
}
});
observer.observe(list, { childList: true });
});
let placesContextDelete = document.getElementById("placesContext_delete");
EventUtils.synthesizeMouseAtCenter(placesContextDelete, {});
await promise;
- promise = BrowserTestUtils.waitForEvent(PanelUI.panel, "popuphidden");
- PanelUI.hide();
- await promise;
+ await gCUITestUtils.hideMainMenu();
});
--- a/browser/components/search/test/browser_searchbar_openpopup.js
+++ b/browser/components/search/test/browser_searchbar_openpopup.js
@@ -1,11 +1,14 @@
// Tests that the suggestion popup appears at the right times in response to
// focus and user events (mouse, keyboard, drop).
+ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
+let gCUITestUtils = new CustomizableUITestUtils(window);
+
// Instead of loading EventUtils.js into the test scope in browser-test.js for all tests,
// we only need EventUtils.js for a few files which is why we are using loadSubScript.
var EventUtils = {};
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
const searchPopup = document.getElementById("PopupSearchAutoComplete");
const kValues = ["long text", "long text 2", "long text 3"];
@@ -565,17 +568,17 @@ add_task(async function dont_open_in_cus
isnot(searchPopup.getAttribute("showonlysettings"), "true", "Should show the full popup");
info("Entering customization mode");
let sawPopup = false;
function listener() {
sawPopup = true;
}
searchPopup.addEventListener("popupshowing", listener);
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
promise = promiseEvent(searchPopup, "popuphidden");
await startCustomizing();
await promise;
searchPopup.removeEventListener("popupshowing", listener);
ok(!sawPopup, "Shouldn't have seen the suggestions popup");
await endCustomizing();
--- a/browser/components/uitour/test/browser_UITour3.js
+++ b/browser/components/uitour/test/browser_UITour3.js
@@ -1,10 +1,13 @@
"use strict";
+ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
+let gCUITestUtils = new CustomizableUITestUtils(window);
+
var gTestTab;
var gContentAPI;
var gContentWindow;
requestLongerTimeout(2);
add_task(setup_UITourTest);
@@ -130,17 +133,17 @@ add_UITour_task(async function test_info
is(returnValue.result, "closeButton", "Close button callback called");
}),
add_UITour_task(async function test_info_target_callback() {
let popup = document.getElementById("UITourTooltip");
await showInfoPromise("appMenu", "I want to know when the target is clicked", "*click*", null, null, "makeInfoOptions");
- await PanelUI.show();
+ await gCUITestUtils.openMainMenu();
let returnValue = await waitForCallbackResultPromise();
is(returnValue.result, "target", "target callback called");
is(returnValue.data.target, "appMenu", "target callback was from the appMenu");
is(returnValue.data.type, "popupshown", "target callback was from the mousedown");
// Cleanup.