Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 1 | // 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 | |
| 5 | import {assert} from 'chai'; |
| 6 | |
| 7 | import {expectError} from '../../conductor/events.js'; |
Adam Raine | 2fcf01b | 2022-10-04 15:17:38 -0700 | [diff] [blame] | 8 | import {setDevToolsSettings, waitFor} from '../../shared/helper.js'; |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 9 | import {describe, it} from '../../shared/mocha-extensions.js'; |
| 10 | import { |
| 11 | clickStartButton, |
| 12 | getAuditsBreakdown, |
| 13 | navigateToLighthouseTab, |
Adam Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 14 | selectCategories, |
Adam Raine | bf8654c | 2022-09-13 13:24:07 -0700 | [diff] [blame] | 15 | selectDevice, |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 16 | setLegacyNavigation, |
| 17 | setThrottlingMethod, |
Adam Raine | da3fa69 | 2022-09-06 17:47:28 -0700 | [diff] [blame] | 18 | setToolbarCheckboxWithText, |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 19 | 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 Raine | cd6d449 | 2022-07-27 12:01:36 -0700 | [diff] [blame] | 25 | describe('Navigation', async function() { |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 26 | // 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 Raine | bf8654c | 2022-09-13 13:24:07 -0700 | [diff] [blame] | 35 | // https://bugs.chromium.org/p/chromium/issues/detail?id=1357791 |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 36 | expectError(/Protocol Error: the message with wrong session id/); |
| 37 | expectError(/Protocol Error: the message with wrong session id/); |
Adam Raine | 38be459 | 2022-08-16 16:38:20 -0700 | [diff] [blame] | 38 | 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 Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 41 | } |
| 42 | }); |
| 43 | |
| 44 | it('successfully returns a Lighthouse report', async () => { |
| 45 | await navigateToLighthouseTab('lighthouse/hello.html'); |
| 46 | |
| 47 | await setLegacyNavigation(mode === 'legacy'); |
Adam Raine | 7179cf5 | 2022-09-29 13:09:37 -0700 | [diff] [blame] | 48 | await selectCategories([ |
| 49 | 'performance', |
| 50 | 'accessibility', |
| 51 | 'best-practices', |
| 52 | 'seo', |
| 53 | 'pwa', |
| 54 | 'lighthouse-plugin-publisher-ads', |
| 55 | ]); |
Adam Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 56 | |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 57 | await clickStartButton(); |
| 58 | |
| 59 | const {lhr, artifacts, reportEl} = await waitForResult(); |
| 60 | |
Adam Raine | 38be459 | 2022-08-16 16:38:20 -0700 | [diff] [blame] | 61 | assert.strictEqual(lhr.lighthouseVersion, '9.6.6'); |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 62 | assert.match(lhr.finalUrl, /^https:\/\/localhost:[0-9]+\/test\/e2e\/resources\/lighthouse\/hello.html/); |
Adam Raine | 4515db6 | 2022-09-28 16:37:20 -0700 | [diff] [blame] | 63 | |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 64 | assert.strictEqual(lhr.configSettings.throttlingMethod, 'simulate'); |
Adam Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 65 | assert.strictEqual(lhr.configSettings.disableStorageReset, false); |
| 66 | assert.strictEqual(lhr.configSettings.formFactor, 'mobile'); |
Adam Raine | 4515db6 | 2022-09-28 16:37:20 -0700 | [diff] [blame] | 67 | assert.strictEqual(lhr.configSettings.throttling.rttMs, 150); |
| 68 | assert.strictEqual(lhr.configSettings.screenEmulation.disabled, true); |
| 69 | assert.include(lhr.configSettings.emulatedUserAgent, 'Mobile'); |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 70 | |
Adam Raine | 4515db6 | 2022-09-28 16:37:20 -0700 | [diff] [blame] | 71 | // 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 Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 85 | |
| 86 | const {auditResults, erroredAudits, failedAudits} = getAuditsBreakdown(lhr); |
Adam Raine | 7179cf5 | 2022-09-29 13:09:37 -0700 | [diff] [blame] | 87 | assert.strictEqual(auditResults.length, 175); |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 88 | assert.strictEqual(erroredAudits.length, 0); |
| 89 | assert.deepStrictEqual(failedAudits.map(audit => audit.id), [ |
| 90 | 'service-worker', |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 91 | 'installable-manifest', |
| 92 | 'apple-touch-icon', |
| 93 | 'splash-screen', |
| 94 | 'themed-omnibox', |
| 95 | 'maskable-icon', |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 96 | 'document-title', |
| 97 | 'html-has-lang', |
| 98 | 'meta-description', |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 99 | ]); |
| 100 | |
Adam Raine | 2fcf01b | 2022-10-04 15:17:38 -0700 | [diff] [blame] | 101 | const viewTraceButton = await waitFor('.lh-button--trace', reportEl); |
| 102 | const viewTraceText = await viewTraceButton.evaluate(viewTraceEl => { |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 103 | return viewTraceEl.textContent; |
| 104 | }); |
| 105 | assert.strictEqual(viewTraceText, 'View Original Trace'); |
Adam Raine | 2fcf01b | 2022-10-04 15:17:38 -0700 | [diff] [blame] | 106 | |
| 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 Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 113 | }); |
| 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 Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 120 | |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 121 | await clickStartButton(); |
| 122 | |
| 123 | const {lhr, reportEl} = await waitForResult(); |
| 124 | |
| 125 | assert.strictEqual(lhr.configSettings.throttlingMethod, 'devtools'); |
| 126 | |
Adam Raine | cd6d449 | 2022-07-27 12:01:36 -0700 | [diff] [blame] | 127 | // [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 Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 134 | assert.strictEqual(auditResults.length, 152); |
| 135 | assert.strictEqual(erroredAudits.length, 0); |
| 136 | assert.deepStrictEqual(failedAudits.map(audit => audit.id), [ |
| 137 | 'service-worker', |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 138 | 'installable-manifest', |
| 139 | 'apple-touch-icon', |
| 140 | 'splash-screen', |
| 141 | 'themed-omnibox', |
| 142 | 'maskable-icon', |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 143 | 'document-title', |
| 144 | 'html-has-lang', |
| 145 | 'meta-description', |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 146 | ]); |
| 147 | |
| 148 | const viewTraceText = await reportEl.$eval('.lh-button--trace', viewTraceEl => { |
| 149 | return viewTraceEl.textContent; |
| 150 | }); |
| 151 | assert.strictEqual(viewTraceText, 'View Trace'); |
| 152 | }); |
Adam Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 153 | |
| 154 | it('successfully returns a Lighthouse report when settings changed', async () => { |
Adam Raine | da3fa69 | 2022-09-06 17:47:28 -0700 | [diff] [blame] | 155 | await setDevToolsSettings({language: 'en-XL'}); |
Adam Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 156 | await navigateToLighthouseTab('lighthouse/hello.html'); |
| 157 | |
Adam Raine | da3fa69 | 2022-09-06 17:47:28 -0700 | [diff] [blame] | 158 | await setToolbarCheckboxWithText(mode === 'legacy', 'L̂éĝáĉý n̂áv̂íĝát̂íôń'); |
| 159 | await setToolbarCheckboxWithText(false, 'Ĉĺêár̂ śt̂ór̂áĝé'); |
Adam Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 160 | await selectCategories(['performance', 'best-practices']); |
Adam Raine | bf8654c | 2022-09-13 13:24:07 -0700 | [diff] [blame] | 161 | await selectDevice('desktop'); |
Adam Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 162 | |
| 163 | await clickStartButton(); |
| 164 | |
Adam Raine | da3fa69 | 2022-09-06 17:47:28 -0700 | [diff] [blame] | 165 | const {reportEl, lhr, artifacts} = await waitForResult(); |
Adam Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 166 | |
| 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 Raine | 4515db6 | 2022-09-28 16:37:20 -0700 | [diff] [blame] | 179 | 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 Raine | da3fa69 | 2022-09-06 17:47:28 -0700 | [diff] [blame] | 189 | |
| 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 Raine | a708e01 | 2022-08-10 09:58:23 -0700 | [diff] [blame] | 196 | }); |
Adam Raine | b1ac423 | 2022-07-21 12:13:29 -0700 | [diff] [blame] | 197 | }); |
| 198 | } |
| 199 | }); |