Skip to content

Commit

Permalink
Add a test of screenshot with overridden device scale factor
Browse files Browse the repository at this point in the history
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
caseq authored and Chromium LUCI CQ committed Jan 11, 2021
1 parent 6cf2df8 commit daba326
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
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
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();
})
2 changes: 2 additions & 0 deletions headless/test/headless_compositor_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,7 @@ HEADLESS_COMPOSITOR_TEST(RendererOpacityAnimation,
"sanity/renderer-opacity-animation.js")
HEADLESS_COMPOSITOR_TEST(ScreenshotAfterMetricsOverride,
"sanity/screenshot-after-metrics-override.js")
HEADLESS_COMPOSITOR_TEST(ScreenshotDeviceScaleFactor,
"emulation/screenshot-device-scale-factor.js")

} // namespace headless

0 comments on commit daba326

Please sign in to comment.