-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathnew-tab.spec.js
More file actions
302 lines (268 loc) · 12.1 KB
/
Copy pathnew-tab.spec.js
File metadata and controls
302 lines (268 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import { expect, test } from '@playwright/test';
import { NewtabPage } from './new-tab.page.js';
import { CustomizerPage } from '../app/customizer/integration-tests/customizer.page.js';
test.describe('newtab widgets', () => {
test('widget config single click', async ({ page }, workerInfo) => {
await page.clock.install();
const ntp = NewtabPage.create(page, workerInfo);
const cp = new CustomizerPage(ntp);
await ntp.reducedMotion();
await ntp.openPage();
await cp.opensCustomizer();
// hide
await page.getByRole('switch', { name: 'Toggle Protections Report' }).uncheck();
// debounced
await page.clock.fastForward(501);
// verify the single sync call, where one is hidden
const outgoing = await ntp.mocks.outgoing({ names: ['widgets_setConfig'] });
expect(outgoing).toStrictEqual([
{
payload: {
context: 'specialPages',
featureName: 'newTabPage',
params: [
{ id: 'omnibar', visibility: 'visible' },
{ id: 'favorites', visibility: 'visible' },
{ id: 'protections', visibility: 'hidden' },
],
method: 'widgets_setConfig',
},
},
]);
});
test.skip('widget config double click', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
// menu
await page.getByRole('button', { name: 'Customize' }).click();
// hide
await page.locator('label').filter({ hasText: 'Blocked Tracking Attempts' }).uncheck();
// show
await page.locator('label').filter({ hasText: 'Blocked Tracking Attempts' }).check();
// debounced
await page.waitForTimeout(500);
// verify the single sync call, where both are visible.
const outgoing = await ntp.mocks.outgoing({ names: ['widgets_setConfig'] });
expect(outgoing).toStrictEqual([
{
payload: {
context: 'specialPages',
featureName: 'newTabPage',
params: [
{ id: 'omnibar', visibility: 'visible' },
{ id: 'favorites', visibility: 'visible' },
{ id: 'protections', visibility: 'visible' },
],
method: 'widgets_setConfig',
},
},
]);
});
test('context menu', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
// wait for the menu, as a signal that the JS is ready
await page.getByRole('button', { name: 'Customize' }).waitFor();
await page.locator('body').click({ button: 'right' });
const calls = await ntp.mocks.waitForCallCount({ method: 'contextMenu', count: 1 });
expect(calls[0].payload).toStrictEqual({
context: 'specialPages',
featureName: 'newTabPage',
method: 'contextMenu',
params: {
visibilityMenuItems: [
{
id: 'omnibar',
title: 'Search',
},
{
id: 'favorites',
title: 'Favorites',
},
{
id: 'protections',
title: 'Protections Report',
},
],
},
});
});
test.describe('default background colors', () => {
test('default background light', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
await ntp.waitForCustomizer();
await ntp.hasBackgroundColor({ hex: '#fafafa' });
});
test('default background dark', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.darkMode();
await ntp.openPage();
await ntp.waitForCustomizer();
await ntp.hasBackgroundColor({ hex: '#1c1c1c' });
});
test('with overrides from initial setup (light)', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage({ additional: { defaultStyles: 'visual-refresh' } });
await ntp.waitForCustomizer();
await page.pause();
await ntp.hasBackgroundColor({ hex: '#E9EBEC' });
});
test('with overrides from initial setup (dark)', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.darkMode();
await ntp.openPage({ additional: { defaultStyles: 'visual-refresh' } });
await ntp.waitForCustomizer();
await ntp.hasBackgroundColor({ hex: '#27282A' });
});
test('with pushed updated theme value (light)', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
const cp = new CustomizerPage(ntp);
await ntp.reducedMotion();
await ntp.openPage({});
await ntp.waitForCustomizer();
await cp.acceptsThemeUpdateWithDefaults('light', { darkBackgroundColor: '#000000', lightBackgroundColor: '#ffffff' });
await ntp.hasBackgroundColor({ hex: '#ffffff' });
});
test('with pushed updated theme value (dark)', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
const cp = new CustomizerPage(ntp);
await ntp.reducedMotion();
await ntp.darkMode();
await ntp.openPage({});
await ntp.waitForCustomizer();
await cp.acceptsThemeUpdateWithDefaults('dark', { darkBackgroundColor: '#000000', lightBackgroundColor: '#ffffff' });
await ntp.hasBackgroundColor({ hex: '#000000' });
});
});
test.describe('global error listeners', () => {
test('reports uncaught errors via reportInitException', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
await ntp.waitForCustomizer();
await page.evaluate(() => {
setTimeout(() => {
throw new Error('test uncaught error');
}, 0);
});
const calls = await ntp.mocks.waitForCallCount({ method: 'reportInitException', count: 1 });
expect(calls).toMatchObject([
{
payload: {
context: 'specialPages',
featureName: 'newTabPage',
method: 'reportInitException',
params: { message: '[uncaught] test uncaught error' },
},
},
]);
});
test('reports unhandled rejections via reportInitException', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
await ntp.waitForCustomizer();
await page.evaluate(() => {
Promise.reject(new Error('test unhandled rejection'));
});
const calls = await ntp.mocks.waitForCallCount({ method: 'reportInitException', count: 1 });
expect(calls).toMatchObject([
{
payload: {
context: 'specialPages',
featureName: 'newTabPage',
method: 'reportInitException',
params: { message: '[unhandledrejection] test unhandled rejection' },
},
},
]);
});
test('does not fire reportInitException during normal page load', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
await ntp.waitForCustomizer();
const calls = await ntp.mocks.outgoing({ names: ['reportInitException'] });
expect(calls).toHaveLength(0);
});
test('falls back to ErrorEvent.message when event.error is null', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
await ntp.waitForCustomizer();
await page.evaluate(() => {
window.dispatchEvent(new ErrorEvent('error', { message: 'Script error.', error: null }));
});
const calls = await ntp.mocks.waitForCallCount({ method: 'reportInitException', count: 1 });
expect(calls).toMatchObject([
{
payload: {
params: { message: '[uncaught] Script error.' },
},
},
]);
});
test("falls back to 'unknown error' when ErrorEvent has neither error nor message", async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
await ntp.waitForCustomizer();
await page.evaluate(() => {
window.dispatchEvent(new ErrorEvent('error', { error: null }));
});
const calls = await ntp.mocks.waitForCallCount({ method: 'reportInitException', count: 1 });
expect(calls).toMatchObject([
{
payload: {
params: { message: '[uncaught] unknown error' },
},
},
]);
});
test('stringifies a thrown non-Error value', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
await ntp.waitForCustomizer();
await page.evaluate(() => {
setTimeout(() => {
// eslint-disable-next-line no-throw-literal -- intentional: a non-Error throw surfaces via event.error
throw 'raw string';
}, 0);
});
const calls = await ntp.mocks.waitForCallCount({ method: 'reportInitException', count: 1 });
expect(calls).toMatchObject([
{
payload: {
params: { message: '[uncaught] raw string' },
},
},
]);
});
test('reports primitive and nullish rejection reasons distinctly', async ({ page }, workerInfo) => {
const ntp = NewtabPage.create(page, workerInfo);
await ntp.reducedMotion();
await ntp.openPage();
await ntp.waitForCustomizer();
await page.evaluate(() => {
/* eslint-disable prefer-promise-reject-errors -- intentional: testing non-Error rejection reasons */
setTimeout(() => Promise.reject(undefined), 0);
setTimeout(() => Promise.reject(null), 0);
setTimeout(() => Promise.reject(0), 0);
/* eslint-enable prefer-promise-reject-errors */
});
const calls = await ntp.mocks.waitForCallCount({ method: 'reportInitException', count: 3 });
const messages = calls.map((c) => c.payload.params.message);
expect(messages).toEqual(
expect.arrayContaining(['[unhandledrejection] undefined', '[unhandledrejection] null', '[unhandledrejection] 0']),
);
});
});
});