diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js')
-rw-r--r-- | toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js | 140 |
1 files changed, 95 insertions, 45 deletions
diff --git a/toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js b/toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js index d857bb6aac..779a3a6ad4 100644 --- a/toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js +++ b/toolkit/components/pdfjs/test/browser_pdfjs_editing_contextmenu.js @@ -32,9 +32,9 @@ async function openContextMenuAt(browser, x, y) { * Open a context menu and get the pdfjs entries * @param {Object} browser * @param {Object} box - * @returns {Map<string,HTMLElement>} the pdfjs menu entries. + * @returns {Promise<Map<string,HTMLElement>>} the pdfjs menu entries. */ -async function getContextMenuItems(browser, box) { +function getContextMenuItems(browser, box) { return new Promise(resolve => { setTimeout(async () => { const { x, y, width, height } = box; @@ -48,6 +48,7 @@ async function getContextMenuItems(browser, box) { "context-pdfjs-delete", "context-pdfjs-selectall", "context-sep-pdfjs-selectall", + "context-pdfjs-highlight-selection", ]; await openContextMenuAt(browser, x + width / 2, y + height / 2); @@ -68,7 +69,7 @@ async function getContextMenuItems(browser, box) { * and returs the pdfjs menu entries. * @param {Object} browser * @param {string} selector - * @returns {Map<string,HTMLElement>} the pdfjs menu entries. + * @returns {Promise<Map<string,HTMLElement>>} the pdfjs menu entries. */ async function getContextMenuItemsOn(browser, selector) { const box = await SpecialPowers.spawn( @@ -129,35 +130,36 @@ function assertMenuitems(menuitems, expected) { elmt => !elmt.id.includes("-sep-") && !elmt.hidden && - elmt.getAttribute("disabled") === "false" + ["", "false"].includes(elmt.getAttribute("disabled")) ) .map(elmt => elmt.id), expected ); } -// Text copy, paste, undo, redo, delete and select all in using the context -// menu. -add_task(async function test() { - let mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); - let handlerInfo = mimeService.getFromTypeAndExtension( - "application/pdf", - "pdf" - ); - - // Make sure pdf.js is the default handler. - is( - handlerInfo.alwaysAskBeforeHandling, - false, - "pdf handler defaults to always-ask is false" - ); - is( - handlerInfo.preferredAction, - Ci.nsIHandlerInfo.handleInternally, - "pdf handler defaults to internal" +async function waitAndCheckEmptyContextMenu(browser) { + // check that PDF is opened with internal viewer + await waitForPdfJSAllLayers(browser, TESTROOT + "file_pdfjs_test.pdf", [ + ["annotationEditorLayer", "annotationLayer", "textLayer", "canvasWrapper"], + ["annotationEditorLayer", "textLayer", "canvasWrapper"], + ]); + + const spanBox = await getSpanBox(browser, "and found references"); + const menuitems = await getContextMenuItems(browser, spanBox); + + // Nothing have been edited, hence the context menu doesn't contain any + // pdf entries. + Assert.ok( + [...menuitems.values()].every(elmt => elmt.hidden), + "No visible pdf menuitem" ); + await hideContextMenu(browser); +} - info("Pref action: " + handlerInfo.preferredAction); +// Text copy, paste, undo, redo, delete and select all in using the context +// menu. +add_task(async function test_copy_paste_undo_redo() { + makePDFJSHandler(); await BrowserTestUtils.withNewTab( { gBrowser, url: "about:blank" }, @@ -168,27 +170,8 @@ add_task(async function test() { set: [["pdfjs.annotationEditorMode", 0]], }); - // check that PDF is opened with internal viewer - await waitForPdfJSAllLayers(browser, TESTROOT + "file_pdfjs_test.pdf", [ - [ - "annotationEditorLayer", - "annotationLayer", - "textLayer", - "canvasWrapper", - ], - ["annotationEditorLayer", "textLayer", "canvasWrapper"], - ]); - + await waitAndCheckEmptyContextMenu(browser); const spanBox = await getSpanBox(browser, "and found references"); - let menuitems = await getContextMenuItems(browser, spanBox); - - // Nothing have been edited, hence the context menu doesn't contain any - // pdf entries. - Assert.ok( - [...menuitems.values()].every(elmt => elmt.hidden), - "No visible pdf menuitem" - ); - await hideContextMenu(browser); await enableEditor(browser, "FreeText"); await addFreeText(browser, "hello", spanBox); @@ -211,7 +194,7 @@ add_task(async function test() { Assert.equal(await countElements(browser, ".selectedEditor"), 0); - menuitems = await getContextMenuItems(browser, spanBox); + let menuitems = await getContextMenuItems(browser, spanBox); assertMenuitems(menuitems, [ "context-pdfjs-undo", // Last created editor is undoable "context-pdfjs-selectall", // and selectable. @@ -374,6 +357,73 @@ add_task(async function test() { await SpecialPowers.spawn(browser, [], async function () { var viewer = content.wrappedJSObject.PDFViewerApplication; + viewer.pdfDocument.annotationStorage.resetModified(); + await viewer.close(); + }); + } + ); +}); + +add_task(async function test_highlight_selection() { + makePDFJSHandler(); + + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:blank" }, + async function (browser) { + await SpecialPowers.pushPrefEnv({ + set: [ + ["pdfjs.annotationEditorMode", 0], + ["pdfjs.enableHighlightEditor", true], + ], + }); + + await waitAndCheckEmptyContextMenu(browser); + const spanBox = await getSpanBox(browser, "and found references"); + + const changePromise = BrowserTestUtils.waitForContentEvent( + browser, + "annotationeditorstateschanged", + false, + null, + true + ); + await clickAt( + browser, + spanBox.x + spanBox.width / 2, + spanBox.y + spanBox.height / 2, + 2 + ); + await changePromise; + await TestUtils.waitForTick(); + + const mozBox = await getSpanBox(browser, "Mozilla automated testing"); + const menuitems = await getContextMenuItems(browser, mozBox); + + assertMenuitems(menuitems, ["context-pdfjs-highlight-selection"]); + + const telemetryPromise = BrowserTestUtils.waitForContentEvent( + browser, + "reporttelemetry", + false, + null, + true + ); + await clickOnItem( + browser, + menuitems, + "context-pdfjs-highlight-selection" + ); + await telemetryPromise; + + Assert.equal( + await countElements(browser, ".highlightEditor"), + 1, + "An highlight editor must have been added" + ); + + await SpecialPowers.spawn(browser, [], async function () { + var viewer = content.wrappedJSObject.PDFViewerApplication; + viewer.pdfDocument.annotationStorage.resetModified(); await viewer.close(); }); } |