Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions special-pages/pages/new-tab/app/components/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ body[data-animate-background="true"] {
transition: background-color .3s;
}

body[data-rebrand="true"] {
/* NTP rebrand styles go here. */
}

:global(.layout-centered) {
margin-inline: auto;
width: 100%;
Expand Down
4 changes: 3 additions & 1 deletion special-pages/pages/new-tab/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export async function init(root, messaging, telemetry, baseEnvironment) {
.withPlatformName(init.platform?.name)
.withPlatformName(baseEnvironment.urlParams.get('platform'))
.withFeatureState('customizerDrawer', init.settings?.customizerDrawer)
.withFeatureState('adBlocking', init.settings?.adBlocking);
.withFeatureState('adBlocking', init.settings?.adBlocking)
.withFeatureState('newTabPageRebranding', init.settings?.newTabPageRebranding);

if (!window.__playwright_01) {
console.log('environment:', environment);
Expand Down Expand Up @@ -175,6 +176,7 @@ function installGlobalSideEffects(environment, settings) {
document.body.dataset.platformName = settings.platform.name;
document.body.dataset.display = environment.display;
document.body.dataset.animation = environment.urlParams.get('animation') || '';
document.body.dataset.rebrand = settings.newTabPageRebranding.state === 'enabled' ? 'true' : 'false';
}

/**
Expand Down
4 changes: 4 additions & 0 deletions special-pages/pages/new-tab/app/mock-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ export function initialSetup(url) {
settings.adBlocking = { state: 'enabled' };
}

if (url.searchParams.get('rebrand') === 'enabled') {
settings.newTabPageRebranding = { state: 'enabled' };
}

if (url.searchParams.has('tabs')) {
initial.tabs = { tabId: '01', tabIds: ['01'] };
}
Expand Down
5 changes: 4 additions & 1 deletion special-pages/pages/new-tab/app/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ export class Settings {
* @param {{name: 'macos' | 'windows'}} [params.platform]
* @param {{state: 'enabled' | 'disabled', autoOpen: boolean}} [params.customizerDrawer]
* @param {{state: 'enabled' | 'disabled'}} [params.adBlocking]
* @param {{state: 'enabled' | 'disabled'}} [params.newTabPageRebranding]
*/
constructor({
platform = { name: detectPlatform() },
customizerDrawer = { state: 'enabled', autoOpen: false },
adBlocking = { state: 'disabled' },
newTabPageRebranding = { state: 'disabled' },
}) {
this.platform = platform;
this.customizerDrawer = customizerDrawer;
this.adBlocking = adBlocking;
this.newTabPageRebranding = newTabPageRebranding;
}

withPlatformName(name) {
Expand All @@ -43,7 +46,7 @@ export class Settings {
withFeatureState(named, settings) {
if (!settings) return this;
/** @type {(keyof import("../types/new-tab.js").NewTabPageSettings)[]} */
const valid = ['customizerDrawer', 'adBlocking'];
const valid = ['customizerDrawer', 'adBlocking', 'newTabPageRebranding'];
if (!valid.includes(named)) {
console.warn(`Excluding invalid feature key ${named}`);
return this;
Expand Down
8 changes: 8 additions & 0 deletions special-pages/pages/new-tab/app/settings.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ export function useAdBlocking() {
const settings = useContext(SettingsContext).settings;
return settings.adBlocking.state === 'enabled';
}

/**
* @returns {boolean}
*/
export function useNewTabPageRebranding() {
const settings = useContext(SettingsContext).settings;
return settings.newTabPageRebranding.state === 'enabled';
}
14 changes: 14 additions & 0 deletions special-pages/pages/new-tab/integration-tests/new-tab.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ test.describe('newtab widgets', () => {
},
});
});
test('defaults rebrand data attribute to false', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();

await expect(page.locator('body')).toHaveAttribute('data-rebrand', 'false');
});
test('sets rebrand data attribute from mock url param', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage({ additional: { rebrand: 'enabled' } });

await expect(page.locator('body')).toHaveAttribute('data-rebrand', 'true');
});
test.describe('default background colors', () => {
test('default background light', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
Expand Down
10 changes: 10 additions & 0 deletions special-pages/pages/new-tab/messages/types/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
"enum": ["enabled", "disabled"]
}
}
},
"newTabPageRebranding": {
"type": "object",
"required": ["state"],
"properties": {
"state": {
"type": "string",
"enum": ["enabled", "disabled"]
}
}
}
}
}
8 changes: 8 additions & 0 deletions special-pages/pages/new-tab/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@
- `true` - Opens customizer automatically
- `false` - Does not open customizer automatically

### New Tab Page Rebrand
- **Purpose**: Controls the New Tab Page rebrand feature flag in the mock transport (sets `body[data-rebrand]`)
- **Parameter**: `rebrand`
- **Example**: `?rebrand=enabled`
- **Options**:
- `enabled` - Turns on New Tab Page rebranding
- `disabled` - Turns off New Tab Page rebranding (default)

### RMF (Remote Messaging Framework)
- **Purpose**: Controls Remote Messaging Framework dialog
- **Parameter**: `rmf`
Expand Down
3 changes: 3 additions & 0 deletions special-pages/pages/new-tab/types/new-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,9 @@ export interface NewTabPageSettings {
adBlocking?: {
state: "enabled" | "disabled";
};
newTabPageRebranding?: {
state: "enabled" | "disabled";
};
}
export interface CustomizerData {
background: BackgroundVariant;
Expand Down
Loading