From 80ed4070339e4f0b1bd66ab9e0e0ed289e5d3195 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Sat, 10 Oct 2020 21:50:37 -0700 Subject: [PATCH] test: add a failing test for the issue 4038 (#4111) Chromium corrupts screenshots taller than 8192. --- test/page-screenshot.spec.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/page-screenshot.spec.ts b/test/page-screenshot.spec.ts index 851e23087d..bc024235a3 100644 --- a/test/page-screenshot.spec.ts +++ b/test/page-screenshot.spec.ts @@ -19,6 +19,7 @@ import { it, expect, describe } from './fixtures'; import { verifyViewport } from './utils'; import path from 'path'; import fs from 'fs'; +import { PNG } from 'pngjs'; // Firefox headful produces a different image. @@ -290,4 +291,35 @@ describe('page screenshot', (suite, { browserName, headful }) => { const error = await page.screenshot({ path: 'file.txt' }).catch(e => e); expect(error.message).toContain('path: unsupported mime type "text/plain"'); }); + + it('should work with large size', (test, { browserName }) => { + test.fail(browserName === 'chromium', 'Upstream Chromium bug'); + }, async ({ page }) => { + await page.setViewportSize({ width: 1280, height: 800 }); + await page.evaluate(() => { + document.body.style.margin = '0'; + document.body.style.padding = '0'; + document.documentElement.style.margin = '0'; + document.documentElement.style.padding = '0'; + const div = document.createElement('div'); + div.style.width = '1250px'; + div.style.height = '8440px'; + div.style.background = 'linear-gradient(red, blue)'; + document.body.appendChild(div); + }); + const buffer = await page.screenshot({ fullPage: true }); + const decoded = PNG.sync.read(buffer); + + const pixel = (x: number, y: number) => { + const dst = new PNG({ width: 1, height: 1 }); + PNG.bitblt(decoded, dst, x, y, 1, 1); + const pixels = dst.data; + return { r: pixels[0], g: pixels[1], b: pixels[2], a: pixels[3] }; + }; + + expect(pixel(0, 0).r).toBeGreaterThan(128); + expect(pixel(0, 0).b).toBeLessThan(128); + expect(pixel(0, 8339).r).toBeLessThan(128); + expect(pixel(0, 8339).b).toBeGreaterThan(128); + }); });