Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(screencast): add auto scale test #3733

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions test/assets/checkerboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<html>
<script>
function changeBackground() {
const color = location.hash.substr(1);
document.body.style.backgroundColor = color;
}
</script>
<style>
body {
margin: 0;
}

.container {
display: grid;
background-color: rgb(0, 0, 0);
grid-template-columns: auto auto;
width: 100%;
height: 100%;
}

.cell {
border: none;
font-size: 30px;
text-align: center;
}

.cell.grey {
background-color: rgb(100, 100, 100);
}

.cell.red {
background-color: rgb(255, 0, 0);
}
</style>
<body>
<div class="container">
<div class="cell red"></div>
<div class="cell grey"></div>
<div class="cell grey"></div>
<div class="cell red"></div>
</div>
</body>
</html>
7 changes: 5 additions & 2 deletions test/assets/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
return count;
}

async function seekLastFrame() {
const frameCount = await countFrames();
async function seekLastFrame(isWPE) {
let frameCount = await countFrames();
// TODO: figure out why playing last frame in WPE resets the picture.
if (isWPE && frameCount > 1)
--frameCount;
await playNFrames(frameCount);
return frameCount;
}
Expand Down
46 changes: 45 additions & 1 deletion test/screencast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class VideoPlayer {
}

async seekLastFrame() {
return await this._page.evaluate(async () => await (window as any).seekLastFrame());
const isWPE = LINUX && options.WEBKIT && options.HEADLESS;
return await this._page.evaluate(async x => await (window as any).seekLastFrame(x), isWPE);
}

async pixels(point = {x: 0, y: 0}) {
Expand Down Expand Up @@ -312,4 +313,47 @@ describe('screencast', suite => {
expect(path.dirname(await screencast.path())).toBe(tmpDir);
await context.close();
});

it('should scale frames down to the requested size ', test => {
test.fixme(options.CHROMIUM && options.HEADLESS, 'Window is not resized when changing viewport');
}, async ({page, videoPlayer, tmpDir, server, toImpl}) => {
// Set size to 1/2 of the viewport.
await page.setViewportSize({width: 640, height: 480});
const videoFile = path.join(tmpDir, 'v.webm');
await page.goto(server.PREFIX + '/checkerboard.html');
await toImpl(page)._delegate.startScreencast({outputFile: videoFile, width: 320, height: 240});
// Update the picture to ensure enough frames are generated.
await page.$eval('.container', container => {
container.firstElementChild.classList.remove('red');
});
await new Promise(r => setTimeout(r, 300));
await page.$eval('.container', container => {
container.firstElementChild.classList.add('red');
});
await new Promise(r => setTimeout(r, 300));
await toImpl(page)._delegate.stopScreencast();
expect(fs.existsSync(videoFile)).toBe(true);

await videoPlayer.load(videoFile);
const duration = await videoPlayer.duration();
expect(duration).toBeGreaterThan(0);

await videoPlayer.seekLastFrame();
{
const pixels = await videoPlayer.pixels({x: 0, y: 0});
expectAll(pixels, almostRed);
}
{
const pixels = await videoPlayer.pixels({x: 300, y: 0});
expectAll(pixels, almostGrey);
}
{
const pixels = await videoPlayer.pixels({x: 0, y: 200});
expectAll(pixels, almostGrey);
}
{
const pixels = await videoPlayer.pixels({x: 300, y: 200});
expectAll(pixels, almostRed);
}
});
});