forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test of screenshot with overridden device scale factor
This is a regression test for issue 1164610. Bug: 1164610 Change-Id: I1671fadf581778ddd2d90c310c1574a91ecdd967 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2621962 Commit-Queue: Andrey Kosyakov <caseq@chromium.org> Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org> Cr-Commit-Position: refs/heads/master@{#842201}
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
headless/test/data/protocol/emulation/screenshot-device-scale-factor-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Tests screenshot with overridden device scale factor | ||
requested url: http://example.com/ | ||
Screenshot size: 200 x 200 | ||
rgba @(175,175) 0,0,255,255 |
58 changes: 58 additions & 0 deletions
58
headless/test/data/protocol/emulation/screenshot-device-scale-factor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
(async function(testRunner) { | ||
const {page, session, dp} = await testRunner.startWithFrameControl( | ||
'Tests screenshot with overridden device scale factor'); | ||
|
||
await dp.Runtime.enable(); | ||
await dp.HeadlessExperimental.enable(); | ||
|
||
dp.Emulation.enable(); | ||
await dp.Emulation.setDeviceMetricsOverride({ | ||
deviceScaleFactor: 2, | ||
width: 100, | ||
height: 100, | ||
screenHeight: 100, | ||
screenWidth: 100, | ||
mobile: true, | ||
viewport: {x: 0, y: 0, width: 100, height: 100, scale: 1} | ||
}); | ||
|
||
const RendererTestHelper = | ||
await testRunner.loadScript('../helpers/renderer-test-helper.js'); | ||
const {httpInterceptor, frameNavigationHelper, virtualTimeController} = | ||
await (new RendererTestHelper(testRunner, dp, page)).init(); | ||
|
||
httpInterceptor.addResponse(`http://example.com/`, | ||
`<!doctype html> | ||
<html> | ||
<meta name=viewport content="width=device-width"> | ||
<style> | ||
html, body { width: 100%; height: 100%; margin:0; padding:0; } | ||
div { | ||
width: 100%; height: 100%; margin:0; padding:0; | ||
background-size: 100% 100%; | ||
background-color: blue; | ||
} | ||
</style> | ||
<body> | ||
<div></div> | ||
</body> | ||
</html> | ||
`); | ||
|
||
let ctx = await new Promise(async fulfill => { | ||
await virtualTimeController.grantInitialTime(500, 100, | ||
null, | ||
async () => fulfill(await virtualTimeController.captureScreenshot()) | ||
); | ||
frameNavigationHelper.navigate('http://example.com/'); | ||
}); | ||
// We use a screen and viewport of 100x100 DIP, which is 200 physical pixels | ||
// due to deviceScaleFactor of 2. Make sure the screenshot is not clipped. | ||
let rgba = ctx.getImageData(175, 175, 1, 1).data; | ||
testRunner.log(`rgba @(175,175) ${rgba}`); | ||
testRunner.completeTest(); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters