зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1705121 - Proton new user onboarding welcome screen primary CTA r=pdahiya
Async dynamically modify default proton content based on if app needs pin. Also hide en-only caption. Differential Revision: https://phabricator.services.mozilla.com/D112443
This commit is contained in:
Родитель
f7cfe3bf27
Коммит
081dcd6a4a
|
@ -230,7 +230,7 @@ class AboutWelcomeChild extends JSWindowActorChild {
|
|||
featureConfig = { ...attributionData, ...featureConfig };
|
||||
} else {
|
||||
log.debug("Loading about:welcome with default data");
|
||||
let defaults = AboutWelcomeDefaults.getDefaults(featureConfig);
|
||||
let defaults = await AboutWelcomeDefaults.getDefaults(featureConfig);
|
||||
// FeatureConfig (from prefs or experiments) has higher precendence
|
||||
// to defaults. But the `screens` property isn't defined we shouldn't
|
||||
// override the default with `null`
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const EXPORTED_SYMBOLS = ["AboutWelcomeDefaults"];
|
||||
const EXPORTED_SYMBOLS = ["AboutWelcomeDefaults", "DEFAULT_WELCOME_CONTENT"];
|
||||
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
ShellService: "resource:///modules/ShellService.jsm",
|
||||
AttributionCode: "resource:///modules/AttributionCode.jsm",
|
||||
AddonRepository: "resource://gre/modules/addons/AddonRepository.jsm",
|
||||
AttributionCode: "resource:///modules/AttributionCode.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
ShellService: "resource:///modules/ShellService.jsm",
|
||||
});
|
||||
|
||||
const DEFAULT_WELCOME_CONTENT = {
|
||||
|
@ -209,8 +210,9 @@ const DEFAULT_PROTON_WELCOME_CONTENT = {
|
|||
subtitle: {
|
||||
string_id: "mr1-welcome-screen-hero-text",
|
||||
},
|
||||
// This is dynamically removed for non-en locales below.
|
||||
help_text: {
|
||||
text: "Sam Moqadam - Metal drummer, Firefox fan",
|
||||
text: "Photograph by Sam Moqadam via Unsplash",
|
||||
},
|
||||
primary_button: {
|
||||
label: {
|
||||
|
@ -218,7 +220,7 @@ const DEFAULT_PROTON_WELCOME_CONTENT = {
|
|||
},
|
||||
action: {
|
||||
navigate: true,
|
||||
type: "SET_DEFAULT_BROWSER",
|
||||
type: "PIN_AND_DEFAULT",
|
||||
},
|
||||
},
|
||||
secondary_button: {
|
||||
|
@ -361,19 +363,6 @@ const DEFAULT_PROTON_WELCOME_CONTENT = {
|
|||
],
|
||||
};
|
||||
|
||||
// Helper function to determine if Windows platform supports
|
||||
// automated pinning to taskbar.
|
||||
// See https://searchfox.org/mozilla-central/rev/002023eb262be9db3479142355e1675645d52d52/browser/components/shell/nsIWindowsShellService.idl#17
|
||||
function canPinCurrentAppToTaskbar() {
|
||||
try {
|
||||
ShellService.QueryInterface(
|
||||
Ci.nsIWindowsShellService
|
||||
).checkPinCurrentAppToTaskbar();
|
||||
return true;
|
||||
} catch (e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function getAddonFromRepository(data) {
|
||||
const [addonInfo] = await AddonRepository.getAddonsByIDs([data]);
|
||||
if (addonInfo.sourceURI.scheme !== "https") {
|
||||
|
@ -444,9 +433,23 @@ async function getAttributionContent() {
|
|||
const RULES = [
|
||||
{
|
||||
description: "Proton Default AW content",
|
||||
getDefaults(featureConfig) {
|
||||
async getDefaults(featureConfig) {
|
||||
if (featureConfig?.isProton) {
|
||||
return { ...DEFAULT_PROTON_WELCOME_CONTENT };
|
||||
const content = { ...DEFAULT_PROTON_WELCOME_CONTENT };
|
||||
|
||||
// Switch to "primary" if we also need to pin.
|
||||
if (await ShellService.doesAppNeedPin()) {
|
||||
content.screens[0].content.primary_button.label.string_id =
|
||||
"mr1-onboarding-set-default-pin-primary-button-label";
|
||||
content.screens[0].id = "AW_PIN_AND_DEFAULT";
|
||||
}
|
||||
|
||||
// Remove the English-only image caption.
|
||||
if (Services.locale.appLocaleAsBCP47.split("-")[0] !== "en") {
|
||||
delete content.screens[0].content.help_text;
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -454,8 +457,8 @@ const RULES = [
|
|||
},
|
||||
{
|
||||
description: "Windows pin to task bar screen",
|
||||
getDefaults() {
|
||||
if (canPinCurrentAppToTaskbar()) {
|
||||
async getDefaults() {
|
||||
if (await ShellService.doesAppNeedPin()) {
|
||||
return {
|
||||
template: "multistage",
|
||||
screens: [
|
||||
|
@ -521,9 +524,9 @@ const RULES = [
|
|||
},
|
||||
];
|
||||
|
||||
function getDefaults(featureConfig) {
|
||||
async function getDefaults(featureConfig) {
|
||||
for (const rule of RULES) {
|
||||
const result = rule.getDefaults(featureConfig);
|
||||
const result = await rule.getDefaults(featureConfig);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
import { AboutWelcomeDefaults } from "aboutwelcome/lib/AboutWelcomeDefaults.jsm";
|
||||
import { MultiStageProtonScreen } from "content-src/aboutwelcome/components/MultiStageProtonScreen";
|
||||
import React from "react";
|
||||
import { mount } from "enzyme";
|
||||
|
||||
describe("MultiStageAboutWelcomeProton module", () => {
|
||||
let sandbox;
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox();
|
||||
});
|
||||
afterEach(() => sandbox.restore());
|
||||
|
||||
describe("MultiStageAWProton component", () => {
|
||||
it("should render MultiStageProton Screen", () => {
|
||||
const SCREEN_PROPS = {
|
||||
|
@ -29,4 +36,40 @@ describe("MultiStageAboutWelcomeProton module", () => {
|
|||
assert.equal(wrapper.find(".section-left h1").text(), "test subtitle");
|
||||
});
|
||||
});
|
||||
|
||||
describe("AboutWelcomeDefaults for proton", () => {
|
||||
const getData = () => AboutWelcomeDefaults.getDefaults({ isProton: true });
|
||||
it("should have 'default' button by default", async () => {
|
||||
const data = await getData();
|
||||
|
||||
assert.propertyVal(
|
||||
data.screens[0].content.primary_button.label,
|
||||
"string_id",
|
||||
"mr1-onboarding-set-default-only-primary-button-label"
|
||||
);
|
||||
});
|
||||
it("should have 'primary' button if we need to pin", async () => {
|
||||
sandbox.stub(global.ShellService, "doesAppNeedPin").resolves(true);
|
||||
|
||||
const data = await getData();
|
||||
|
||||
assert.propertyVal(
|
||||
data.screens[0].content.primary_button.label,
|
||||
"string_id",
|
||||
"mr1-onboarding-set-default-pin-primary-button-label"
|
||||
);
|
||||
});
|
||||
it("should keep caption for en-*", async () => {
|
||||
const data = await getData();
|
||||
|
||||
assert.property(data.screens[0].content, "help_text");
|
||||
});
|
||||
it("should remove caption for not-en", async () => {
|
||||
sandbox.stub(global.Services.locale, "appLocaleAsBCP47").value("de");
|
||||
|
||||
const data = await getData();
|
||||
|
||||
assert.notProperty(data.screens[0].content, "help_text");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,11 +10,9 @@ import { MultiStageProtonScreen } from "content-src/aboutwelcome/components/Mult
|
|||
import { Themes } from "content-src/aboutwelcome/components/Themes";
|
||||
import React from "react";
|
||||
import { shallow, mount } from "enzyme";
|
||||
import { AboutWelcomeDefaults } from "aboutwelcome/lib/AboutWelcomeDefaults.jsm";
|
||||
import { DEFAULT_WELCOME_CONTENT } from "aboutwelcome/lib/AboutWelcomeDefaults.jsm";
|
||||
import { AboutWelcomeUtils } from "content-src/lib/aboutwelcome-utils";
|
||||
|
||||
const DEFAULT_WELCOME_CONTENT = AboutWelcomeDefaults.getDefaults();
|
||||
|
||||
describe("MultiStageAboutWelcome module", () => {
|
||||
let globals;
|
||||
let sandbox;
|
||||
|
|
|
@ -433,7 +433,10 @@ const TEST_GLOBAL = {
|
|||
},
|
||||
},
|
||||
EventEmitter,
|
||||
ShellService: { isDefaultBrowser: () => true },
|
||||
ShellService: {
|
||||
doesAppNeedPin: () => false,
|
||||
isDefaultBrowser: () => true,
|
||||
},
|
||||
FilterExpressions: {
|
||||
eval() {
|
||||
return Promise.resolve(false);
|
||||
|
|
Загрузка…
Ссылка в новой задаче