blob: d16fddade77d122d400c8981cc785c77c8575487 [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';
8import {describe, it} from '../../shared/mocha-extensions.js';
9import {
10 clickStartButton,
11 getAuditsBreakdown,
12 navigateToLighthouseTab,
13 setLegacyNavigation,
14 setThrottlingMethod,
15 waitForResult,
16} from '../helpers/lighthouse-helpers.js';
17
18// This test will fail (by default) in headful mode, as the target page never gets painted.
19// To resolve this when debugging, just make sure the target page is visible during the lighthouse run.
20
Adam Rainecd6d4492022-07-27 12:01:36 -070021describe('Navigation', async function() {
Adam Raineb1ac4232022-07-21 12:13:29 -070022 // The tests in this suite are particularly slow
23 this.timeout(60_000);
24
25 const modes = ['legacy', 'FR'];
26
27 for (const mode of modes) {
28 describe(`in ${mode} mode`, () => {
29 beforeEach(() => {
30 if (mode === 'FR') {
31 // TODO: Figure out why these are emitted in FR.
32 expectError(/Protocol Error: the message with wrong session id/);
33 expectError(/Protocol Error: the message with wrong session id/);
34 }
35 });
36
37 it('successfully returns a Lighthouse report', async () => {
38 await navigateToLighthouseTab('lighthouse/hello.html');
39
40 await setLegacyNavigation(mode === 'legacy');
41 await clickStartButton();
42
43 const {lhr, artifacts, reportEl} = await waitForResult();
44
45 assert.strictEqual(lhr.lighthouseVersion, '9.6.2');
46 assert.match(lhr.finalUrl, /^https:\/\/localhost:[0-9]+\/test\/e2e\/resources\/lighthouse\/hello.html/);
47 assert.strictEqual(lhr.configSettings.throttlingMethod, 'simulate');
48
49 const {innerWidth, innerHeight, outerWidth, outerHeight, devicePixelRatio} = artifacts.ViewportDimensions;
50 // This value can vary slightly, depending on the display.
51 assert.approximately(innerHeight, 1742, 1);
52 assert.strictEqual(innerWidth, 980);
53 assert.strictEqual(outerWidth, 360);
54 assert.strictEqual(outerHeight, 640);
55 assert.strictEqual(devicePixelRatio, 3);
56
57 const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr);
58 assert.strictEqual(auditResults.length, 152);
59 assert.strictEqual(erroredAudits.length, 0);
60 assert.deepStrictEqual(failedAudits.map(audit => audit.id), [
61 'service-worker',
62 'viewport',
63 'installable-manifest',
64 'apple-touch-icon',
65 'splash-screen',
66 'themed-omnibox',
67 'maskable-icon',
68 'content-width',
69 'document-title',
70 'html-has-lang',
71 'meta-description',
72 'font-size',
73 'tap-targets',
74 ]);
75
76 const viewTraceText = await reportEl.$eval('.lh-button--trace', viewTraceEl => {
77 return viewTraceEl.textContent;
78 });
79 assert.strictEqual(viewTraceText, 'View Original Trace');
80 });
81
82 it('successfully returns a Lighthouse report with DevTools throttling', async () => {
83 await navigateToLighthouseTab('lighthouse/hello.html');
84
85 await setThrottlingMethod('devtools');
86 await setLegacyNavigation(mode === 'legacy');
87 await clickStartButton();
88
89 const {lhr, reportEl} = await waitForResult();
90
91 assert.strictEqual(lhr.configSettings.throttlingMethod, 'devtools');
92
Adam Rainecd6d4492022-07-27 12:01:36 -070093 // [crbug.com/1347220] DevTools throttling can force resources to load slow enough for these audits to fail sometimes.
94 const flakyAudits = [
95 'server-response-time',
96 'render-blocking-resources',
97 ];
98
99 const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr, flakyAudits);
Adam Raineb1ac4232022-07-21 12:13:29 -0700100 assert.strictEqual(auditResults.length, 152);
101 assert.strictEqual(erroredAudits.length, 0);
102 assert.deepStrictEqual(failedAudits.map(audit => audit.id), [
103 'service-worker',
104 'viewport',
105 'installable-manifest',
106 'apple-touch-icon',
107 'splash-screen',
108 'themed-omnibox',
109 'maskable-icon',
110 'content-width',
111 'document-title',
112 'html-has-lang',
113 'meta-description',
114 'font-size',
115 'tap-targets',
116 ]);
117
118 const viewTraceText = await reportEl.$eval('.lh-button--trace', viewTraceEl => {
119 return viewTraceEl.textContent;
120 });
121 assert.strictEqual(viewTraceText, 'View Trace');
122 });
123 });
124 }
125});