Skip to content

Commit 39300a7

Browse files
committed
ntp: support default background colors
1 parent 847694d commit 39300a7

19 files changed

+222
-9
lines changed

special-pages/pages/new-tab/app/components/BackgroundProvider.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ export function BackgroundConsumer({ browser }) {
8080
}
8181
if (background.kind === 'userImage') {
8282
const isDark = background.value.colorScheme === 'dark';
83-
nextBodyBackground = isDark ? 'var(--default-dark-bg)' : 'var(--default-light-bg)';
83+
nextBodyBackground = isDark ? 'var(--default-dark-background-color)' : 'var(--default-light-background-color)';
8484
}
8585
if (background.kind === 'default') {
86-
nextBodyBackground = browser.value === 'dark' ? 'var(--default-dark-bg)' : 'var(--default-light-bg)';
86+
nextBodyBackground =
87+
browser.value === 'dark' ? 'var(--default-dark-background-color)' : 'var(--default-light-background-color)';
8788
}
8889

8990
document.body.style.setProperty('background-color', nextBodyBackground);

special-pages/pages/new-tab/app/favorites/components/Favorites.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function useVisibleRows(rows, rowHeight, safeAreaRef, expansion) {
317317
}, [rows.length]);
318318

319319
useEffect(() => {
320-
if (!contentTubeRef.current) return console.warn('cannot find content tube');
320+
if (!contentTubeRef.current) return;
321321
let lastHeight;
322322
let debounceTimer;
323323
const resizer = new ResizeObserver((entries) => {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export async function init(root, messaging, telemetry, baseEnvironment) {
7676

7777
// install global side effects that are not specific to any widget
7878
installGlobalSideEffects(environment, settings);
79+
applyDefaultStyles(init.defaultStyles);
7980

8081
// return early if we're in the 'components' view.
8182
if (environment.display === 'components') {
@@ -162,6 +163,20 @@ function installGlobalSideEffects(environment, settings) {
162163
document.body.dataset.animation = environment.urlParams.get('animation') || '';
163164
}
164165

166+
/**
167+
* This will apply default background colors as early as possible.
168+
*
169+
* @param {import("../types/new-tab.ts").DefaultStyles | null | undefined} defaultStyles
170+
*/
171+
function applyDefaultStyles(defaultStyles) {
172+
if (defaultStyles?.lightBackgroundColor) {
173+
document.body.style.setProperty('--default-light-background-color', defaultStyles.lightBackgroundColor);
174+
}
175+
if (defaultStyles?.darkBackgroundColor) {
176+
document.body.style.setProperty('--default-dark-background-color', defaultStyles.darkBackgroundColor);
177+
}
178+
}
179+
165180
/**
166181
*
167182
* @param {import('../types/new-tab.js').InitialSetupResponse['widgets']} widgets

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ export function mockTransport() {
503503
env: 'development',
504504
locale: 'en',
505505
updateNotification,
506+
defaultStyles: getDefaultStyles(),
506507
};
507508

508509
const feed = url.searchParams.get('feed') || 'stats';
@@ -539,6 +540,20 @@ export function mockTransport() {
539540
});
540541
}
541542

543+
/**
544+
* @returns {import("../types/new-tab.js").DefaultStyles | null}
545+
*/
546+
function getDefaultStyles() {
547+
if (url.searchParams.get('defaultStyles') === 'visual-refresh') {
548+
// https://app.asana.com/0/1201141132935289/1209349703167198/f
549+
return {
550+
lightBackgroundColor: '#E9EBEC',
551+
darkBackgroundColor: '#27282A',
552+
};
553+
}
554+
return null;
555+
}
556+
542557
/**
543558
* @template {{id: string}} T
544559
* @param {T[]} array

special-pages/pages/new-tab/app/styles/ntp-theme.css

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
:root {
2-
--default-light-bg: var(--color-gray-0);
3-
--default-dark-bg: var(--color-gray-85);
42
--ntp-gap: 2rem;
53
--ntp-drawer-width: calc(224 * var(--px-in-rem));
64
--ntp-drawer-scroll-width: 12px;
@@ -39,8 +37,13 @@
3937
--focus-ring-thin: 0px 0px 0px 1px var(--ntp-focus-outline-color), 0px 0px 0px 1px var(--color-white);
4038
}
4139

40+
body {
41+
--default-light-background-color: var(--color-gray-0);
42+
--default-dark-background-color: var(--color-gray-85);
43+
}
44+
45+
4246
[data-theme=light] {
43-
--ntp-background-color: var(--default-light-bg);
4447
--ntp-surface-background-color: var(--color-white-at-30);
4548
--ntp-surfaces-panel-background-color: white;
4649
--ntp-surface-border-color: var(--color-black-at-9);
@@ -55,7 +58,6 @@
5558
}
5659

5760
[data-theme=dark] {
58-
--ntp-background-color: var(--default-dark-bg);
5961
--ntp-surface-background-color: var(--color-black-at-18);
6062
--ntp-surfaces-panel-background-color: #222222;
6163
--ntp-surface-border-color: var(--color-white-at-12);
@@ -66,7 +68,7 @@
6668
--ntp-focus-outline-color: white;
6769
--focus-ring: 0px 0px 0px 1px var(--ntp-focus-outline-color), 0px 0px 0px 3px var(--color-white);
6870
--focus-ring-thin: 0px 0px 0px 1px var(--color-white), 0px 0px 0px 1px var(--ntp-focus-outline-color);
69-
--focus-ring-primary: 0px 0px 0px 1px var(--default-dark-bg), 0px 0px 0px 3px var(--ntp-color-primary);
71+
--focus-ring-primary: 0px 0px 0px 1px var(--default-dark-background-color), 0px 0px 0px 3px var(--ntp-color-primary);
7072
}
7173

7274
/* This comes from the application settings */

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Mocks } from '../../../shared/mocks.js';
22
import { perPlatform } from 'injected/integration-test/type-helpers.mjs';
3+
import { expect } from '@playwright/test';
34

45
/**
56
* @typedef {import('injected/integration-test/type-helpers.mjs').Build} Build
@@ -150,4 +151,21 @@ export class NewtabPage {
150151
async darkMode() {
151152
await this.page.emulateMedia({ colorScheme: 'dark' });
152153
}
154+
155+
async waitForCustomizer() {
156+
await this.page.getByRole('button', { name: 'Customize' }).waitFor();
157+
}
158+
159+
/**
160+
* @param {object} params
161+
* @param {string} params.hex
162+
* @returns {Promise<void>}
163+
*/
164+
async hasBackgroundColor({ hex }) {
165+
const r = parseInt(hex.slice(1, 3), 16);
166+
const g = parseInt(hex.slice(3, 5), 16);
167+
const b = parseInt(hex.slice(5, 7), 16);
168+
const rgb = `rgb(${[r, g, b].join(', ')})`;
169+
await expect(this.page.locator('body')).toHaveCSS('background-color', rgb, { timeout: 50 });
170+
}
153171
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { expect, test } from '@playwright/test';
2+
import { NewtabPage } from './new-tab.page.js';
3+
import { ActivityPage } from '../app/activity/integration-tests/activity.page.js';
4+
import { CustomizerPage } from '../app/customizer/integration-tests/customizer.page.js';
5+
import { PrivacyStatsPage } from '../app/privacy-stats/integration-tests/privacy-stats.page.js';
6+
7+
const maxDiffPixels = 20;
8+
9+
test.describe('NTP screenshots', () => {
10+
test.describe('feed = privacy stats', () => {
11+
test.use({ viewport: { width: 1000, height: 600 } });
12+
test('with dataset "few"', async ({ page }, workerInfo) => {
13+
const ntp = NewtabPage.create(page, workerInfo);
14+
const stats = new PrivacyStatsPage(page, ntp);
15+
await ntp.reducedMotion();
16+
17+
// see privacy-stats.mocks.js
18+
await ntp.openPage({ additional: { stats: 'few' } });
19+
20+
// make sure we're screenshotting when data is showing
21+
await stats.hasRows(4);
22+
await expect(page).toHaveScreenshot('stats-few.png', { maxDiffPixels });
23+
});
24+
});
25+
26+
test.describe('activity widget screenshots narrow', () => {
27+
test.use({ viewport: { width: 800, height: 800 } });
28+
test('default', async ({ page }, workerInfo) => {
29+
const ntp = NewtabPage.create(page, workerInfo);
30+
const ap = new ActivityPage(page, ntp);
31+
await ntp.reducedMotion();
32+
await ntp.openPage({ additional: { feed: 'activity' } });
33+
await ap.didRender();
34+
await expect(page).toHaveScreenshot('narrow-default.png', { maxDiffPixels });
35+
});
36+
test('empty', async ({ page }, workerInfo) => {
37+
const ntp = NewtabPage.create(page, workerInfo);
38+
const ap = new ActivityPage(page, ntp);
39+
await ntp.reducedMotion();
40+
await ntp.openPage({ additional: { feed: 'activity', activity: 'empty' } });
41+
await ap.didRender();
42+
await expect(page).toHaveScreenshot('narrow-empty.png', { maxDiffPixels });
43+
});
44+
});
45+
46+
test.describe('activity widget screenshots wide', () => {
47+
test.use({ viewport: { width: 1000, height: 800 } });
48+
test('default', async ({ page }, workerInfo) => {
49+
const ntp = NewtabPage.create(page, workerInfo);
50+
const ap = new ActivityPage(page, ntp);
51+
await ntp.reducedMotion();
52+
await ntp.openPage({ additional: { feed: 'activity' } });
53+
await ap.didRender();
54+
await expect(page).toHaveScreenshot('wide-default.png', { maxDiffPixels });
55+
});
56+
test('empty', async ({ page }, workerInfo) => {
57+
const ntp = NewtabPage.create(page, workerInfo);
58+
const ap = new ActivityPage(page, ntp);
59+
await ntp.reducedMotion();
60+
await ntp.openPage({ additional: { feed: 'activity', activity: 'empty' } });
61+
await ap.didRender();
62+
await expect(page).toHaveScreenshot('wide-empty.png', { maxDiffPixels });
63+
});
64+
test('with drawer', async ({ page }, workerInfo) => {
65+
const ntp = NewtabPage.create(page, workerInfo);
66+
const ap = new ActivityPage(page, ntp);
67+
const customizer = new CustomizerPage(ntp);
68+
await ntp.reducedMotion();
69+
await ntp.openPage({ additional: { feed: 'activity', customizerDrawer: 'enabled' } });
70+
await ap.didRender();
71+
await customizer.opensCustomizer();
72+
await expect(page).toHaveScreenshot('wide-default-drawer.png', { maxDiffPixels });
73+
});
74+
});
75+
});
66 KB
Loading
25.9 KB
Loading
35.5 KB
Loading

0 commit comments

Comments
 (0)