From 059b22b97661d17f190236677d9ddc01db8da60f Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Mon, 8 Nov 2021 15:37:45 +0000 Subject: [PATCH] Bug 1739501 - Add test for fullViewport switch for PageThumbs capture methods. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D130496 --- .../components/thumbnails/test/browser.ini | 1 + .../test/browser_thumbnails_fullViewport.js | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 toolkit/components/thumbnails/test/browser_thumbnails_fullViewport.js diff --git a/toolkit/components/thumbnails/test/browser.ini b/toolkit/components/thumbnails/test/browser.ini index 12623a722815..5763576cd5b7 100644 --- a/toolkit/components/thumbnails/test/browser.ini +++ b/toolkit/components/thumbnails/test/browser.ini @@ -41,6 +41,7 @@ skip-if = (verify && debug && (os == 'linux')) [browser_thumbnails_capture_parent_process.js] skip-if = true # bug 1314039 # Bug 1345418 [browser_thumbnails_expiration.js] +[browser_thumbnails_fullViewport.js] [browser_thumbnails_privacy.js] [browser_thumbnails_redirect.js] [browser_thumbnails_storage.js] diff --git a/toolkit/components/thumbnails/test/browser_thumbnails_fullViewport.js b/toolkit/components/thumbnails/test/browser_thumbnails_fullViewport.js new file mode 100644 index 000000000000..92533bdd3d1a --- /dev/null +++ b/toolkit/components/thumbnails/test/browser_thumbnails_fullViewport.js @@ -0,0 +1,74 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const BUILDER_URL = "https://example.com/document-builder.sjs?html="; +const PAGE_MARKUP = ` + + + + + +
+ + +`; +const PAGE_URL = BUILDER_URL + encodeURI(PAGE_MARKUP); + +/** + * These tests ensure that it's possible to capture the full viewport of + * a browser, and not just the top region. + */ +add_task(async function thumbnails_fullViewport_capture() { + // Create a tab with a green background. + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: PAGE_URL, + }, + async browser => { + let canvas = PageThumbs.createCanvas(window); + await PageThumbs.captureToCanvas(browser, canvas, { + fullViewport: true, + }); + + // The red region isn't scrolled in yet, so we should get + // a green thumbnail. + let ctx = canvas.getContext("2d"); + let [r, g, b] = ctx.getImageData(0, 0, 1, 1).data; + Assert.equal(r, 0, "No red channel"); + Assert.equal(g, 255, "Full green channel"); + Assert.equal(b, 0, "No blue channel"); + + // Now scroll the red region into view. + await SpecialPowers.spawn(browser, [], () => { + let redblock = content.document.getElementById("bigredblock"); + redblock.scrollIntoView(true); + }); + + await PageThumbs.captureToCanvas(browser, canvas, { + fullViewport: true, + }); + + // The captured region should be red. + ctx = canvas.getContext("2d"); + [r, g, b] = ctx.getImageData(0, 0, 1, 1).data; + Assert.equal(r, 255, "Full red channel"); + Assert.equal(g, 0, "No green channel"); + Assert.equal(b, 0, "No blue channel"); + } + ); +});