Backed out changeset f594e6f00208 (bug 1940883) for causing crashes in bug 1941164.
[gecko.git] / toolkit / components / pdfjs / test / browser_pdfjs_caret_browsing_mode.js
blobc986b934aa80f7b45bdbfc9e0fdd22b0ef7e2710
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 caretBrowsingModePref = "accessibility.browsewithcaret";
9 // Test telemetry.
10 add_task(async function test() {
11   let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
12   let handlerInfo = mimeService.getFromTypeAndExtension(
13     "application/pdf",
14     "pdf"
15   );
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"
22   );
23   is(
24     handlerInfo.preferredAction,
25     Ci.nsIHandlerInfo.handleInternally,
26     "pdf handler defaults to internal"
27   );
29   info("Pref action: " + handlerInfo.preferredAction);
31   await BrowserTestUtils.withNewTab(
32     { gBrowser, url: "about:blank" },
33     async function test_caret_browsing_mode(browser) {
34       await waitForPdfJS(browser, pdfUrl);
36       let promise = BrowserTestUtils.waitForContentEvent(
37         browser,
38         "updatedPreference",
39         false,
40         null,
41         true
42       );
43       await SpecialPowers.pushPrefEnv({
44         set: [[caretBrowsingModePref, true]],
45       });
46       await promise;
47       await TestUtils.waitForTick();
49       await SpecialPowers.spawn(browser, [], async function () {
50         const viewer = content.wrappedJSObject.PDFViewerApplication;
51         Assert.ok(
52           viewer.supportsCaretBrowsingMode,
53           "Caret browsing mode is supported"
54         );
55       });
57       promise = BrowserTestUtils.waitForContentEvent(
58         browser,
59         "updatedPreference",
60         false,
61         null,
62         true
63       );
64       await SpecialPowers.popPrefEnv();
65       await promise;
66       await TestUtils.waitForTick();
68       await SpecialPowers.spawn(browser, [], async function () {
69         const viewer = content.wrappedJSObject.PDFViewerApplication;
70         Assert.ok(
71           !viewer.supportsCaretBrowsingMode,
72           "Caret browsing mode isn't supported"
73         );
74       });
76       await waitForPdfJSClose(browser);
77     }
78   );
79 });