Bug 1918529 - fix some subpixel misalignment issues with gfx.webrender.svg-filter...
[gecko.git] / dom / manifest / test / browser_ManifestIcons_browserFetchIcon.js
blobe56e1e25c285930725ec5554438b0e8bb7161e20
1 "use strict";
3 Services.prefs.setBoolPref("dom.manifest.enabled", true);
5 const { ManifestIcons } = ChromeUtils.importESModule(
6 "resource://gre/modules/ManifestIcons.sys.mjs"
7 );
8 const { ManifestObtainer } = ChromeUtils.importESModule(
9 "resource://gre/modules/ManifestObtainer.sys.mjs"
12 const defaultURL = new URL(
13 "https://example.org/browser/dom/manifest/test/resource.sjs"
15 defaultURL.searchParams.set("Content-Type", "application/manifest+json");
17 const manifestMock = JSON.stringify({
18 icons: [
20 sizes: "50x50",
21 src: "red-50.png?Content-type=image/png",
24 sizes: "150x150",
25 src: "blue-150.png?Content-type=image/png",
28 });
30 function makeTestURL() {
31 const url = new URL(defaultURL);
32 const body = `<link rel="manifest" href='${defaultURL}&body=${manifestMock}'>`;
33 url.searchParams.set("Content-Type", "text/html; charset=utf-8");
34 url.searchParams.set("body", encodeURIComponent(body));
35 return url.href;
38 function getIconColor(icon) {
39 return new Promise((resolve, reject) => {
40 const canvas = content.document.createElement("canvas");
41 const ctx = canvas.getContext("2d");
42 const image = new content.Image();
43 image.onload = function () {
44 ctx.drawImage(image, 0, 0);
45 resolve(ctx.getImageData(1, 1, 1, 1).data);
47 image.onerror = function () {
48 reject(new Error("could not create image"));
50 image.src = icon;
51 });
54 add_task(async function () {
55 const tabOptions = { gBrowser, url: makeTestURL() };
56 await BrowserTestUtils.withNewTab(tabOptions, async function (browser) {
57 const manifest = await ManifestObtainer.browserObtainManifest(browser);
58 let icon = await ManifestIcons.browserFetchIcon(browser, manifest, 25);
59 let color = await SpecialPowers.spawn(browser, [icon], getIconColor);
60 is(color[0], 255, "Fetched red icon");
62 icon = await ManifestIcons.browserFetchIcon(browser, manifest, 500);
63 color = await SpecialPowers.spawn(browser, [icon], getIconColor);
64 is(color[2], 255, "Fetched blue icon");
65 });
66 });