3 Services
.prefs
.setBoolPref("dom.manifest.enabled", true);
5 const { ManifestIcons
} = ChromeUtils
.importESModule(
6 "resource://gre/modules/ManifestIcons.sys.mjs"
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({
21 src
: "red-50.png?Content-type=image/png",
25 src
: "blue-150.png?Content-type=image/png",
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
));
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"));
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");