Backed out changeset f594e6f00208 (bug 1940883) for causing crashes in bug 1941164.
[gecko.git] / toolkit / components / pdfjs / test / browser_pdfjs_views.js
blob6155f6959c0c4ad78287408fd3ae0e105d50e802
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;
7 add_task(async function test() {
8   let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
9   let handlerInfo = mimeService.getFromTypeAndExtension(
10     "application/pdf",
11     "pdf"
12   );
14   // Make sure pdf.js is the default handler.
15   is(
16     handlerInfo.alwaysAskBeforeHandling,
17     false,
18     "pdf handler defaults to always-ask is false"
19   );
20   is(
21     handlerInfo.preferredAction,
22     Ci.nsIHandlerInfo.handleInternally,
23     "pdf handler defaults to internal"
24   );
26   info("Pref action: " + handlerInfo.preferredAction);
28   await BrowserTestUtils.withNewTab(
29     { gBrowser, url: "about:blank" },
30     async function (browser) {
31       // check that PDF is opened with internal viewer
32       await waitForPdfJS(browser, TESTROOT + "file_pdfjs_test.pdf");
34       await SpecialPowers.spawn(browser, [], async function () {
35         Assert.ok(
36           content.document.querySelector("div#viewer"),
37           "document content has viewer UI"
38         );
40         // open sidebar
41         var sidebar = content.document.querySelector("#sidebarToggleButton");
42         var outerContainer =
43           content.document.querySelector("div#outerContainer");
45         sidebar.click();
46         Assert.ok(
47           outerContainer.classList.contains("sidebarOpen"),
48           "sidebar opens on click"
49         );
51         // check that thumbnail view is open
52         var thumbnailView = content.document.querySelector("div#thumbnailView");
53         var outlineView = content.document.querySelector("div#outlineView");
55         Assert.equal(
56           thumbnailView.getAttribute("class"),
57           null,
58           "Initial view is thumbnail view"
59         );
60         Assert.equal(
61           outlineView.getAttribute("class"),
62           "hidden",
63           "Outline view is hidden initially"
64         );
66         // switch to outline view
67         var viewOutlineButton =
68           content.document.querySelector("button#viewOutline");
69         viewOutlineButton.click();
71         Assert.equal(
72           thumbnailView.getAttribute("class"),
73           "hidden",
74           "Thumbnail view is hidden when outline is selected"
75         );
76         Assert.equal(
77           outlineView.getAttribute("class"),
78           "",
79           "Outline view is visible when selected"
80         );
82         // switch back to thumbnail view
83         var viewThumbnailButton = content.document.querySelector(
84           "button#viewThumbnail"
85         );
86         viewThumbnailButton.click();
88         Assert.equal(
89           thumbnailView.getAttribute("class"),
90           "",
91           "Thumbnail view is visible when selected"
92         );
93         Assert.equal(
94           outlineView.getAttribute("class"),
95           "hidden",
96           "Outline view is hidden when thumbnail is selected"
97         );
99         sidebar.click();
100       });
102       await waitForPdfJSClose(browser);
103     }
104   );