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 // This is a modified version from browser_contextmenuFillLogins.js.
8 async function openContextMenuForSelector(browser, selector) {
9 const doc = browser.ownerDocument;
10 const CONTEXT_MENU = doc.getElementById("contentAreaContextMenu");
12 let contextMenuShownPromise = BrowserTestUtils.waitForEvent(
17 let inputCoords = await SpecialPowers.spawn(
21 let input = content.document.querySelector(selector);
23 let inputRect = input.getBoundingClientRect();
25 // listen for the contextmenu event so we can assert on receiving it
26 // and examine the target
27 content.contextmenuPromise = new Promise(resolve => {
28 content.document.body.addEventListener(
32 `Received event on target: ${event.target.nodeName}, type: ${event.target.type}`
34 content.console.log("got contextmenu event: ", event);
42 x: inputRect.x + inputRect.width / 2,
43 y: inputRect.y + inputRect.height / 2,
49 // add the offsets of the <browser> in the chrome window
50 let browserOffsets = browser.getBoundingClientRect();
51 let offsetX = browserOffsets.x + inputCoords.x;
52 let offsetY = browserOffsets.y + inputCoords.y;
54 // Synthesize a right mouse click over the input element, we have to trigger
55 // both events because formfill code relies on this event happening before the contextmenu
56 // (which it does for real user input) in order to not show the password autocomplete.
57 let eventDetails = { type: "mousedown", button: 2 };
58 await EventUtils.synthesizeMouseAtPoint(offsetX, offsetY, eventDetails);
60 // Synthesize a contextmenu event to actually open the context menu.
61 eventDetails = { type: "contextmenu", button: 2 };
62 await EventUtils.synthesizeMouseAtPoint(offsetX, offsetY, eventDetails);
64 await SpecialPowers.spawn(browser, [], async () => {
65 await content.contextmenuPromise;
68 info("waiting for contextMenuShownPromise");
70 await contextMenuShownPromise;
75 * Ensure the fill login context menu is not shown for PDF.js forms.
77 add_task(async function test_filllogin() {
78 await BrowserTestUtils.withNewTab(
79 { gBrowser, url: "about:blank" },
80 async function (browser) {
81 await waitForPdfJSAnnotationLayer(
83 TESTROOT + "file_pdfjs_form.pdf"
86 let contextMenu = await openContextMenuForSelector(
88 "#viewerContainer input"
90 let fillItem = contextMenu.querySelector("#fill-login");
91 ok(fillItem, "fill menu item exists");
92 ok(fillItem && EventUtils.isHidden(fillItem), "fill menu item is hidden");
94 let promiseHidden = BrowserTestUtils.waitForEvent(
98 info("Calling hidePopup on contextMenu");
99 contextMenu.hidePopup();
100 info("waiting for promiseHidden");
103 await waitForPdfJSClose(browser);