From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../test/browser_thumbnails_fullViewport.js | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 toolkit/components/thumbnails/test/browser_thumbnails_fullViewport.js (limited to 'toolkit/components/thumbnails/test/browser_thumbnails_fullViewport.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 0000000000..92533bdd3d --- /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"); + } + ); +}); -- cgit v1.2.3