From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- browser/components/uitour/test/browser.ini | 49 ++ browser/components/uitour/test/browser_UITour.js | 751 +++++++++++++++++++++ browser/components/uitour/test/browser_UITour2.js | 150 ++++ browser/components/uitour/test/browser_UITour3.js | 317 +++++++++ browser/components/uitour/test/browser_UITour4.js | 235 +++++++ browser/components/uitour/test/browser_UITour5.js | 60 ++ .../browser_UITour_annotation_size_attributes.js | 65 ++ .../uitour/test/browser_UITour_availableTargets.js | 129 ++++ .../uitour/test/browser_UITour_colorway.js | 74 ++ .../uitour/test/browser_UITour_defaultBrowser.js | 66 ++ .../uitour/test/browser_UITour_detach_tab.js | 113 ++++ .../uitour/test/browser_UITour_forceReaderMode.js | 24 + .../uitour/test/browser_UITour_modalDialog.js | 116 ++++ .../uitour/test/browser_UITour_observe.js | 99 +++ .../test/browser_UITour_panel_close_annotation.js | 227 +++++++ .../uitour/test/browser_UITour_pocket.js | 38 ++ .../uitour/test/browser_UITour_resetProfile.js | 46 ++ .../uitour/test/browser_UITour_showNewTab.js | 25 + .../test/browser_UITour_showProtectionReport.js | 47 ++ .../components/uitour/test/browser_UITour_sync.js | 231 +++++++ .../uitour/test/browser_UITour_toggleReaderMode.js | 21 + .../uitour/test/browser_backgroundTab.js | 57 ++ browser/components/uitour/test/browser_closeTab.js | 23 + browser/components/uitour/test/browser_fxa.js | 61 ++ .../components/uitour/test/browser_fxa_config.js | 379 +++++++++++ .../uitour/test/browser_openPreferences.js | 73 ++ .../uitour/test/browser_openSearchPanel.js | 34 + browser/components/uitour/test/head.js | 539 +++++++++++++++ browser/components/uitour/test/image.png | Bin 0 -> 56060 bytes browser/components/uitour/test/uitour.html | 42 ++ 30 files changed, 4091 insertions(+) create mode 100644 browser/components/uitour/test/browser.ini create mode 100644 browser/components/uitour/test/browser_UITour.js create mode 100644 browser/components/uitour/test/browser_UITour2.js create mode 100644 browser/components/uitour/test/browser_UITour3.js create mode 100644 browser/components/uitour/test/browser_UITour4.js create mode 100644 browser/components/uitour/test/browser_UITour5.js create mode 100644 browser/components/uitour/test/browser_UITour_annotation_size_attributes.js create mode 100644 browser/components/uitour/test/browser_UITour_availableTargets.js create mode 100644 browser/components/uitour/test/browser_UITour_colorway.js create mode 100644 browser/components/uitour/test/browser_UITour_defaultBrowser.js create mode 100644 browser/components/uitour/test/browser_UITour_detach_tab.js create mode 100644 browser/components/uitour/test/browser_UITour_forceReaderMode.js create mode 100644 browser/components/uitour/test/browser_UITour_modalDialog.js create mode 100644 browser/components/uitour/test/browser_UITour_observe.js create mode 100644 browser/components/uitour/test/browser_UITour_panel_close_annotation.js create mode 100644 browser/components/uitour/test/browser_UITour_pocket.js create mode 100644 browser/components/uitour/test/browser_UITour_resetProfile.js create mode 100644 browser/components/uitour/test/browser_UITour_showNewTab.js create mode 100644 browser/components/uitour/test/browser_UITour_showProtectionReport.js create mode 100644 browser/components/uitour/test/browser_UITour_sync.js create mode 100644 browser/components/uitour/test/browser_UITour_toggleReaderMode.js create mode 100644 browser/components/uitour/test/browser_backgroundTab.js create mode 100644 browser/components/uitour/test/browser_closeTab.js create mode 100644 browser/components/uitour/test/browser_fxa.js create mode 100644 browser/components/uitour/test/browser_fxa_config.js create mode 100644 browser/components/uitour/test/browser_openPreferences.js create mode 100644 browser/components/uitour/test/browser_openSearchPanel.js create mode 100644 browser/components/uitour/test/head.js create mode 100644 browser/components/uitour/test/image.png create mode 100644 browser/components/uitour/test/uitour.html (limited to 'browser/components/uitour/test') diff --git a/browser/components/uitour/test/browser.ini b/browser/components/uitour/test/browser.ini new file mode 100644 index 0000000000..2fb34ea080 --- /dev/null +++ b/browser/components/uitour/test/browser.ini @@ -0,0 +1,49 @@ +[DEFAULT] +support-files = + head.js + image.png + uitour.html + ../UITour-lib.js + + +[browser_UITour.js] +skip-if = + os == "linux" || verify # Intermittent failures, bug 951965 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_UITour2.js] +[browser_UITour3.js] +[browser_UITour4.js] +[browser_UITour5.js] +[browser_UITour_annotation_size_attributes.js] +[browser_UITour_availableTargets.js] +[browser_UITour_colorway.js] +[browser_UITour_defaultBrowser.js] +[browser_UITour_detach_tab.js] +[browser_UITour_forceReaderMode.js] +[browser_UITour_modalDialog.js] +skip-if = os != "mac" # modal dialog disabling only working on OS X. +[browser_UITour_observe.js] +[browser_UITour_panel_close_annotation.js] +skip-if = true # Bug 1026310 +[browser_UITour_pocket.js] +skip-if = true # Disabled pending removal of pocket UI Tour +[browser_UITour_resetProfile.js] +skip-if = (verify && !debug && (os == 'linux')) +[browser_UITour_showNewTab.js] +skip-if = (verify && !debug && (os == 'linux')) +[browser_UITour_showProtectionReport.js] +skip-if = os == "linux" && (asan || debug || tsan) # Bug 1697217 +[browser_UITour_sync.js] +skip-if = + os == "linux" # Bug 1678417 + os == "win" && os_version == "6.1" # Skip on Azure - frequent failure +[browser_UITour_toggleReaderMode.js] +skip-if = (verify && !debug && (os == 'linux')) +[browser_backgroundTab.js] +[browser_closeTab.js] +skip-if = (verify && !debug && (os == 'linux')) +[browser_fxa.js] +[browser_fxa_config.js] +[browser_openPreferences.js] +[browser_openSearchPanel.js] +skip-if = true # Bug 1113038 - Intermittent "Popup was opened" diff --git a/browser/components/uitour/test/browser_UITour.js b/browser/components/uitour/test/browser_UITour.js new file mode 100644 index 0000000000..fc2353117a --- /dev/null +++ b/browser/components/uitour/test/browser_UITour.js @@ -0,0 +1,751 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var gTestTab; +var gContentAPI; + +ChromeUtils.defineESModuleGetters(this, { + ProfileAge: "resource://gre/modules/ProfileAge.sys.mjs", + TelemetryArchiveTesting: + "resource://testing-common/TelemetryArchiveTesting.sys.mjs", + TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.sys.mjs", + UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs", +}); + +function test() { + UITourTest(); +} + +var tests = [ + function test_untrusted_host(done) { + loadUITourTestPage(function () { + CustomizableUI.addWidgetToArea( + "bookmarks-menu-button", + CustomizableUI.AREA_NAVBAR, + 0 + ); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("bookmarks-menu-button") + ); + let bookmarksMenu = document.getElementById("bookmarks-menu-button"); + is(bookmarksMenu.open, false, "Bookmark menu should initially be closed"); + + gContentAPI.showMenu("bookmarks"); + is( + bookmarksMenu.open, + false, + "Bookmark menu should not open on a untrusted host" + ); + + done(); + }, "http://mochi.test:8888/"); + }, + function test_testing_host(done) { + // Add two testing origins intentionally surrounded by whitespace to be ignored. + Services.prefs.setCharPref( + "browser.uitour.testingOrigins", + "https://test1.example.org, https://test2.example.org:443 " + ); + + registerCleanupFunction(() => { + Services.prefs.clearUserPref("browser.uitour.testingOrigins"); + }); + function callback(result) { + ok(result, "Callback should be called on a testing origin"); + done(); + } + + loadUITourTestPage(function () { + gContentAPI.getConfiguration("appinfo", callback); + }, "https://test2.example.org/"); + }, + function test_unsecure_host(done) { + loadUITourTestPage(function () { + let bookmarksMenu = document.getElementById("bookmarks-menu-button"); + is(bookmarksMenu.open, false, "Bookmark menu should initially be closed"); + + gContentAPI.showMenu("bookmarks"); + is( + bookmarksMenu.open, + false, + "Bookmark menu should not open on a unsecure host" + ); + + done(); + }, "http://example.org/"); + }, + function test_unsecure_host_override(done) { + Services.prefs.setBoolPref("browser.uitour.requireSecure", false); + loadUITourTestPage(function () { + let highlight = document.getElementById("UITourHighlight"); + is_element_hidden(highlight, "Highlight should initially be hidden"); + + gContentAPI.showHighlight("urlbar").then(() => { + waitForElementToBeVisible( + highlight, + done, + "Highlight should be shown on a unsecure host when override pref is set" + ); + + Services.prefs.setBoolPref("browser.uitour.requireSecure", true); + }); + }, "http://example.org/"); + }, + function test_disabled(done) { + Services.prefs.setBoolPref("browser.uitour.enabled", false); + + let bookmarksMenu = document.getElementById("bookmarks-menu-button"); + is(bookmarksMenu.open, false, "Bookmark menu should initially be closed"); + + gContentAPI.showMenu("bookmarks").then(() => { + is( + bookmarksMenu.open, + false, + "Bookmark menu should not open when feature is disabled" + ); + + Services.prefs.setBoolPref("browser.uitour.enabled", true); + }); + done(); + }, + function test_highlight(done) { + function test_highlight_2() { + let highlight = document.getElementById("UITourHighlight"); + gContentAPI.hideHighlight(); + + waitForElementToBeHidden( + highlight, + test_highlight_3, + "Highlight should be hidden after hideHighlight()" + ); + } + function test_highlight_3() { + is_element_hidden( + highlight, + "Highlight should be hidden after hideHighlight()" + ); + + gContentAPI.showHighlight("urlbar"); + waitForElementToBeVisible( + highlight, + test_highlight_4, + "Highlight should be shown after showHighlight()" + ); + } + function test_highlight_4() { + let highlight = document.getElementById("UITourHighlight"); + gContentAPI.showHighlight("backForward"); + waitForElementToBeVisible( + highlight, + done, + "Highlight should be shown after showHighlight()" + ); + } + + let highlight = document.getElementById("UITourHighlight"); + is_element_hidden(highlight, "Highlight should initially be hidden"); + + gContentAPI.showHighlight("urlbar"); + waitForElementToBeVisible( + highlight, + test_highlight_2, + "Highlight should be shown after showHighlight()" + ); + }, + function test_highlight_toolbar_button(done) { + function check_highlight_size() { + let panel = highlight.parentElement; + let anchor = panel.anchorNode; + let anchorRect = anchor.getBoundingClientRect(); + info( + "addons target: width: " + + anchorRect.width + + " height: " + + anchorRect.height + ); + let dimension = anchorRect.width; + let highlightRect = highlight.getBoundingClientRect(); + info( + "highlight: width: " + + highlightRect.width + + " height: " + + highlightRect.height + ); + is( + Math.round(highlightRect.width), + dimension, + "The width of the highlight should be equal to the width of the target" + ); + is( + Math.round(highlightRect.height), + dimension, + "The height of the highlight should be equal to the width of the target" + ); + is( + highlight.classList.contains("rounded-highlight"), + true, + "Highlight should be rounded-rectangle styled" + ); + CustomizableUI.removeWidgetFromArea("home-button"); + done(); + } + info("Adding home button."); + CustomizableUI.addWidgetToArea("home-button", "nav-bar"); + // Force the button to get layout so we can show the highlight. + document.getElementById("home-button").clientHeight; + let highlight = document.getElementById("UITourHighlight"); + is_element_hidden(highlight, "Highlight should initially be hidden"); + + gContentAPI.showHighlight("home"); + waitForElementToBeVisible( + highlight, + check_highlight_size, + "Highlight should be shown after showHighlight()" + ); + }, + function test_highlight_addons_auto_open_close(done) { + let highlight = document.getElementById("UITourHighlight"); + gContentAPI.showHighlight("addons"); + waitForElementToBeVisible( + highlight, + function checkPanelIsOpen() { + isnot(PanelUI.panel.state, "closed", "Panel should have opened"); + isnot( + highlight.classList.contains("rounded-highlight"), + true, + "Highlight should not be round-rectangle styled." + ); + + let hiddenPromise = promisePanelElementHidden(window, PanelUI.panel); + // Move the highlight outside which should close the app menu. + gContentAPI.showHighlight("appMenu"); + hiddenPromise.then(() => { + waitForElementToBeVisible( + highlight, + function checkPanelIsClosed() { + isnot( + PanelUI.panel.state, + "open", + "Panel should have closed after the highlight moved elsewhere." + ); + done(); + }, + "Highlight should move to the appMenu button" + ); + }); + }, + "Highlight should be shown after showHighlight() for fixed panel items" + ); + }, + function test_highlight_addons_manual_open_close(done) { + let highlight = document.getElementById("UITourHighlight"); + // Manually open the app menu then show a highlight there. The menu should remain open. + let shownPromise = promisePanelShown(window); + gContentAPI.showMenu("appMenu"); + shownPromise + .then(() => { + isnot(PanelUI.panel.state, "closed", "Panel should have opened"); + gContentAPI.showHighlight("addons"); + + waitForElementToBeVisible( + highlight, + function checkPanelIsStillOpen() { + isnot(PanelUI.panel.state, "closed", "Panel should still be open"); + + // Move the highlight outside which shouldn't close the app menu since it was manually opened. + gContentAPI.showHighlight("appMenu"); + waitForElementToBeVisible( + highlight, + function () { + isnot( + PanelUI.panel.state, + "closed", + "Panel should remain open since UITour didn't open it in the first place" + ); + gContentAPI.hideMenu("appMenu"); + done(); + }, + "Highlight should move to the appMenu button" + ); + }, + "Highlight should be shown after showHighlight() for fixed panel items" + ); + }) + .catch(console.error); + }, + function test_highlight_effect(done) { + function waitForHighlightWithEffect(highlightEl, effect, next, error) { + return waitForCondition( + () => highlightEl.getAttribute("active") == effect, + next, + error + ); + } + function checkDefaultEffect() { + is( + highlight.getAttribute("active"), + "none", + "The default should be no effect" + ); + + gContentAPI.showHighlight("urlbar", "none"); + waitForHighlightWithEffect( + highlight, + "none", + checkZoomEffect, + "There should be no effect" + ); + } + function checkZoomEffect() { + gContentAPI.showHighlight("urlbar", "zoom"); + waitForHighlightWithEffect( + highlight, + "zoom", + () => { + let style = window.getComputedStyle(highlight); + is( + style.animationName, + "uitour-zoom", + "The animation-name should be uitour-zoom" + ); + checkSameEffectOnDifferentTarget(); + }, + "There should be a zoom effect" + ); + } + function checkSameEffectOnDifferentTarget() { + gContentAPI.showHighlight("appMenu", "wobble"); + waitForHighlightWithEffect( + highlight, + "wobble", + () => { + highlight.addEventListener( + "animationstart", + function (aEvent) { + ok( + true, + "Animation occurred again even though the effect was the same" + ); + checkRandomEffect(); + }, + { once: true } + ); + gContentAPI.showHighlight("backForward", "wobble"); + }, + "There should be a wobble effect" + ); + } + function checkRandomEffect() { + function waitForActiveHighlight(highlightEl, next, error) { + return waitForCondition( + () => highlightEl.hasAttribute("active"), + next, + error + ); + } + + gContentAPI.hideHighlight(); + gContentAPI.showHighlight("urlbar", "random"); + waitForActiveHighlight( + highlight, + () => { + ok( + highlight.hasAttribute("active"), + "The highlight should be active" + ); + isnot( + highlight.getAttribute("active"), + "none", + "A random effect other than none should have been chosen" + ); + isnot( + highlight.getAttribute("active"), + "random", + "The random effect shouldn't be 'random'" + ); + isnot( + UITour.highlightEffects.indexOf(highlight.getAttribute("active")), + -1, + "Check that a supported effect was randomly chosen" + ); + done(); + }, + "There should be an active highlight with a random effect" + ); + } + + let highlight = document.getElementById("UITourHighlight"); + is_element_hidden(highlight, "Highlight should initially be hidden"); + + gContentAPI.showHighlight("urlbar"); + waitForElementToBeVisible( + highlight, + checkDefaultEffect, + "Highlight should be shown after showHighlight()" + ); + }, + function test_highlight_effect_unsupported(done) { + function checkUnsupportedEffect() { + is( + highlight.getAttribute("active"), + "none", + "No effect should be used when an unsupported effect is requested" + ); + done(); + } + + let highlight = document.getElementById("UITourHighlight"); + is_element_hidden(highlight, "Highlight should initially be hidden"); + + gContentAPI.showHighlight("urlbar", "__UNSUPPORTED__"); + waitForElementToBeVisible( + highlight, + checkUnsupportedEffect, + "Highlight should be shown after showHighlight()" + ); + }, + function test_info_1(done) { + let popup = document.getElementById("UITourTooltip"); + let title = document.getElementById("UITourTooltipTitle"); + let desc = document.getElementById("UITourTooltipDescription"); + let icon = document.getElementById("UITourTooltipIcon"); + let buttons = document.getElementById("UITourTooltipButtons"); + + popup.addEventListener( + "popupshown", + function () { + is( + popup.anchorNode, + document.getElementById("urlbar"), + "Popup should be anchored to the urlbar" + ); + is(title.textContent, "test title", "Popup should have correct title"); + is( + desc.textContent, + "test text", + "Popup should have correct description text" + ); + is(icon.src, "", "Popup should have no icon"); + is(buttons.hasChildNodes(), false, "Popup should have no buttons"); + + popup.addEventListener( + "popuphidden", + function () { + popup.addEventListener( + "popupshown", + function () { + done(); + }, + { once: true } + ); + + gContentAPI.showInfo("urlbar", "test title", "test text"); + }, + { once: true } + ); + gContentAPI.hideInfo(); + }, + { once: true } + ); + + gContentAPI.showInfo("urlbar", "test title", "test text"); + }, + taskify(async function test_info_2() { + let popup = document.getElementById("UITourTooltip"); + let title = document.getElementById("UITourTooltipTitle"); + let desc = document.getElementById("UITourTooltipDescription"); + let icon = document.getElementById("UITourTooltipIcon"); + let buttons = document.getElementById("UITourTooltipButtons"); + + await showInfoPromise("urlbar", "urlbar title", "urlbar text"); + + is( + popup.anchorNode, + document.getElementById("urlbar"), + "Popup should be anchored to the urlbar" + ); + is(title.textContent, "urlbar title", "Popup should have correct title"); + is( + desc.textContent, + "urlbar text", + "Popup should have correct description text" + ); + is(icon.src, "", "Popup should have no icon"); + is(buttons.hasChildNodes(), false, "Popup should have no buttons"); + + // Place the search bar in the navigation toolbar temporarily. + await SpecialPowers.pushPrefEnv({ + set: [["browser.search.widget.inNavBar", true]], + }); + + await showInfoPromise("search", "search title", "search text"); + + is( + popup.anchorNode, + document.getElementById("searchbar"), + "Popup should be anchored to the searchbar" + ); + is(title.textContent, "search title", "Popup should have correct title"); + is( + desc.textContent, + "search text", + "Popup should have correct description text" + ); + + await SpecialPowers.popPrefEnv(); + }), + function test_getConfigurationVersion(done) { + function callback(result) { + ok( + typeof result.version !== "undefined", + "Check version isn't undefined." + ); + is( + result.version, + Services.appinfo.version, + "Should have the same version property." + ); + is( + result.defaultUpdateChannel, + UpdateUtils.getUpdateChannel(false), + "Should have the correct update channel." + ); + done(); + } + + gContentAPI.getConfiguration("appinfo", callback); + }, + function test_getConfigurationDistribution(done) { + gContentAPI.getConfiguration("appinfo", result => { + ok( + typeof result.distribution !== "undefined", + "Check distribution isn't undefined." + ); + // distribution id defaults to "default" for most builds, and + // "mozilla-MSIX" for MSIX builds. + is( + result.distribution, + AppConstants.platform === "win" && + Services.sysinfo.getProperty("hasWinPackageId") + ? "mozilla-MSIX" + : "default", + 'Should be "default" without preference set.' + ); + + let defaults = Services.prefs.getDefaultBranch("distribution."); + let testDistributionID = "TestDistribution"; + defaults.setCharPref("id", testDistributionID); + gContentAPI.getConfiguration("appinfo", result2 => { + ok( + typeof result2.distribution !== "undefined", + "Check distribution isn't undefined." + ); + is( + result2.distribution, + testDistributionID, + "Should have the distribution as set in preference." + ); + + done(); + }); + }); + }, + function test_getConfigurationProfileAge(done) { + gContentAPI.getConfiguration("appinfo", result => { + ok( + typeof result.profileCreatedWeeksAgo === "number", + "profileCreatedWeeksAgo should be number." + ); + ok( + result.profileResetWeeksAgo === null, + "profileResetWeeksAgo should be null." + ); + + // Set profile reset date to 15 days ago. + ProfileAge().then(profileAccessor => { + profileAccessor.recordProfileReset( + Date.now() - 15 * 24 * 60 * 60 * 1000 + ); + gContentAPI.getConfiguration("appinfo", result2 => { + ok( + typeof result2.profileResetWeeksAgo === "number", + "profileResetWeeksAgo should be number." + ); + is( + result2.profileResetWeeksAgo, + 2, + "profileResetWeeksAgo should be 2." + ); + done(); + }); + }); + }); + }, + function test_addToolbarButton(done) { + let placement = CustomizableUI.getPlacementOfWidget("panic-button"); + is(placement, null, "default UI has panic button in the palette"); + + gContentAPI.getConfiguration("availableTargets", data => { + let available = data.targets.includes("forget"); + ok(!available, "Forget button should not be available by default"); + + gContentAPI.addNavBarWidget("forget", () => { + info("addNavBarWidget callback successfully called"); + + let updatedPlacement = + CustomizableUI.getPlacementOfWidget("panic-button"); + is(updatedPlacement.area, CustomizableUI.AREA_NAVBAR); + + gContentAPI.getConfiguration("availableTargets", data2 => { + let updatedAvailable = data2.targets.includes("forget"); + ok(updatedAvailable, "Forget button should now be available"); + + // Cleanup + CustomizableUI.removeWidgetFromArea("panic-button"); + done(); + }); + }); + }); + }, + taskify(async function test_search() { + let defaultEngine = await Services.search.getDefault(); + let visibleEngines = await Services.search.getVisibleEngines(); + let expectedEngines = visibleEngines + .filter(engine => engine.identifier) + .map(engine => "searchEngine-" + engine.identifier); + + let data = await new Promise(resolve => + gContentAPI.getConfiguration("search", resolve) + ); + let engines = data.engines; + ok(Array.isArray(engines), "data.engines should be an array"); + is( + engines.sort().toString(), + expectedEngines.sort().toString(), + "Engines should be as expected" + ); + + is( + data.searchEngineIdentifier, + defaultEngine.identifier, + "the searchEngineIdentifier property should contain the defaultEngine's identifier" + ); + + let someOtherEngineID = data.engines.filter( + t => t != "searchEngine-" + defaultEngine.identifier + )[0]; + someOtherEngineID = someOtherEngineID.replace(/^searchEngine-/, ""); + + Services.telemetry.clearEvents(); + Services.fog.testResetFOG(); + + await new Promise(resolve => { + let observe = function (subject, topic, verb) { + Services.obs.removeObserver(observe, "browser-search-engine-modified"); + info("browser-search-engine-modified: " + verb); + if (verb == "engine-default") { + is( + Services.search.defaultEngine.identifier, + someOtherEngineID, + "correct engine was switched to" + ); + resolve(); + } + }; + Services.obs.addObserver(observe, "browser-search-engine-modified"); + registerCleanupFunction(async () => { + await Services.search.setDefault( + defaultEngine, + Ci.nsISearchService.CHANGE_REASON_UNKNOWN + ); + }); + + gContentAPI.setDefaultSearchEngine(someOtherEngineID); + }); + + let engine = (await Services.search.getVisibleEngines()).filter( + e => e.identifier == someOtherEngineID + )[0]; + + let submissionUrl = engine + .getSubmission("dummy") + .uri.spec.replace("dummy", ""); + + TelemetryTestUtils.assertEvents( + [ + { + object: "change_default", + value: "uitour", + extra: { + prev_id: defaultEngine.telemetryId, + new_id: engine.telemetryId, + new_name: engine.name, + new_load_path: engine.wrappedJSObject._loadPath, + // Telemetry has a limit of 80 characters. + new_sub_url: submissionUrl.slice(0, 80), + }, + }, + ], + { category: "search", method: "engine" } + ); + + let snapshot = await Glean.searchEngineDefault.changed.testGetValue(); + delete snapshot[0].timestamp; + Assert.deepEqual( + snapshot[0], + { + category: "search.engine.default", + name: "changed", + extra: { + change_source: "uitour", + previous_engine_id: defaultEngine.telemetryId, + new_engine_id: engine.telemetryId, + new_display_name: engine.name, + new_load_path: engine.wrappedJSObject._loadPath, + // Glean has a limit of 100 characters. + new_submission_url: submissionUrl.slice(0, 100), + }, + }, + "Should have received the correct event details" + ); + }), + taskify(async function test_treatment_tag() { + let ac = new TelemetryArchiveTesting.Checker(); + await ac.promiseInit(); + await gContentAPI.setTreatmentTag("foobar", "baz"); + // Wait until the treatment telemetry is sent before looking in the archive. + await BrowserTestUtils.waitForContentEvent( + gTestTab.linkedBrowser, + "mozUITourNotification", + false, + event => event.detail.event === "TreatmentTag:TelemetrySent" + ); + await new Promise(resolve => { + gContentAPI.getTreatmentTag("foobar", data => { + is(data.value, "baz", "set and retrieved treatmentTag"); + ac.promiseFindPing("uitour-tag", [ + [["payload", "tagName"], "foobar"], + [["payload", "tagValue"], "baz"], + ]).then( + found => { + ok(found, "Telemetry ping submitted for setTreatmentTag"); + resolve(); + }, + err => { + ok(false, "Exception finding uitour telemetry ping: " + err); + resolve(); + } + ); + }); + }); + }), + + // Make sure this test is last in the file so the appMenu gets left open and done will confirm it got tore down. + taskify(async function cleanupMenus() { + let shownPromise = promisePanelShown(window); + gContentAPI.showMenu("appMenu"); + await shownPromise; + }), +]; diff --git a/browser/components/uitour/test/browser_UITour2.js b/browser/components/uitour/test/browser_UITour2.js new file mode 100644 index 0000000000..d911a6142d --- /dev/null +++ b/browser/components/uitour/test/browser_UITour2.js @@ -0,0 +1,150 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +var gTestTab; +var gContentAPI; + +function test() { + UITourTest(); +} + +var tests = [ + function test_info_addons_auto_open_close(done) { + let popup = document.getElementById("UITourTooltip"); + gContentAPI.showInfo("addons", "Addons", "Let's get addons!"); + + let shownPromise = promisePanelShown(window); + shownPromise.then(() => { + UITour.getTarget(window, "addons").then(addonsTarget => { + waitForPopupAtAnchor( + popup, + addonsTarget.node, + function checkPanelIsOpen() { + isnot( + PanelUI.panel.state, + "closed", + "Panel should have opened before the popup anchored" + ); + ok( + PanelUI.panel.hasAttribute("noautohide"), + "@noautohide on the menu panel should have been set" + ); + + // Move the info outside which should close the app menu. + gContentAPI.showInfo("appMenu", "Open Me", "You know you want to"); + UITour.getTarget(window, "appMenu").then(target => { + waitForPopupAtAnchor( + popup, + target.node, + function checkPanelIsClosed() { + isnot( + PanelUI.panel.state, + "open", + "Panel should have closed after the info moved elsewhere." + ); + ok( + !PanelUI.panel.hasAttribute("noautohide"), + "@noautohide on the menu panel should have been cleaned up on close" + ); + done(); + }, + "Info should move to the appMenu button" + ); + }); + }, + "Info panel should be anchored to the addons button" + ); + }); + }); + }, + function test_info_addons_manual_open_close(done) { + let popup = document.getElementById("UITourTooltip"); + // Manually open the app menu then show an info panel there. The menu should remain open. + let shownPromise = promisePanelShown(window); + gContentAPI.showMenu("appMenu"); + shownPromise + .then(() => { + isnot(PanelUI.panel.state, "closed", "Panel should have opened"); + ok( + PanelUI.panel.hasAttribute("noautohide"), + "@noautohide on the menu panel should have been set" + ); + gContentAPI.showInfo("addons", "Addons", "Let's get addons!"); + + UITour.getTarget(window, "addons").then(customizeTarget => { + waitForPopupAtAnchor( + popup, + customizeTarget.node, + function () { + isnot( + PanelUI.panel.state, + "closed", + "Panel should still be open" + ); + ok( + PanelUI.panel.hasAttribute("noautohide"), + "@noautohide on the menu panel should still be set" + ); + + // Move the info outside which shouldn't close the app menu since it was manually opened. + gContentAPI.showInfo( + "appMenu", + "Open Me", + "You know you want to" + ); + UITour.getTarget(window, "appMenu").then(target => { + waitForPopupAtAnchor( + popup, + target.node, + function () { + isnot( + PanelUI.panel.state, + "closed", + "Menu should remain open since UITour didn't open it in the first place" + ); + waitForElementToBeHidden(window.PanelUI.panel, () => { + ok( + !PanelUI.panel.hasAttribute("noautohide"), + "@noautohide on the menu panel should have been cleaned up on close" + ); + done(); + }); + gContentAPI.hideMenu("appMenu"); + }, + "Info should move to the appMenu button" + ); + }); + }, + "Info should be shown after showInfo() for fixed menu panel items" + ); + }); + }) + .catch(console.error); + }, + taskify(async function test_bookmarks_menu() { + CustomizableUI.addWidgetToArea( + "bookmarks-menu-button", + CustomizableUI.AREA_NAVBAR, + 0 + ); + registerCleanupFunction(() => + CustomizableUI.removeWidgetFromArea("bookmarks-menu-button") + ); + + let bookmarksMenuButton = document.getElementById("bookmarks-menu-button"); + + is(bookmarksMenuButton.open, false, "Menu should initially be closed"); + gContentAPI.showMenu("bookmarks"); + + await waitForConditionPromise(() => { + return bookmarksMenuButton.open; + }, "Menu should be visible after showMenu()"); + + gContentAPI.hideMenu("bookmarks"); + await waitForConditionPromise(() => { + return !bookmarksMenuButton.open; + }, "Menu should be hidden after hideMenu()"); + }), +]; diff --git a/browser/components/uitour/test/browser_UITour3.js b/browser/components/uitour/test/browser_UITour3.js new file mode 100644 index 0000000000..526994f420 --- /dev/null +++ b/browser/components/uitour/test/browser_UITour3.js @@ -0,0 +1,317 @@ +"use strict"; + +const { CustomizableUITestUtils } = ChromeUtils.importESModule( + "resource://testing-common/CustomizableUITestUtils.sys.mjs" +); +let gCUITestUtils = new CustomizableUITestUtils(window); + +var gTestTab; +var gContentAPI; + +requestLongerTimeout(2); + +add_task(setup_UITourTest); + +add_UITour_task(async function test_info_icon() { + let popup = document.getElementById("UITourTooltip"); + let title = document.getElementById("UITourTooltipTitle"); + let desc = document.getElementById("UITourTooltipDescription"); + let icon = document.getElementById("UITourTooltipIcon"); + let buttons = document.getElementById("UITourTooltipButtons"); + + // Disable the animation to prevent the mouse clicks from hitting the main + // window during the transition instead of the buttons in the popup. + popup.setAttribute("animate", "false"); + + await showInfoPromise("urlbar", "a title", "some text", "image.png"); + + is(title.textContent, "a title", "Popup should have correct title"); + is( + desc.textContent, + "some text", + "Popup should have correct description text" + ); + + let imageURL = getRootDirectory(gTestPath) + "image.png"; + imageURL = imageURL.replace( + "chrome://mochitests/content/", + "https://example.org/" + ); + is(icon.src, imageURL, "Popup should have correct icon shown"); + + is(buttons.hasChildNodes(), false, "Popup should have no buttons"); +}); + +add_UITour_task(async function test_info_buttons_1() { + let popup = document.getElementById("UITourTooltip"); + let title = document.getElementById("UITourTooltipTitle"); + let desc = document.getElementById("UITourTooltipDescription"); + let icon = document.getElementById("UITourTooltipIcon"); + + await showInfoPromise( + "urlbar", + "another title", + "moar text", + "./image.png", + "makeButtons" + ); + + is(title.textContent, "another title", "Popup should have correct title"); + is( + desc.textContent, + "moar text", + "Popup should have correct description text" + ); + + let imageURL = getRootDirectory(gTestPath) + "image.png"; + imageURL = imageURL.replace( + "chrome://mochitests/content/", + "https://example.org/" + ); + is(icon.src, imageURL, "Popup should have correct icon shown"); + + let buttons = document.getElementById("UITourTooltipButtons"); + is(buttons.childElementCount, 4, "Popup should have four buttons"); + + is(buttons.children[0].nodeName, "label", "Text label should be a