1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 const RELATIVE_DIR = "toolkit/components/pdfjs/test/";
5 const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR;
8 * Get the first and last pixels on the drawn canvas.
9 * @param {Object} browser
12 async function getFirstLastPixels(browser) {
13 return SpecialPowers.spawn(browser, [], async function () {
14 const { document } = content;
15 const canvas = document.querySelector("canvas");
17 Assert.ok(!!canvas, "We must have a canvas");
19 const data = Array.from(
20 canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height)
25 first: data.slice(0, 3),
26 last: data.slice(-4, -1),
32 * Test that the pdf has the correct color depending on the high contrast mode.
34 add_task(async function test() {
35 let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
36 let handlerInfo = mimeService.getFromTypeAndExtension(
41 // Make sure pdf.js is the default handler.
43 handlerInfo.alwaysAskBeforeHandling,
45 "pdf handler defaults to always-ask is false"
48 handlerInfo.preferredAction,
49 Ci.nsIHandlerInfo.handleInternally,
50 "pdf handler defaults to internal"
53 info("Pref action: " + handlerInfo.preferredAction);
55 await SpecialPowers.pushPrefEnv({
57 ["browser.display.document_color_use", 0],
58 ["browser.display.background_color", "#ff0000"],
59 ["browser.display.foreground_color", "#00ff00"],
60 ["browser.display.use_system_colors", false],
64 await BrowserTestUtils.withNewTab(
65 { gBrowser, url: "about:blank" },
66 async function (browser) {
67 // check that PDF is opened with internal viewer
68 await waitForPdfJSCanvas(
70 `${TESTROOT}file_pdfjs_hcm.pdf#zoom=800`
73 const { first, last } = await getFirstLastPixels(browser);
74 // The first pixel must be black and not green.
75 Assert.deepEqual(first, [0, 0, 0]);
77 // The last pixel must be white and not red.
78 Assert.deepEqual(last, [255, 255, 255]);
80 await waitForPdfJSClose(browser);
85 await SpecialPowers.pushPrefEnv({
86 set: [["ui.useAccessibilityTheme", 1]],
89 await BrowserTestUtils.withNewTab(
90 { gBrowser, url: "about:blank" },
91 async function (browser) {
92 // check that PDF is opened with internal viewer
93 await waitForPdfJSCanvas(
95 `${TESTROOT}file_pdfjs_hcm.pdf#zoom=800`
98 const { first, last } = await getFirstLastPixels(browser);
99 // The first pixel must be green.
100 Assert.deepEqual(first, [0, 255, 0]);
102 // The last pixel must be red.
103 Assert.deepEqual(last, [255, 0, 0]);
105 await waitForPdfJSClose(browser);
109 await SpecialPowers.popPrefEnv();