Bug 1382579 - Part 3: Tests, r=Gijs

This commit
- adds 2 utility functions to the uitour's head.js

- adds the browser_UITour4.js

- moves the tests in the browser_showMenu_controlCenter.js into the newly added the browser_showMenu.js

- deletes the browser_showMenu_urlbar.js because it's test has been modified and moved into the browser_showMenu.js

- adds one test case for the page action panel in the browser_showMenu.js

- updates the browser_UITour_availableTargets.js test because we have more targets right now.

MozReview-Commit-ID: CydEAkqAl3V

--HG--
rename : browser/components/uitour/test/browser_showMenu_controlCenter.js => browser/components/uitour/test/browser_showMenu.js
extra : rebase_source : 3b4d124ccfc12e577ce509241d19795d87fa3206
This commit is contained in:
Fischer Liu 2017-08-02 13:53:05 +08:00
Родитель 39b51b3ffc
Коммит 3a0f05a4ca
6 изменённых файлов: 346 добавлений и 66 удалений

Просмотреть файл

@ -21,13 +21,13 @@ support-files =
!/browser/base/content/test/general/trackingPage.html
[browser_trackingProtection_tour.js]
tag = trackingprotection
[browser_showMenu_controlCenter.js]
[browser_showMenu_urlbar.js]
[browser_showMenu.js]
tag = trackingprotection
[browser_UITour.js]
skip-if = os == "linux" # Intermittent failures, bug 951965
[browser_UITour2.js]
[browser_UITour3.js]
[browser_UITour4.js]
skip-if = os == "linux" # Linux: Bug 986760, Bug 989101.
[browser_UITour_availableTargets.js]
[browser_UITour_annotation_size_attributes.js]

Просмотреть файл

@ -0,0 +1,285 @@
"use strict";
var gTestTab;
var gContentAPI;
var gContentWindow;
add_task(setup_UITourTest);
add_UITour_task(async function test_highligh_between_pageActionButtonOnUrlbar_and_buttonOnPageActionPanel() {
let highlight = document.getElementById("UITourHighlight");
is_element_hidden(highlight, "Highlight should initially be hidden");
// Test highlighting the page action button on the urlbar
let pageActionPanel = BrowserPageActions.panelNode;
let highlightVisiblePromise = elementVisiblePromise(highlight, "Should show highlight");
gContentAPI.showHighlight("pageActionButton");
await highlightVisiblePromise;
is(pageActionPanel.state, "closed", "Shouldn't open the page action panel while highlighting the pageActionButton");
is(getShowHighlightTargetName(), "pageActionButton", "Should highlight the pageActionButton");
// Test switching the highlight to the bookmark button on the page action panel
let panelShownPromise = promisePanelElementShown(window, pageActionPanel);
highlightVisiblePromise = elementVisiblePromise(highlight, "Should show highlight");
gContentAPI.showHighlight("pageAction-panel-bookmark");
await highlightVisiblePromise;
await panelShownPromise;
is(pageActionPanel.state, "open", "Should open the page action panel for highlighting the pageAction-panel-bookmark");
is(getShowHighlightTargetName(), "pageAction-panel-bookmark", "Should highlight the pageAction-panel-bookmark");
// Test hiding highlight
let panelHiddenPromise = promisePanelElementHidden(window, pageActionPanel);
let highlightHiddenPromise = elementHiddenPromise(highlight, "Should hide highlight");
gContentAPI.hideHighlight();
await highlightHiddenPromise;
await panelHiddenPromise;
is(pageActionPanel.state, "closed", "Should close the page action panel after hiding highlight");
});
add_UITour_task(async function test_highligh_between_buttonOnAppMenu_and_buttonOnPageActionPanel() {
let highlight = document.getElementById("UITourHighlight");
is_element_hidden(highlight, "Highlight should initially be hidden");
let appMenu = window.PanelUI.panel;
let pageActionPanel = BrowserPageActions.panelNode;
// Test highlighting the addons button on the app menu
let appMenuShownPromise = promisePanelElementShown(window, appMenu);
let highlightVisiblePromise = elementVisiblePromise(highlight, "Should show highlight");
gContentAPI.showHighlight("addons");
await appMenuShownPromise;
await highlightVisiblePromise;
is(appMenu.state, "open", "Should open the app menu to highlight the addons button");
is(pageActionPanel.state, "closed", "Shouldn't open the page action panel");
is(getShowHighlightTargetName(), "addons", "Should highlight the addons button on the app menu");
// Test switching the highlight to the copyURL button on the page action panel
let appMenuHiddenPromise = promisePanelElementHidden(window, appMenu);
let pageActionPanelShownPromise = promisePanelElementShown(window, pageActionPanel);
highlightVisiblePromise = elementVisiblePromise(highlight, "Should show highlight");
gContentAPI.showHighlight("pageAction-panel-copyURL");
await appMenuHiddenPromise;
await pageActionPanelShownPromise;
await highlightVisiblePromise;
is(appMenu.state, "closed", "Should close the app menu after no more highlight for the addons button");
is(pageActionPanel.state, "open", "Should open the page action panel to highlight the copyURL button");
is(getShowHighlightTargetName(), "pageAction-panel-copyURL", "Should highlight the copyURL button on the page action panel");
// Test hiding highlight
let pageActionPanelHiddenPromise = promisePanelElementHidden(window, pageActionPanel);
let highlightHiddenPromise = elementHiddenPromise(highlight, "Should hide highlight");
gContentAPI.hideHighlight();
await pageActionPanelHiddenPromise
await highlightHiddenPromise;
is(appMenu.state, "closed", "Shouldn't open the app menu after hiding highlight");
is(pageActionPanel.state, "closed", "Should close the page action panel after hiding highlight");
});
add_UITour_task(async function test_showInfo_between_buttonOnPageActionPanel_and_buttonOnAppMenu() {
let tooltip = document.getElementById("UITourTooltip");
is_element_hidden(tooltip, "Tooltip should initially be hidden");
let appMenu = window.PanelUI.panel;
let pageActionPanel = BrowserPageActions.panelNode;
// Test showing info tooltip on the emailLink button on the page action panel
let pageActionPanelShownPromise = promisePanelElementShown(window, pageActionPanel);
let tooltipVisiblePromise = elementVisiblePromise(tooltip, "Should show info tooltip");
await showInfoPromise("pageAction-panel-emailLink", "title", "text");
await pageActionPanelShownPromise;
await tooltipVisiblePromise;
is(appMenu.state, "closed", "Shouldn't open the app menu");
is(pageActionPanel.state, "open", "Should open the page action panel to show info on the copyURL button");
is(getShowInfoTargetName(), "pageAction-panel-emailLink", "Should show info tooltip on the emailLink button on the page action panel");
// Test switching info tooltip to the customize button on the app menu
let appMenuShownPromise = promisePanelElementShown(window, appMenu);
let pageActionPanelHiddenPromise = promisePanelElementHidden(window, pageActionPanel);
tooltipVisiblePromise = elementVisiblePromise(tooltip, "Should show info tooltip");
await showInfoPromise("customize", "title", "text");
await appMenuShownPromise;
await pageActionPanelHiddenPromise;
await tooltipVisiblePromise;
is(appMenu.state, "open", "Should open the app menu to show info on the customize button");
is(pageActionPanel.state, "closed", "Should close the page action panel after no more show info for the copyURL button");
is(getShowInfoTargetName(), "customize", "Should show info tooltip on the customize button on the app menu");
// Test hiding info tooltip
let appMenuHiddenPromise = promisePanelElementHidden(window, appMenu);
let tooltipHiddenPromise = elementHiddenPromise(tooltip, "Should hide info");
gContentAPI.hideInfo();
await appMenuHiddenPromise;
await tooltipHiddenPromise;
is(appMenu.state, "closed", "Should close the app menu after hiding info");
is(pageActionPanel.state, "closed", "Shouldn't open the page action panel after hiding info");
});
add_UITour_task(async function test_highlight_buttonOnPageActionPanel_and_showInfo_buttonOnAppMenu() {
let highlight = document.getElementById("UITourHighlight");
is_element_hidden(highlight, "Highlight should initially be hidden");
let tooltip = document.getElementById("UITourTooltip");
is_element_hidden(tooltip, "Tooltip should initially be hidden");
let appMenu = window.PanelUI.panel;
let pageActionPanel = BrowserPageActions.panelNode;
// Test highlighting the sendToDevice button on the page action panel
let pageActionPanelShownPromise = promisePanelElementShown(window, pageActionPanel);
let highlightVisiblePromise = elementVisiblePromise(highlight, "Should show highlight");
gContentAPI.showHighlight("pageAction-panel-sendToDevice");
await pageActionPanelShownPromise;
await highlightVisiblePromise;
is(appMenu.state, "closed", "Shouldn't open the app menu");
is(pageActionPanel.state, "open", "Should open the page action panel to highlight the sendToDevice button");
is(getShowHighlightTargetName(), "pageAction-panel-sendToDevice", "Should highlight the sendToDevice button on the page action panel");
// Test showing info tooltip on the privateWindow button on the app menu
let appMenuShownPromise = promisePanelElementShown(window, appMenu);
let tooltipVisiblePromise = elementVisiblePromise(tooltip, "Should show info tooltip");
let pageActionPanelHiddenPromise = promisePanelElementHidden(window, pageActionPanel);
let highlightHiddenPromise = elementHiddenPromise(highlight, "Should hide highlight");
await showInfoPromise("privateWindow", "title", "text");
await appMenuShownPromise;
await tooltipVisiblePromise;
await pageActionPanelHiddenPromise;
await highlightHiddenPromise;
is(appMenu.state, "open", "Should open the app menu to show info on the privateWindow button");
is(pageActionPanel.state, "closed", "Should close the page action panel");
is(getShowInfoTargetName(), "privateWindow", "Should show info tooltip on the privateWindow button on the app menu");
// Test hiding info tooltip
let appMenuHiddenPromise = promisePanelElementHidden(window, appMenu);
let tooltipHiddenPromise = elementHiddenPromise(tooltip, "Should hide info");
gContentAPI.hideInfo();
await appMenuHiddenPromise;
await tooltipHiddenPromise;
is(appMenu.state, "closed", "Should close the app menu after hiding info tooltip");
});
add_UITour_task(async function test_showInfo_buttonOnAppMenu_and_highlight_buttonOnPageActionPanel() {
let highlight = document.getElementById("UITourHighlight");
is_element_hidden(highlight, "Highlight should initially be hidden");
let tooltip = document.getElementById("UITourTooltip");
is_element_hidden(tooltip, "Tooltip should initially be hidden");
let appMenu = window.PanelUI.panel;
let pageActionPanel = BrowserPageActions.panelNode;
// Test showing info tooltip on the privateWindow button on the app menu
let appMenuShownPromise = promisePanelElementShown(window, appMenu);
let tooltipVisiblePromise = elementVisiblePromise(tooltip, "Should show info tooltip");
await showInfoPromise("privateWindow", "title", "text");
await appMenuShownPromise;
await tooltipVisiblePromise;
is(appMenu.state, "open", "Should open the app menu to show info on the privateWindow button");
is(pageActionPanel.state, "closed", "Shouldn't open the page action panel");
is(getShowInfoTargetName(), "privateWindow", "Should show info tooltip on the privateWindow button on the app menu");
// Test highlighting the sendToDevice button on the page action panel
let pageActionPanelShownPromise = promisePanelElementShown(window, pageActionPanel);
let highlightVisiblePromise = elementVisiblePromise(highlight, "Should show highlight");
let appMenuHiddenPromise = promisePanelElementHidden(window, appMenu);
let tooltipHiddenPromise = elementHiddenPromise(tooltip, "Should hide info");
gContentAPI.showHighlight("pageAction-panel-sendToDevice");
await pageActionPanelShownPromise;
await highlightVisiblePromise;
await appMenuHiddenPromise;
await tooltipHiddenPromise;
is(appMenu.state, "closed", "Should close the app menu");
is(pageActionPanel.state, "open", "Should open the page action panel to highlight the sendToDevice button");
is(getShowHighlightTargetName(), "pageAction-panel-sendToDevice", "Should highlight the sendToDevice button on the page action panel");
// Test hiding highlight
let pageActionPanelHiddenPromise = promisePanelElementHidden(window, pageActionPanel);
let highlightHiddenPromise = elementHiddenPromise(highlight, "Should hide highlight");
gContentAPI.hideHighlight();
await pageActionPanelHiddenPromise;
await highlightHiddenPromise;
is(pageActionPanel.state, "closed", "Should close the page action panel after hiding highlight");
});
add_UITour_task(async function test_show_appMenu_and_highligh_buttonOnPageActionPanel() {
let highlight = document.getElementById("UITourHighlight");
is_element_hidden(highlight, "Highlight should initially be hidden");
let appMenu = window.PanelUI.panel;
let pageActionPanel = BrowserPageActions.panelNode;
// Test explicity asking for opening the app menu
let appMenuShownPromise = promisePanelElementShown(window, appMenu);
gContentAPI.showMenu("appMenu");
await appMenuShownPromise;
is(appMenu.state, "open", "Should open the app menu");
is(pageActionPanel.state, "closed", "Shouldn't open the page action panel");
// Test highlighting the sendToDevice button on the page action panel
let pageActionPanelShownPromise = promisePanelElementShown(window, pageActionPanel);
let highlightVisiblePromise = elementVisiblePromise(highlight, "Should show highlight");
gContentAPI.showHighlight("pageAction-panel-sendToDevice");
await pageActionPanelShownPromise;
await highlightVisiblePromise;
is(appMenu.state, "open", "Shouldn't close the app menu because it is opened explictly by api user.");
is(pageActionPanel.state, "open", "Should open the page action panel to highlight the sendToDevice button");
is(getShowHighlightTargetName(), "pageAction-panel-sendToDevice", "Should highlight the sendToDevice button on the page action panel");
// Test hiding the app menu wouldn't affect the highlight on the page action panel
let appMenuHiddenPromise = promisePanelElementHidden(window, appMenu);
gContentAPI.hideMenu("appMenu");
await appMenuHiddenPromise;
is_element_visible(highlight, "Highlight should still be visible");
is(appMenu.state, "closed", "Should close the app menu");
is(pageActionPanel.state, "open", "Shouldn't close the page action panel");
is(getShowHighlightTargetName(), "pageAction-panel-sendToDevice", "Should still highlight the sendToDevice button on the page action panel");
// Test hiding highlight
let pageActionPanelHiddenPromise = promisePanelElementHidden(window, pageActionPanel);
let highlightHiddenPromise = elementHiddenPromise(highlight, "Should hide highlight");
gContentAPI.hideHighlight();
await pageActionPanelHiddenPromise;
await highlightHiddenPromise;
is(appMenu.state, "closed", "Shouldn't open the app menu");
is(pageActionPanel.state, "closed", "Should close the page action panel after hiding highlight");
});
add_UITour_task(async function test_show_pageActionPanel_and_showInfo_buttonOnAppMenu() {
let tooltip = document.getElementById("UITourTooltip");
is_element_hidden(tooltip, "Tooltip should initially be hidden");
let appMenu = window.PanelUI.panel;
let pageActionPanel = BrowserPageActions.panelNode;
// Test explicity asking for opening the page action panel
let pageActionPanelShownPromise = promisePanelElementShown(window, pageActionPanel);
gContentAPI.showMenu("pageActionPanel");
await pageActionPanelShownPromise;
is(appMenu.state, "closed", "Shouldn't open the app menu");
is(pageActionPanel.state, "open", "Should open the page action panel");
// Test showing info tooltip on the privateWindow button on the app menu
let appMenuShownPromise = promisePanelElementShown(window, appMenu);
let tooltipVisiblePromise = elementVisiblePromise(tooltip, "Should show info tooltip");
await showInfoPromise("privateWindow", "title", "text");
await appMenuShownPromise;
await tooltipVisiblePromise;
is(appMenu.state, "open", "Should open the app menu to show info on the privateWindow button");
is(pageActionPanel.state, "open", "Shouldn't close the page action panel because it is opened explictly by api user.");
is(getShowInfoTargetName(), "privateWindow", "Should show info tooltip on the privateWindow button on the app menu");
// Test hiding the page action panel wouldn't affect the info tooltip on the app menu
let pageActionPanelHiddenPromise = promisePanelElementHidden(window, pageActionPanel);
gContentAPI.hideMenu("pageActionPanel");
await pageActionPanelHiddenPromise;
is_element_visible(tooltip, "Tooltip should still be visible");
is(appMenu.state, "open", "Shouldn't close the app menu");
is(pageActionPanel.state, "closed", "Should close the page action panel after hideMenu");
is(getShowInfoTargetName(), "privateWindow", "Should still show info tooltip on the privateWindow button on the app menu");
// Test hiding info tooltip
let appMenuHiddenPromise = promisePanelElementHidden(window, appMenu);
let tooltipHiddenPromise = elementHiddenPromise(tooltip, "Should hide info");
gContentAPI.hideInfo();
await appMenuHiddenPromise;
await tooltipHiddenPromise;
is(appMenu.state, "closed", "Should close the app menu after hideInfo");
is(pageActionPanel.state, "closed", "Shouldn't open the page action panel");
});

Просмотреть файл

@ -8,21 +8,25 @@ var hasPocket = Services.prefs.getBoolPref("extensions.pocket.enabled");
var hasQuit = AppConstants.platform != "macosx";
requestLongerTimeout(2);
add_task(setup_UITourTest);
add_UITour_task(async function test_availableTargets() {
let data = await getConfigurationPromise("availableTargets");
ok_targets(data, [
function getExpectedTargets() {
return [
"accountStatus",
"addons",
"appMenu",
"backForward",
"bookmarks",
"bookmark-star-button",
"customize",
"devtools",
"help",
"home",
"library",
"pageActionButton",
"pageAction-panel-bookmark",
"pageAction-panel-copyURL",
"pageAction-panel-emailLink",
"pageAction-panel-sendToDevice",
...(hasPocket ? ["pocket"] : []),
"privateWindow",
...(hasQuit ? ["quit"] : []),
@ -31,7 +35,15 @@ add_UITour_task(async function test_availableTargets() {
"searchIcon",
"trackingProtection",
"urlbar",
]);
];
}
add_task(setup_UITourTest);
add_UITour_task(async function test_availableTargets() {
let data = await getConfigurationPromise("availableTargets");
let expecteds = getExpectedTargets();
ok_targets(data, expecteds);
ok(UITour.availableTargetsCache.has(window),
"Targets should now be cached");
@ -42,25 +54,9 @@ add_UITour_task(async function test_availableTargets_changeWidgets() {
ok(!UITour.availableTargetsCache.has(window),
"Targets should be evicted from cache after widget change");
let data = await getConfigurationPromise("availableTargets");
ok_targets(data, [
"accountStatus",
"addons",
"appMenu",
"backForward",
"customize",
"help",
"devtools",
"home",
"library",
...(hasPocket ? ["pocket"] : []),
"privateWindow",
...(hasQuit ? ["quit"] : []),
"readerMode-urlBar",
"search",
"searchIcon",
"trackingProtection",
"urlbar",
]);
let expecteds = getExpectedTargets();
expecteds = expecteds.filter(target => target != "bookmarks");
ok_targets(data, expecteds);
ok(UITour.availableTargetsCache.has(window),
"Targets should now be cached again");
@ -74,25 +70,10 @@ add_UITour_task(async function test_availableTargets_exceptionFromGetTarget() {
// Make sure the callback still fires with the other available targets.
CustomizableUI.removeWidgetFromArea("search-container");
let data = await getConfigurationPromise("availableTargets");
let expecteds = getExpectedTargets();
// Default minus "search" and "searchIcon"
ok_targets(data, [
"accountStatus",
"addons",
"appMenu",
"backForward",
"bookmarks",
"customize",
"devtools",
"help",
"home",
"library",
...(hasPocket ? ["pocket"] : []),
"privateWindow",
...(hasQuit ? ["quit"] : []),
"readerMode-urlBar",
"trackingProtection",
"urlbar",
]);
expecteds = expecteds.filter(target => target != "search" && target != "searchIcon");
ok_targets(data, expecteds);
CustomizableUI.reset();
});

Просмотреть файл

@ -10,7 +10,7 @@ var gContentWindow;
add_task(setup_UITourTest);
add_UITour_task(async function test_showMenu() {
add_UITour_task(async function test_showMenu_controlCenter() {
is_element_hidden(CONTROL_CENTER_PANEL, "Panel should initially be hidden");
await showMenuPromise(CONTROL_CENTER_MENU_NAME);
is_element_visible(CONTROL_CENTER_PANEL, "Panel should be visible after showMenu");
@ -32,7 +32,7 @@ add_UITour_task(async function test_showMenu() {
is_element_hidden(CONTROL_CENTER_PANEL, "Panel should hide upon tab switch");
});
add_UITour_task(async function test_hideMenu() {
add_UITour_task(async function test_hideMenu_controlCenter() {
is_element_hidden(CONTROL_CENTER_PANEL, "Panel should initially be hidden");
await showMenuPromise(CONTROL_CENTER_MENU_NAME);
is_element_visible(CONTROL_CENTER_PANEL, "Panel should be visible after showMenu");
@ -42,3 +42,27 @@ add_UITour_task(async function test_hideMenu() {
is_element_hidden(CONTROL_CENTER_PANEL, "Panel should hide after hideMenu");
});
add_UITour_task(async function test_showMenu_hideMenu_urlbarPopup() {
let shownPromise = promisePanelElementShown(window, gURLBar.popup);
await showMenuPromise("urlbar");
await shownPromise;
is(gURLBar.popup.state, "open", "The urlbar popup should open after showMenu");
is(gURLBar.controller.searchString, "Firefox", "Search string is Firefox");
let hidePromise = promisePanelElementHidden(window, gURLBar.popup);
await gContentAPI.hideMenu("urlbar");
await hidePromise;
is(gURLBar.popup.state, "closed", "The urlbar popup should close after hideMenu");
});
add_UITour_task(async function test_showMenu_hideMenu_pageActionPanel() {
let pageActionPanel = BrowserPageActions.panelNode;
let shownPromise = promisePanelElementShown(window, pageActionPanel);
await showMenuPromise("pageActionPanel");
await shownPromise;
is(pageActionPanel.state, "open", "The page action panel should open after showMenu");
let hidePromise = promisePanelElementHidden(window, pageActionPanel);
await gContentAPI.hideMenu("pageActionPanel");
await hidePromise;
is(pageActionPanel.state, "closed", "The page action panel should close after hideMenu");
});

Просмотреть файл

@ -1,20 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(setup_UITourTest);
var gTestTab;
var gContentAPI;
var gContentWindow;
add_UITour_task(async function test_openSearchPanel() {
let urlbar = window.document.getElementById("urlbar");
urlbar.focus();
await showMenuPromise("urlbar");
is(urlbar.popup.state, "open", "Popup was opened");
is(urlbar.controller.searchString, "Firefox", "Search string is Firefox");
urlbar.popup.closePopup();
is(urlbar.popup.state, "closed", "Popup was closed");
});

Просмотреть файл

@ -136,6 +136,16 @@ function getConfigurationPromise(configName) {
});
}
function getShowHighlightTargetName() {
let highlight = document.getElementById("UITourHighlight");
return highlight.parentElement.getAttribute("targetName");
}
function getShowInfoTargetName() {
let tooltip = document.getElementById("UITourTooltip");
return tooltip.getAttribute("targetName");
}
function hideInfoPromise(...args) {
let popup = document.getElementById("UITourTooltip");
gContentAPI.hideInfo.apply(gContentAPI, args);