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;
8 add_task(async function test() {
9 let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
10 let handlerInfo = mimeService.getFromTypeAndExtension(
15 // Make sure pdf.js is the default handler.
17 handlerInfo.alwaysAskBeforeHandling,
19 "pdf handler defaults to always-ask is false"
22 handlerInfo.preferredAction,
23 Ci.nsIHandlerInfo.handleInternally,
24 "pdf handler defaults to internal"
27 info("Pref action: " + handlerInfo.preferredAction);
29 await BrowserTestUtils.withNewTab(
30 { gBrowser, url: "about:blank" },
31 async function (browser) {
32 await SpecialPowers.pushPrefEnv({
34 ["pdfjs.annotationEditorMode", 0],
35 ["pdfjs.enableHighlight", true],
39 Services.fog.testResetFOG();
41 // check that PDF is opened with internal viewer
42 await waitForPdfJSAllLayers(browser, TESTROOT + "file_pdfjs_test.pdf", [
44 "annotationEditorLayer",
49 ["annotationEditorLayer", "textLayer", "canvasWrapper"],
52 await Services.fog.testFlushAllChildren();
54 (Glean.pdfjsEditingHighlight.kind.freeHighlight.testGetValue() || 0) +
55 (Glean.pdfjsEditingHighlight.kind.highlight.testGetValue() || 0),
57 "Should have no highlight"
60 await enableEditor(browser, "Highlight", 1);
61 const strs = ["In production", "buildbot automation"];
62 for (let i = 0; i < strs.length; i++) {
65 const spanBox = await getSpanBox(browser, str);
68 spanBox.x + 0.75 * spanBox.width,
69 spanBox.y + 0.5 * spanBox.height,
72 await waitForEditors(browser, ".highlightEditor", N);
73 await Services.fog.testFlushAllChildren();
76 Glean.pdfjsEditingHighlight.kind.highlight.testGetValue(),
78 `Should have ${N} highlights`
81 Glean.pdfjsEditingHighlight.color.yellow.testGetValue(),
83 `Should have ${N} yellow highlights`
86 Glean.pdfjsEditingHighlight.method.main_toolbar.testGetValue(),
88 `Should have ${N} highlights created from the toolbar`
91 await EventUtils.synthesizeKey("KEY_Escape");
92 await waitForSelector(browser, ".highlightEditor:not(.selectedEditor)");
94 document.getElementById("cmd_print").doCommand();
95 await BrowserTestUtils.waitForCondition(() => {
96 let preview = document.querySelector(".printPreviewBrowser");
97 return preview && BrowserTestUtils.isVisible(preview);
99 await EventUtils.synthesizeKey("KEY_Escape");
101 await Services.fog.testFlushAllChildren();
103 Assert.equal(Glean.pdfjs.editing.print.testGetValue(), N);
104 Assert.equal(Glean.pdfjsEditingHighlight.print.testGetValue(), N);
106 Glean.pdfjsEditingHighlight.numberOfColors.one.testGetValue(),
113 "#highlightParamsToolbarContainer button[title='Green']"
115 const spanBox = await getSpanBox(browser, "Mozilla automated testing");
116 await BrowserTestUtils.synthesizeMouseAtPoint(
118 spanBox.y + spanBox.height / 2,
125 await BrowserTestUtils.synthesizeMouseAtPoint(
126 spanBox.x + spanBox.width,
127 spanBox.y + spanBox.height / 2,
134 await BrowserTestUtils.synthesizeMouseAtPoint(
135 spanBox.x + spanBox.width,
136 spanBox.y + spanBox.height / 2,
143 await waitForEditors(browser, ".highlightEditor", 3);
145 await Services.fog.testFlushAllChildren();
146 Assert.equal(Glean.pdfjsEditingHighlight.color.green.testGetValue(), 1);
148 Glean.pdfjsEditingHighlight.kind.free_highlight.testGetValue(),
152 let telemetryPromise = waitForTelemetry(browser);
153 await focus(browser, "#editorFreeHighlightThickness");
154 await EventUtils.synthesizeKey("KEY_ArrowRight");
156 await telemetryPromise;
158 await Services.fog.testFlushAllChildren();
160 Glean.pdfjsEditingHighlight.thickness.testGetValue().values[12],
164 Glean.pdfjsEditingHighlight.thickness.testGetValue().values[13],
168 Glean.pdfjsEditingHighlight.thicknessChanged.testGetValue(),
172 document.getElementById("cmd_print").doCommand();
173 await BrowserTestUtils.waitForCondition(() => {
174 let preview = document.querySelector(".printPreviewBrowser");
175 return preview && BrowserTestUtils.isVisible(preview);
177 await EventUtils.synthesizeKey("KEY_Escape");
179 await Services.fog.testFlushAllChildren();
181 Assert.equal(Glean.pdfjs.editing.print.testGetValue(), 3);
182 Assert.equal(Glean.pdfjsEditingHighlight.print.testGetValue(), 3);
184 Glean.pdfjsEditingHighlight.numberOfColors.one.testGetValue(),
188 Glean.pdfjsEditingHighlight.numberOfColors.two.testGetValue(),
192 await click(browser, ".highlightEditor.free button.colorPicker");
193 telemetryPromise = waitForTelemetry(browser);
196 ".highlightEditor.free button.colorPicker button[title='Red']"
198 await telemetryPromise;
200 await Services.fog.testFlushAllChildren();
201 Assert.equal(Glean.pdfjsEditingHighlight.colorChanged.testGetValue(), 1);
203 document.getElementById("cmd_print").doCommand();
204 await BrowserTestUtils.waitForCondition(() => {
205 let preview = document.querySelector(".printPreviewBrowser");
206 return preview && BrowserTestUtils.isVisible(preview);
208 await EventUtils.synthesizeKey("KEY_Escape");
210 await Services.fog.testFlushAllChildren();
212 Glean.pdfjsEditingHighlight.numberOfColors.one.testGetValue(),
216 Glean.pdfjsEditingHighlight.numberOfColors.two.testGetValue(),
220 telemetryPromise = waitForTelemetry(browser);
221 await EventUtils.synthesizeKey("KEY_Delete");
222 await telemetryPromise;
224 await Services.fog.testFlushAllChildren();
225 Assert.equal(Glean.pdfjsEditingHighlight.deleted.testGetValue(), 1);
227 await waitForPdfJSClose(browser);
228 await SpecialPowers.popPrefEnv();