From 5b71aa93a740fa62cf5c35094e3d987e611c322b Mon Sep 17 00:00:00 2001 From: "Alex N. Jose" Date: Wed, 22 Mar 2023 15:20:56 -0700 Subject: [PATCH] Update review changes (Math.round + leaving width: 0) Apply scaling to output + overflow smoke tests. --- .../fixtures/scaled-overflow-content.html | 12 ++++ cli/test/smokehouse/core-tests.js | 2 + .../test-definitions/fps-overflow-x.js | 61 +++++++++++++++++++ .../smokehouse/test-definitions/fps-scaled.js | 4 +- core/gather/gatherers/full-page-screenshot.js | 23 ++++--- .../gatherers/full-page-screenshot-test.js | 8 +-- 6 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 cli/test/fixtures/scaled-overflow-content.html create mode 100644 cli/test/smokehouse/test-definitions/fps-overflow-x.js diff --git a/cli/test/fixtures/scaled-overflow-content.html b/cli/test/fixtures/scaled-overflow-content.html new file mode 100644 index 000000000000..0717ea64d68d --- /dev/null +++ b/cli/test/fixtures/scaled-overflow-content.html @@ -0,0 +1,12 @@ + + + + + + + Document + + +

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

+ + \ No newline at end of file diff --git a/cli/test/smokehouse/core-tests.js b/cli/test/smokehouse/core-tests.js index 8cbd54e8778d..7b857a9d5333 100644 --- a/cli/test/smokehouse/core-tests.js +++ b/cli/test/smokehouse/core-tests.js @@ -17,6 +17,7 @@ import formsAutoComplete from './test-definitions/forms-autocomplete.js'; import fpsMax from './test-definitions/fps-max.js'; import fpsMaxPassive from './test-definitions/fps-max-passive.js'; import fpsScaled from './test-definitions/fps-scaled.js'; +import fpsOverflowX from './test-definitions/fps-overflow-x.js'; import issuesMixedContent from './test-definitions/issues-mixed-content.js'; import lanternFetch from './test-definitions/lantern-fetch.js'; import lanternIdleCallbackLong from './test-definitions/lantern-idle-callback-long.js'; @@ -80,6 +81,7 @@ const smokeTests = [ formsAutoComplete, fpsMax, fpsScaled, + fpsOverflowX, fpsMaxPassive, issuesMixedContent, lanternFetch, diff --git a/cli/test/smokehouse/test-definitions/fps-overflow-x.js b/cli/test/smokehouse/test-definitions/fps-overflow-x.js new file mode 100644 index 000000000000..b72552ef633f --- /dev/null +++ b/cli/test/smokehouse/test-definitions/fps-overflow-x.js @@ -0,0 +1,61 @@ +/** + * @license Copyright 2023 The Lighthouse Authors. All Rights Reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + */ + +/** @type {LH.Config} */ +const config = { + extends: 'lighthouse:default', + settings: { + onlyCategories: ['performance'], + }, +}; + +/** + * @type {Smokehouse.ExpectedRunnerResult} + */ +const expectations = { + artifacts: { + ViewportDimensions: { + innerWidth: 1325, + innerHeight: 2647, + outerWidth: 412, + outerHeight: 823, + devicePixelRatio: 1.75, + }, + }, + lhr: { + requestedUrl: 'http://localhost:10200/scaled-overflow-content.html', + finalDisplayedUrl: 'http://localhost:10200/scaled-overflow-content.html', + audits: {}, + fullPageScreenshot: { + nodes: { + _includes: [ + [ + /-BODY$/, + { + top: 21, + bottom: 58, + left: 8, + right: 816, + width: 808, + height: 37, + }, + ], + ], + }, + screenshot: { + height: 1324, + width: 412, + }, + }, + }, +}; + +export default { + id: 'fps-overflow-x', + expectations, + config, +}; + diff --git a/cli/test/smokehouse/test-definitions/fps-scaled.js b/cli/test/smokehouse/test-definitions/fps-scaled.js index 5e037e1a4795..3b19cbb84261 100644 --- a/cli/test/smokehouse/test-definitions/fps-scaled.js +++ b/cli/test/smokehouse/test-definitions/fps-scaled.js @@ -46,8 +46,8 @@ const expectations = { ], }, screenshot: { - height: 2000, - width: 824, + height: 1000, + width: 412, }, }, }, diff --git a/core/gather/gatherers/full-page-screenshot.js b/core/gather/gatherers/full-page-screenshot.js index cc19136976f7..88b913ebbdd2 100644 --- a/core/gather/gatherers/full-page-screenshot.js +++ b/core/gather/gatherers/full-page-screenshot.js @@ -68,15 +68,14 @@ class FullPageScreenshot extends FRGatherer { const session = context.driver.defaultSession; const metrics = await session.sendCommand('Page.getLayoutMetrics'); - // To obtain a full page screenshot, we resize the emulated viewport to - // (1) a height equal to the maximum between visual-viewport height and scaled document height. - // (2) a width equal to emulated visual-viewport width (we choose to clip overflow on x-axis). - // Finally, we cap the viewport to the maximum size allowance of WebP format. - const fullHeight = Math.max( + // To obtain a full page screenshot, we resize the emulated viewport height to + // the maximum between visual-viewport height and the scaled document height. + // Final height is capped to the maximum size allowance of WebP format. + // Height needs to be rounded to an integer for Emulation.setDeviceMetricOverrides. + const fullHeight = Math.round(Math.max( deviceMetrics.height, metrics.cssContentSize.height * metrics.cssVisualViewport.scale - ); + )); const height = Math.min(fullHeight, MAX_WEBP_SIZE); - const width = Math.min(deviceMetrics.width, MAX_WEBP_SIZE); // Setup network monitor before we change the viewport. const networkMonitor = new NetworkMonitor(context.driver.targetManager); @@ -93,7 +92,7 @@ class FullPageScreenshot extends FRGatherer { mobile: deviceMetrics.mobile, deviceScaleFactor: 1, height, - width, + width: 0, // Leave width unchanged }); // Now that the viewport is taller, give the page some time to fetch new resources that @@ -123,9 +122,9 @@ class FullPageScreenshot extends FRGatherer { return { data, // Since we resized emulated viewport to match the desired screenshot size, - // it is safe to rely on visual viewport css dimensions. - width: metrics.cssVisualViewport.clientWidth, - height: metrics.cssVisualViewport.clientHeight, + // it is safe to rely on scaled visual viewport css dimensions. + width: Math.round(metrics.cssVisualViewport.clientWidth * metrics.cssVisualViewport.scale), + height: Math.round(metrics.cssVisualViewport.clientHeight * metrics.cssVisualViewport.scale), }; } @@ -233,7 +232,7 @@ class FullPageScreenshot extends FRGatherer { mobile: deviceMetrics.mobile, deviceScaleFactor: deviceMetrics.deviceScaleFactor, height: deviceMetrics.height, - width: deviceMetrics.width, + width: 0, // Leave width unchanged }); } } diff --git a/core/test/gather/gatherers/full-page-screenshot-test.js b/core/test/gather/gatherers/full-page-screenshot-test.js index a50efcc646b0..8ce9cffbd800 100644 --- a/core/test/gather/gatherers/full-page-screenshot-test.js +++ b/core/test/gather/gatherers/full-page-screenshot-test.js @@ -147,7 +147,7 @@ describe('FullPageScreenshot gatherer', () => { mobile: true, deviceScaleFactor: 1, height: 1500, - width: 500, + width: 0, }) ); @@ -158,7 +158,7 @@ describe('FullPageScreenshot gatherer', () => { mobile: true, deviceScaleFactor: 2, height: 500, - width: 500, + width: 0, }) ); }); @@ -166,7 +166,7 @@ describe('FullPageScreenshot gatherer', () => { it('limits the screenshot height to the max Chrome can capture', async () => { const fpsGatherer = new FullPageScreenshotGatherer(); - contentSize = {width: 100000, height: 100000}; + contentSize = {width: 412, height: 100000}; screenSize = {width: 412, height: 412, dpr: 1}; mockContext.settings = { ...mockContext.settings, @@ -186,7 +186,7 @@ describe('FullPageScreenshot gatherer', () => { { mobile: true, deviceScaleFactor: 1, - width: 412, // Horizontal overflow will be clipped to screen size. + width: 0, height: 16383, } );