Skip to content

Commit 2440ca0

Browse files
committed
Add New Tab rebrand feature flag wiring
1 parent 2443067 commit 2440ca0

8 files changed

Lines changed: 50 additions & 2 deletions

File tree

special-pages/pages/new-tab/app/components/App.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ body[data-animate-background="true"] {
2727
transition: background-color .3s;
2828
}
2929

30+
body[data-rebrand="true"] {
31+
/* NTP rebrand styles go here. */
32+
}
33+
3034
:global(.layout-centered) {
3135
margin-inline: auto;
3236
width: 100%;

special-pages/pages/new-tab/app/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export async function init(root, messaging, telemetry, baseEnvironment) {
6666
.withPlatformName(init.platform?.name)
6767
.withPlatformName(baseEnvironment.urlParams.get('platform'))
6868
.withFeatureState('customizerDrawer', init.settings?.customizerDrawer)
69-
.withFeatureState('adBlocking', init.settings?.adBlocking);
69+
.withFeatureState('adBlocking', init.settings?.adBlocking)
70+
.withFeatureState('ntpRebrand', init.settings?.ntpRebrand);
7071

7172
if (!window.__playwright_01) {
7273
console.log('environment:', environment);
@@ -175,6 +176,7 @@ function installGlobalSideEffects(environment, settings) {
175176
document.body.dataset.platformName = settings.platform.name;
176177
document.body.dataset.display = environment.display;
177178
document.body.dataset.animation = environment.urlParams.get('animation') || '';
179+
document.body.dataset.rebrand = settings.ntpRebrand.state === 'enabled' ? 'true' : 'false';
178180
}
179181

180182
/**

special-pages/pages/new-tab/app/mock-transport.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ export function initialSetup(url) {
614614
settings.adBlocking = { state: 'enabled' };
615615
}
616616

617+
if (url.searchParams.get('rebrand') === 'enabled') {
618+
settings.ntpRebrand = { state: 'enabled' };
619+
}
620+
617621
if (url.searchParams.has('tabs')) {
618622
initial.tabs = { tabId: '01', tabIds: ['01'] };
619623
}

special-pages/pages/new-tab/app/settings.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ export class Settings {
1212
* @param {{name: 'macos' | 'windows'}} [params.platform]
1313
* @param {{state: 'enabled' | 'disabled', autoOpen: boolean}} [params.customizerDrawer]
1414
* @param {{state: 'enabled' | 'disabled'}} [params.adBlocking]
15+
* @param {{state: 'enabled' | 'disabled'}} [params.ntpRebrand]
1516
*/
1617
constructor({
1718
platform = { name: detectPlatform() },
1819
customizerDrawer = { state: 'enabled', autoOpen: false },
1920
adBlocking = { state: 'disabled' },
21+
ntpRebrand = { state: 'disabled' },
2022
}) {
2123
this.platform = platform;
2224
this.customizerDrawer = customizerDrawer;
2325
this.adBlocking = adBlocking;
26+
this.ntpRebrand = ntpRebrand;
2427
}
2528

2629
withPlatformName(name) {
@@ -43,7 +46,7 @@ export class Settings {
4346
withFeatureState(named, settings) {
4447
if (!settings) return this;
4548
/** @type {(keyof import("../types/new-tab.js").NewTabPageSettings)[]} */
46-
const valid = ['customizerDrawer', 'adBlocking'];
49+
const valid = ['customizerDrawer', 'adBlocking', 'ntpRebrand'];
4750
if (!valid.includes(named)) {
4851
console.warn(`Excluding invalid feature key ${named}`);
4952
return this;

special-pages/pages/new-tab/app/settings.provider.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ export function useAdBlocking() {
3535
const settings = useContext(SettingsContext).settings;
3636
return settings.adBlocking.state === 'enabled';
3737
}
38+
39+
/**
40+
* @returns {boolean}
41+
*/
42+
export function useNtpRebrand() {
43+
const settings = useContext(SettingsContext).settings;
44+
return settings.ntpRebrand.state === 'enabled';
45+
}

special-pages/pages/new-tab/integration-tests/new-tab.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ test.describe('newtab widgets', () => {
103103
},
104104
});
105105
});
106+
test('defaults rebrand data attribute to false', async ({ page }, workerInfo) => {
107+
const ntp = NewtabPage.create(page, workerInfo);
108+
await ntp.reducedMotion();
109+
await ntp.openPage();
110+
111+
await expect(page.locator('body')).toHaveAttribute('data-rebrand', 'false');
112+
});
113+
test('sets rebrand data attribute from mock url param', async ({ page }, workerInfo) => {
114+
const ntp = NewtabPage.create(page, workerInfo);
115+
await ntp.reducedMotion();
116+
await ntp.openPage({ additional: { rebrand: 'enabled' } });
117+
118+
await expect(page.locator('body')).toHaveAttribute('data-rebrand', 'true');
119+
});
106120
test.describe('default background colors', () => {
107121
test('default background light', async ({ page }, workerInfo) => {
108122
const ntp = NewtabPage.create(page, workerInfo);

special-pages/pages/new-tab/messages/types/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
"enum": ["enabled", "disabled"]
2727
}
2828
}
29+
},
30+
"ntpRebrand": {
31+
"type": "object",
32+
"required": ["state"],
33+
"properties": {
34+
"state": {
35+
"type": "string",
36+
"enum": ["enabled", "disabled"]
37+
}
38+
}
2939
}
3040
}
3141
}

special-pages/pages/new-tab/types/new-tab.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,9 @@ export interface NewTabPageSettings {
11531153
adBlocking?: {
11541154
state: "enabled" | "disabled";
11551155
};
1156+
ntpRebrand?: {
1157+
state: "enabled" | "disabled";
1158+
};
11561159
}
11571160
export interface CustomizerData {
11581161
background: BackgroundVariant;

0 commit comments

Comments
 (0)