blob: 2bda1f3fec7dfe48b9e34036be2e1ae92eed427f [file] [log] [blame]
Adam Raineb1ac4232022-07-21 12:13:29 -07001// Copyright 2022 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {assert} from 'chai';
6
7import {expectError} from '../../conductor/events.js';
Adam Raine2fcf01b2022-10-04 15:17:38 -07008import {setDevToolsSettings, waitFor} from '../../shared/helper.js';
Adam Raineb1ac4232022-07-21 12:13:29 -07009import {describe, it} from '../../shared/mocha-extensions.js';
10import {
11 clickStartButton,
12 getAuditsBreakdown,
13 navigateToLighthouseTab,
Adam Rainea708e012022-08-10 09:58:23 -070014 selectCategories,
Adam Rainebf8654c2022-09-13 13:24:07 -070015 selectDevice,
Adam Raineb1ac4232022-07-21 12:13:29 -070016 setLegacyNavigation,
17 setThrottlingMethod,
Adam Raineda3fa692022-09-06 17:47:28 -070018 setToolbarCheckboxWithText,
Adam Raineb1ac4232022-07-21 12:13:29 -070019 waitForResult,
20} from '../helpers/lighthouse-helpers.js';
21
22// This test will fail (by default) in headful mode, as the target page never gets painted.
23// To resolve this when debugging, just make sure the target page is visible during the lighthouse run.
24
Adam Rainecd6d4492022-07-27 12:01:36 -070025describe('Navigation', async function() {
Adam Raineb1ac4232022-07-21 12:13:29 -070026 // The tests in this suite are particularly slow
27 this.timeout(60_000);
28
29 const modes = ['legacy', 'FR'];
30
31 for (const mode of modes) {
32 describe(`in ${mode} mode`, () => {
33 beforeEach(() => {
34 if (mode === 'FR') {
Adam Rainebf8654c2022-09-13 13:24:07 -070035 // https://bugs.chromium.org/p/chromium/issues/detail?id=1357791
Adam Raineb1ac4232022-07-21 12:13:29 -070036 expectError(/Protocol Error: the message with wrong session id/);
37 expectError(/Protocol Error: the message with wrong session id/);
Adam Raine38be4592022-08-16 16:38:20 -070038 expectError(/Protocol Error: the message with wrong session id/);
39 expectError(/Protocol Error: the message with wrong session id/);
40 expectError(/Protocol Error: the message with wrong session id/);
Adam Raineb1ac4232022-07-21 12:13:29 -070041 }
42 });
43
44 it('successfully returns a Lighthouse report', async () => {
45 await navigateToLighthouseTab('lighthouse/hello.html');
46
47 await setLegacyNavigation(mode === 'legacy');
Adam Raine7179cf52022-09-29 13:09:37 -070048 await selectCategories([
49 'performance',
50 'accessibility',
51 'best-practices',
52 'seo',
53 'pwa',
54 'lighthouse-plugin-publisher-ads',
55 ]);
Adam Rainea708e012022-08-10 09:58:23 -070056
Adam Raineb1ac4232022-07-21 12:13:29 -070057 await clickStartButton();
58
59 const {lhr, artifacts, reportEl} = await waitForResult();
60
Adam Raine38be4592022-08-16 16:38:20 -070061 assert.strictEqual(lhr.lighthouseVersion, '9.6.6');
Adam Raineb1ac4232022-07-21 12:13:29 -070062 assert.match(lhr.finalUrl, /^https:\/\/localhost:[0-9]+\/test\/e2e\/resources\/lighthouse\/hello.html/);
Adam Raine4515db62022-09-28 16:37:20 -070063
Adam Raineb1ac4232022-07-21 12:13:29 -070064 assert.strictEqual(lhr.configSettings.throttlingMethod, 'simulate');
Adam Rainea708e012022-08-10 09:58:23 -070065 assert.strictEqual(lhr.configSettings.disableStorageReset, false);
66 assert.strictEqual(lhr.configSettings.formFactor, 'mobile');
Adam Raine4515db62022-09-28 16:37:20 -070067 assert.strictEqual(lhr.configSettings.throttling.rttMs, 150);
68 assert.strictEqual(lhr.configSettings.screenEmulation.disabled, true);
69 assert.include(lhr.configSettings.emulatedUserAgent, 'Mobile');
Adam Raineb1ac4232022-07-21 12:13:29 -070070
Adam Raine4515db62022-09-28 16:37:20 -070071 // A bug in FR caused `networkUserAgent` to be excluded from the LHR.
72 // https://github.com/GoogleChrome/lighthouse/pull/14392
73 // TODO: Reenable once the fix lands in DT.
74 if (mode === 'legacy') {
75 assert.include(lhr.environment.networkUserAgent, 'Mobile');
76 }
77
78 assert.deepStrictEqual(artifacts.ViewportDimensions, {
79 innerHeight: 640,
80 innerWidth: 360,
81 outerHeight: 640,
82 outerWidth: 360,
83 devicePixelRatio: 3,
84 });
Adam Raineb1ac4232022-07-21 12:13:29 -070085
86 const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr);
Adam Raine7179cf52022-09-29 13:09:37 -070087 assert.strictEqual(auditResults.length, 175);
Adam Raineb1ac4232022-07-21 12:13:29 -070088 assert.strictEqual(erroredAudits.length, 0);
89 assert.deepStrictEqual(failedAudits.map(audit => audit.id), [
90 'service-worker',
Adam Raineb1ac4232022-07-21 12:13:29 -070091 'installable-manifest',
92 'apple-touch-icon',
93 'splash-screen',
94 'themed-omnibox',
95 'maskable-icon',
Adam Raineb1ac4232022-07-21 12:13:29 -070096 'document-title',
97 'html-has-lang',
98 'meta-description',
Adam Raineb1ac4232022-07-21 12:13:29 -070099 ]);
100
Adam Raine2fcf01b2022-10-04 15:17:38 -0700101 const viewTraceButton = await waitFor('.lh-button--trace', reportEl);
102 const viewTraceText = await viewTraceButton.evaluate(viewTraceEl => {
Adam Raineb1ac4232022-07-21 12:13:29 -0700103 return viewTraceEl.textContent;
104 });
105 assert.strictEqual(viewTraceText, 'View Original Trace');
Adam Raine2fcf01b2022-10-04 15:17:38 -0700106
107 await viewTraceButton.click();
108 const selectedTab = await waitFor('.tabbed-pane-header-tab.selected[aria-label="Performance"]');
109 const selectedTabText = await selectedTab.evaluate(selectedTabEl => {
110 return selectedTabEl.textContent;
111 });
112 assert.strictEqual(selectedTabText, 'Performance');
Adam Raineb1ac4232022-07-21 12:13:29 -0700113 });
114
115 it('successfully returns a Lighthouse report with DevTools throttling', async () => {
116 await navigateToLighthouseTab('lighthouse/hello.html');
117
118 await setThrottlingMethod('devtools');
119 await setLegacyNavigation(mode === 'legacy');
Adam Rainea708e012022-08-10 09:58:23 -0700120
Adam Raineb1ac4232022-07-21 12:13:29 -0700121 await clickStartButton();
122
123 const {lhr, reportEl} = await waitForResult();
124
125 assert.strictEqual(lhr.configSettings.throttlingMethod, 'devtools');
126
Adam Rainecd6d4492022-07-27 12:01:36 -0700127 // [crbug.com/1347220] DevTools throttling can force resources to load slow enough for these audits to fail sometimes.
128 const flakyAudits = [
129 'server-response-time',
130 'render-blocking-resources',
131 ];
132
133 const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr, flakyAudits);
Adam Raineb1ac4232022-07-21 12:13:29 -0700134 assert.strictEqual(auditResults.length, 152);
135 assert.strictEqual(erroredAudits.length, 0);
136 assert.deepStrictEqual(failedAudits.map(audit => audit.id), [
137 'service-worker',
Adam Raineb1ac4232022-07-21 12:13:29 -0700138 'installable-manifest',
139 'apple-touch-icon',
140 'splash-screen',
141 'themed-omnibox',
142 'maskable-icon',
Adam Raineb1ac4232022-07-21 12:13:29 -0700143 'document-title',
144 'html-has-lang',
145 'meta-description',
Adam Raineb1ac4232022-07-21 12:13:29 -0700146 ]);
147
148 const viewTraceText = await reportEl.$eval('.lh-button--trace', viewTraceEl => {
149 return viewTraceEl.textContent;
150 });
151 assert.strictEqual(viewTraceText, 'View Trace');
152 });
Adam Rainea708e012022-08-10 09:58:23 -0700153
154 it('successfully returns a Lighthouse report when settings changed', async () => {
Adam Raineda3fa692022-09-06 17:47:28 -0700155 await setDevToolsSettings({language: 'en-XL'});
Adam Rainea708e012022-08-10 09:58:23 -0700156 await navigateToLighthouseTab('lighthouse/hello.html');
157
Adam Raineda3fa692022-09-06 17:47:28 -0700158 await setToolbarCheckboxWithText(mode === 'legacy', 'L̂éĝáĉý n̂áv̂íĝát̂íôń');
159 await setToolbarCheckboxWithText(false, 'Ĉĺêár̂ śt̂ór̂áĝé');
Adam Rainea708e012022-08-10 09:58:23 -0700160 await selectCategories(['performance', 'best-practices']);
Adam Rainebf8654c2022-09-13 13:24:07 -0700161 await selectDevice('desktop');
Adam Rainea708e012022-08-10 09:58:23 -0700162
163 await clickStartButton();
164
Adam Raineda3fa692022-09-06 17:47:28 -0700165 const {reportEl, lhr, artifacts} = await waitForResult();
Adam Rainea708e012022-08-10 09:58:23 -0700166
167 const {innerWidth, innerHeight, devicePixelRatio} = artifacts.ViewportDimensions;
168 // TODO: Figure out why outerHeight can be different depending on OS
169 assert.strictEqual(innerHeight, 720);
170 assert.strictEqual(innerWidth, 1280);
171 assert.strictEqual(devicePixelRatio, 1);
172
173 const {erroredAudits} = getAuditsBreakdown(lhr);
174 assert.strictEqual(erroredAudits.length, 0);
175
176 assert.deepStrictEqual(Object.keys(lhr.categories), ['performance', 'best-practices']);
177 assert.strictEqual(lhr.configSettings.disableStorageReset, true);
178 assert.strictEqual(lhr.configSettings.formFactor, 'desktop');
Adam Raine4515db62022-09-28 16:37:20 -0700179 assert.strictEqual(lhr.configSettings.throttling.rttMs, 40);
180 assert.strictEqual(lhr.configSettings.screenEmulation.disabled, true);
181 assert.notInclude(lhr.configSettings.emulatedUserAgent, 'Mobile');
182
183 // A bug in FR caused `networkUserAgent` to be excluded from the LHR.
184 // https://github.com/GoogleChrome/lighthouse/pull/14392
185 // TODO: Reenable once the fix lands in DT.
186 if (mode === 'legacy') {
187 assert.notInclude(lhr.environment.networkUserAgent, 'Mobile');
188 }
Adam Raineda3fa692022-09-06 17:47:28 -0700189
190 const viewTraceText = await reportEl.$eval('.lh-button--trace', viewTraceEl => {
191 return viewTraceEl.textContent;
192 });
193 assert.strictEqual(viewTraceText, 'V̂íêẃ Ôŕîǵîńâĺ T̂ŕâćê');
194
195 assert.strictEqual(lhr.i18n.rendererFormattedStrings.footerIssue, 'F̂íl̂é âń îśŝúê');
Adam Rainea708e012022-08-10 09:58:23 -0700196 });
Adam Raineb1ac4232022-07-21 12:13:29 -0700197 });
198 }
199});