From 4cbfcb0b8bdeda44f61e3a1324e761b7c103d4ff Mon Sep 17 00:00:00 2001 From: Dan Mosedale Date: Wed, 17 Aug 2022 16:36:39 +0000 Subject: [PATCH] Bug 1783049 - about:welcome should open FxView in its pinned tab, r=Mardak Differential Revision: https://phabricator.services.mozilla.com/D154478 --- .../aboutwelcome/lib/AboutWelcomeDefaults.jsm | 3 +- .../newtab/lib/OnboardingMessageProvider.jsm | 3 +- .../lib/SpecialMessageActions.jsm | 3 + .../SpecialMessageActionSchemas.json | 12 +++ .../SpecialMessageActionSchemas/index.md | 6 ++ .../test/browser/browser.ini | 1 + .../browser/browser_sma_open_firefox_view.js | 75 +++++++++++++++++++ 7 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_firefox_view.js diff --git a/browser/components/newtab/aboutwelcome/lib/AboutWelcomeDefaults.jsm b/browser/components/newtab/aboutwelcome/lib/AboutWelcomeDefaults.jsm index 224518a43636..142e5c08e14e 100644 --- a/browser/components/newtab/aboutwelcome/lib/AboutWelcomeDefaults.jsm +++ b/browser/components/newtab/aboutwelcome/lib/AboutWelcomeDefaults.jsm @@ -531,8 +531,7 @@ const MR_ABOUT_WELCOME_DEFAULT = { primary_button: { label: "See what’s new", action: { - type: "OPEN_ABOUT_PAGE", - data: { args: "firefoxview", where: "current" }, + type: "OPEN_FIREFOX_VIEW", navigate: true, }, }, diff --git a/browser/components/newtab/lib/OnboardingMessageProvider.jsm b/browser/components/newtab/lib/OnboardingMessageProvider.jsm index 46a6793c8679..4fa05495b5b5 100644 --- a/browser/components/newtab/lib/OnboardingMessageProvider.jsm +++ b/browser/components/newtab/lib/OnboardingMessageProvider.jsm @@ -332,8 +332,7 @@ const ONBOARDING_MESSAGES = () => [ primary_button: { label: "See what’s new", action: { - type: "OPEN_ABOUT_PAGE", - data: { args: "firefoxview", where: "current" }, + type: "OPEN_FIREFOX_VIEW", navigate: true, }, }, diff --git a/toolkit/components/messaging-system/lib/SpecialMessageActions.jsm b/toolkit/components/messaging-system/lib/SpecialMessageActions.jsm index 639ddbf5c1ff..a6d21bda9883 100644 --- a/toolkit/components/messaging-system/lib/SpecialMessageActions.jsm +++ b/toolkit/components/messaging-system/lib/SpecialMessageActions.jsm @@ -258,6 +258,9 @@ const SpecialMessageActions = { action.data.where || "tab" ); break; + case "OPEN_FIREFOX_VIEW": + window.FirefoxViewHandler.openTab(); + break; case "OPEN_PREFERENCES_PAGE": window.openPreferences( action.data.category || action.data.args, diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/SpecialMessageActionSchemas.json b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/SpecialMessageActionSchemas.json index 23ee9ae37126..6b297dee6817 100644 --- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/SpecialMessageActionSchemas.json +++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/SpecialMessageActionSchemas.json @@ -97,6 +97,18 @@ "additionalProperties": false, "description": "Opens an about: page in Firefox" }, + { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": ["OPEN_FIREFOX_VIEW"] + } + }, + "required": ["type"], + "additionalProperties": false, + "description": "Opens the Firefox View pseudo-pinned-tab" + }, { "type": "object", "properties": { diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/index.md b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/index.md index 6fb33745d308..1de58cce95ab 100644 --- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/index.md +++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/index.md @@ -21,6 +21,12 @@ For snippets, you should add the action type in `button_action` and any addition Opens the applications menu. +### `OPEN_FIREFOX_VIEW` + +* args: (none) + +Opens the Firefox View pseudo-tab. + ### `OPEN_PRIVATE_BROWSER_WINDOW` * args: (none) diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser.ini b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser.ini index a1e5a319e512..48d256dd9f52 100644 --- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser.ini +++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser.ini @@ -8,6 +8,7 @@ support-files = [browser_sma_block_message.js] [browser_sma_open_about_page.js] [browser_sma_open_awesome_bar.js] +[browser_sma_open_firefox_view.js] [browser_sma_open_private_browser_window.js] [browser_sma_open_protection_panel.js] [browser_sma_open_protection_report.js] diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_firefox_view.js b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_firefox_view.js new file mode 100644 index 000000000000..1a2c76fc44a3 --- /dev/null +++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_firefox_view.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * The setup code and the utility funcitons here are cribbed from (mostly) + * browser/components/firefoxview/test/browser/head.js + * + * https://bugzilla.mozilla.org/show_bug.cgi?id=1784979 has been filed to move + * these to some place publically accessible, after which we will be able to + * a bunch of code from this file. + */ +add_setup(async () => { + await SpecialPowers.pushPrefEnv({ + set: [["browser.tabs.firefox-view", true]], + }); + + CustomizableUI.addWidgetToArea( + "firefox-view-button", + CustomizableUI.AREA_TABSTRIP, + 0 + ); + + registerCleanupFunction(async () => { + // If you're running mochitest with --keep-open=true, and need to + // easily tell whether the button really appeared, comment out the below + // line so that the button hangs around after the test finishes. + CustomizableUI.removeWidgetFromArea("firefox-view-button"); + await SpecialPowers.popPrefEnv(); + }); +}); + +function assertFirefoxViewTab(w = window) { + ok(w.FirefoxViewHandler.tab, "Firefox View tab exists"); + ok(w.FirefoxViewHandler.tab?.hidden, "Firefox View tab is hidden"); + is( + w.gBrowser.tabs.indexOf(w.FirefoxViewHandler.tab), + 0, + "Firefox View tab is the first tab" + ); + is( + w.gBrowser.visibleTabs.indexOf(w.FirefoxViewHandler.tab), + -1, + "Firefox View tab is not in the list of visible tabs" + ); +} + +function closeFirefoxViewTab(w = window) { + w.gBrowser.removeTab(w.FirefoxViewHandler.tab); + ok( + !w.FirefoxViewHandler.tab, + "Reference to Firefox View tab got removed when closing the tab" + ); +} + +add_task(async function test_open_firefox_view() { + // setup + let newTabOpened = BrowserTestUtils.waitForEvent( + gBrowser.tabContainer, + "TabOpen" + ); + + // execute + await SMATestUtils.executeAndValidateAction({ + type: "OPEN_FIREFOX_VIEW", + }); + + // verify + await newTabOpened; + assertFirefoxViewTab(); + + // cleanup + closeFirefoxViewTab(); +});