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
= "https://example.com/browser/" + RELATIVE_DIR
;
6 const pdfUrl
= TESTROOT
+ "file_pdfjs_test.pdf";
7 const toolbarDensityPref
= "browser.uidensity";
9 // Test that changing the toolbar density pref is dispatched in pdf.js.
10 add_task(async
function test() {
11 const mimeService
= Cc
["@mozilla.org/mime;1"].getService(Ci
.nsIMIMEService
);
12 const handlerInfo
= mimeService
.getFromTypeAndExtension(
17 // Make sure pdf.js is the default handler.
19 handlerInfo
.alwaysAskBeforeHandling
,
21 "pdf handler defaults to always-ask is false"
24 handlerInfo
.preferredAction
,
25 Ci
.nsIHandlerInfo
.handleInternally
,
26 "pdf handler defaults to internal"
29 info("Pref action: " + handlerInfo
.preferredAction
);
31 await BrowserTestUtils
.withNewTab(
32 { gBrowser
, url
: "about:blank" },
33 async
function test_updated_preferences(browser
) {
34 await
waitForPdfJS(browser
, pdfUrl
);
42 listenForUpdate
: true,
48 // pdfBugEnabled is immutable.
50 listenForUpdate
: false,
54 for (const pref
of Object
.keys(prefs
)) {
55 Services
.prefs
.clearUserPref(`pdfjs.${pref}`);
61 { type
, initialValue
, listenForUpdate
},
62 ] of Object
.entries(prefs
)) {
64 Services
.prefs
[`get${type}Pref`](`pdfjs.${pref}`),
66 `pdfjs.${pref} should be ${initialValue}`
68 if (listenForUpdate
) {
70 BrowserTestUtils
.waitForContentEvent(
81 await SpecialPowers
.spawn(browser
, [prefs
], async prfs
=> {
82 const viewer
= content
.wrappedJSObject
.PDFViewerApplication
;
83 for (const [pref
, { newValue
}] of Object
.entries(prfs
)) {
84 await viewer
.preferences
.set(pref
, newValue
);
88 await Promise
.all(promises
);
90 for (const [pref
, { type
, expectedValue
}] of Object
.entries(prefs
)) {
92 Services
.prefs
[`get${type}Pref`](`pdfjs.${pref}`),
94 `pdfjs.${pref} should be ${expectedValue}`
98 for (const pref
of Object
.keys(prefs
)) {
99 Services
.prefs
.clearUserPref(`pdfjs.${pref}`);
102 await
waitForPdfJSClose(browser
);