Bug 1941046 - Part 4: Send a callback request for impression and clicks of MARS Top...
[gecko.git] / toolkit / components / pdfjs / test / browser_pdfjs_update_preferences.js
blob5f940014ab338188f78b572db155e31616e42882
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(
13 "application/pdf",
14 "pdf"
17 // Make sure pdf.js is the default handler.
18 is(
19 handlerInfo.alwaysAskBeforeHandling,
20 false,
21 "pdf handler defaults to always-ask is false"
23 is(
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);
36 const prefs = {
37 enableGuessAltText: {
38 type: "Bool",
39 initialValue: true,
40 newValue: false,
41 expectedValue: false,
42 listenForUpdate: true,
44 pdfBugEnabled: {
45 type: "Bool",
46 initialValue: false,
47 newValue: true,
48 // pdfBugEnabled is immutable.
49 expectedValue: false,
50 listenForUpdate: false,
54 for (const pref of Object.keys(prefs)) {
55 Services.prefs.clearUserPref(`pdfjs.${pref}`);
58 const promises = [];
59 for (const [
60 pref,
61 { type, initialValue, listenForUpdate },
62 ] of Object.entries(prefs)) {
63 Assert.strictEqual(
64 Services.prefs[`get${type}Pref`](`pdfjs.${pref}`),
65 initialValue,
66 `pdfjs.${pref} should be ${initialValue}`
68 if (listenForUpdate) {
69 promises.push(
70 BrowserTestUtils.waitForContentEvent(
71 browser,
72 "updatedPreference",
73 false,
74 null,
75 true
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);
86 });
88 await Promise.all(promises);
90 for (const [pref, { type, expectedValue }] of Object.entries(prefs)) {
91 Assert.strictEqual(
92 Services.prefs[`get${type}Pref`](`pdfjs.${pref}`),
93 expectedValue,
94 `pdfjs.${pref} should be ${expectedValue}`
98 for (const pref of Object.keys(prefs)) {
99 Services.prefs.clearUserPref(`pdfjs.${pref}`);
102 await waitForPdfJSClose(browser);