Skip to content

Commit

Permalink
Update review changes (Math.round + leaving width: 0)
Browse files Browse the repository at this point in the history
Apply scaling to output + overflow smoke tests.
  • Loading branch information
alexnj committed Mar 27, 2023
1 parent 514b647 commit 5b71aa9
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 18 deletions.
12 changes: 12 additions & 0 deletions cli/test/fixtures/scaled-overflow-content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=0.5">
<title>Document</title>
</head>
<body style="overflow: scroll;">
<h1>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</h1>
</body>
</html>
2 changes: 2 additions & 0 deletions cli/test/smokehouse/core-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -80,6 +81,7 @@ const smokeTests = [
formsAutoComplete,
fpsMax,
fpsScaled,
fpsOverflowX,
fpsMaxPassive,
issuesMixedContent,
lanternFetch,
Expand Down
61 changes: 61 additions & 0 deletions cli/test/smokehouse/test-definitions/fps-overflow-x.js
Original file line number Diff line number Diff line change
@@ -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,
};

4 changes: 2 additions & 2 deletions cli/test/smokehouse/test-definitions/fps-scaled.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const expectations = {
],
},
screenshot: {
height: 2000,
width: 824,
height: 1000,
width: 412,
},
},
},
Expand Down
23 changes: 11 additions & 12 deletions core/gather/gatherers/full-page-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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),
};
}

Expand Down Expand Up @@ -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
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/test/gather/gatherers/full-page-screenshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('FullPageScreenshot gatherer', () => {
mobile: true,
deviceScaleFactor: 1,
height: 1500,
width: 500,
width: 0,
})
);

Expand All @@ -158,15 +158,15 @@ describe('FullPageScreenshot gatherer', () => {
mobile: true,
deviceScaleFactor: 2,
height: 500,
width: 500,
width: 0,
})
);
});

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,
Expand All @@ -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,
}
);
Expand Down

0 comments on commit 5b71aa9

Please sign in to comment.