Bug 1716639 - Add a "Disable" button to the Firefox Suggest onboarding prompt that opens about:preferences#search. r=daleharvey

Differential Revision: https://phabricator.services.mozilla.com/D117950
This commit is contained in:
Drew Willcoxon 2021-06-16 21:16:34 +00:00
Родитель a1fe650713
Коммит c2b15a15cd
6 изменённых файлов: 141 добавлений и 5 удалений

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

@ -64,7 +64,7 @@
data-l10n-id="search-show-suggestions-above-history-option"
preference="browser.urlbar.showSearchSuggestionsFirst"/>
<!-- This box is visible only for users enrolled in the en-US Quick Suggest experiment. -->
<hbox id="showQuickSuggestContainer" align="center" hidden="true">
<hbox id="showQuickSuggestContainer" data-subcategory="quickSuggest" align="center" hidden="true">
<checkbox id="showQuickSuggest"
class="tail-with-learn-more"
label="Show Firefox Suggest in the address bar (suggested and sponsored results)"

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

@ -236,7 +236,7 @@ class Suggestions {
return;
}
let params = { learnMore: false };
let params = { disable: false, learnMore: false };
let win = BrowserWindowTracker.getTopWindow();
await win.gDialogBox.open(
"chrome://browser/content/urlbar/quicksuggestOnboarding.xhtml",
@ -245,7 +245,9 @@ class Suggestions {
UrlbarPrefs.set(SEEN_DIALOG_PREF, true);
if (params.learnMore) {
if (params.disable) {
win.openPreferences("search-quickSuggest");
} else if (params.learnMore) {
win.openTrustedLinkIn(UrlbarProviderQuickSuggest.helpUrl, "tab", {
fromChrome: true,
});

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

@ -5,6 +5,10 @@
"use strict";
document.addEventListener("dialogextra1", () => {
window.arguments[0].disable = true;
window.close();
});
document.addEventListener("dialogextra2", () => {
window.arguments[0].learnMore = true;
window.close();
});

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

@ -15,7 +15,7 @@
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
aria-describedby="infoBody">
<dialog id="quicksuggestOnboardingDialog"
buttons="accept, extra1"
buttons="accept, extra1, extra2"
defaultButton="accept">
<linkset>
@ -35,8 +35,11 @@
<xul:button id="onboardingAccept"
dlgtype="accept"
label="Okay, got it!"></xul:button>
<xul:button id="onboardingLearnMore"
<xul:button id="onboardingDisable"
dlgtype="extra1"
label="Disable"></xul:button>
<xul:button id="onboardingLearnMore"
dlgtype="extra2"
label="Learn more"></xul:button>
</div>
</div>

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

@ -173,6 +173,7 @@ skip-if = asan # Bug 1701321
support-files =
quicksuggest.sjs
skip-if = asan # Bug 1701321
[browser_quicksuggest_onboardingDialog.js]
[browser_raceWithTabs.js]
[browser_redirect_error.js]
support-files = redirect_error.sjs

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

@ -0,0 +1,126 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests the buttons in the onboarding dialog for quick suggest/Firefox Suggest.
*/
XPCOMUtils.defineLazyModuleGetters(this, {
UrlbarQuickSuggest: "resource:///modules/UrlbarQuickSuggest.jsm",
});
const DIALOG_URI =
"chrome://browser/content/urlbar/quicksuggestOnboarding.xhtml";
const LEARN_MORE_URL =
Services.urlFormatter.formatURLPref("app.support.baseURL") +
"firefox-suggest";
const MR1_VERSION = 89;
// When the accept button is clicked, no new pages should load.
add_task(async function accept() {
await doDialogTest(async () => {
let tabCount = gBrowser.tabs.length;
let dialogPromise = openDialog("accept");
info("Calling maybeShowOnboardingDialog");
await UrlbarQuickSuggest.maybeShowOnboardingDialog();
info("Waiting for dialog");
await dialogPromise;
Assert.equal(
gBrowser.currentURI.spec,
"about:blank",
"Nothing loaded in the current tab"
);
Assert.equal(gBrowser.tabs.length, tabCount, "No news tabs were opened");
});
});
// When the Disable button is clicked, about:preferences#search should load.
add_task(async function disable() {
await doDialogTest(async () => {
let dialogPromise = openDialog("extra1");
// about:preferences#search will load in the current tab since it's
// about:blank.
let loadPromise = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser
).then(() => info("Saw load"));
info("Calling maybeShowOnboardingDialog");
await UrlbarQuickSuggest.maybeShowOnboardingDialog();
info("Waiting for dialog");
await dialogPromise;
info("Waiting for load");
await loadPromise;
Assert.equal(
gBrowser.currentURI.spec,
"about:preferences#search",
"Current tab is about:preferences#search"
);
});
});
// When the Learn More button is clicked, the support URL should open in a new
// tab.
add_task(async function learnMore() {
await doDialogTest(async () => {
let dialogPromise = openDialog("extra2");
let loadPromise = BrowserTestUtils.waitForNewTab(
gBrowser,
LEARN_MORE_URL
).then(tab => {
info("Saw new tab");
return tab;
});
info("Calling maybeShowOnboardingDialog");
await UrlbarQuickSuggest.maybeShowOnboardingDialog();
info("Waiting for dialog");
await dialogPromise;
info("Waiting for new tab");
let tab = await loadPromise;
Assert.equal(gBrowser.selectedTab, tab, "Current tab is the new tab");
Assert.equal(
gBrowser.currentURI.spec,
LEARN_MORE_URL,
"Current tab is the support page"
);
BrowserTestUtils.removeTab(tab);
});
});
async function doDialogTest(callback) {
await BrowserTestUtils.withNewTab("about:blank", async () => {
// Set all the required prefs for showing the onboarding dialog.
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.quicksuggest.enabled", true],
["browser.urlbar.quicksuggest.shouldShowOnboardingDialog", true],
["browser.urlbar.quicksuggest.showedOnboardingDialog", false],
["browser.urlbar.quicksuggest.showOnboardingDialogAfterNRestarts", 0],
["browser.startup.upgradeDialog.version", MR1_VERSION],
],
});
await callback();
await SpecialPowers.popPrefEnv();
});
}
async function openDialog(button) {
await BrowserTestUtils.promiseAlertDialog(button, DIALOG_URI, {
isSubDialog: true,
});
info("Saw dialog");
}