Revision control
Copy as Markdown
Other Tools
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
/**
* Tests that pressing the space bar while a PDF is open in a content tab
* scrolls down.
*/
"use strict";
var {
be_in_folder,
create_folder,
select_click_row,
wait_for_message_display_completion,
} = ChromeUtils.importESModule(
);
var { make_message_sets_in_folders } = ChromeUtils.importESModule(
);
const PDF_URL =
add_task(
async function test_space_in_pdf_content_tab_does_not_call_cmd_space() {
const tabmail = document.getElementById("tabmail");
tabmail.openTab("contentTab", { url: PDF_URL, background: false });
const contentTab = tabmail.currentTabInfo;
const browser = contentTab.browser;
// Wait for first page to be ready
await BrowserTestUtils.waitForContentEvent(
browser,
"textlayerrendered",
false,
null,
true
);
try {
await SpecialPowers.spawn(browser, [], async () => {
const { ContentTaskUtils } = ChromeUtils.importESModule(
);
const EventUtils = ContentTaskUtils.getEventUtils(content);
const viewerContent =
content.document.getElementById("viewerContainer");
viewerContent.focus();
Assert.equal(viewerContent.scrollTop, 10, "initial scrollTop ok");
const { promise, resolve } = Promise.withResolvers();
viewerContent.addEventListener("scrollend", () => resolve(), {
once: true,
});
EventUtils.synthesizeKey(" ", {}, content);
await promise;
Assert.greater(viewerContent.scrollTop, 10, "did scroll down");
});
} finally {
tabmail.closeTab(contentTab);
}
}
);
add_task(async function test_ctrlS_in_pdf_content_tab_triggers_download() {
const tabmail = document.getElementById("tabmail");
tabmail.openTab("contentTab", { url: PDF_URL, background: false });
const contentTab = tabmail.currentTabInfo;
const browser = contentTab.browser;
await BrowserTestUtils.waitForContentEvent(
browser,
"textlayerrendered",
false,
null,
true
);
try {
// Intercept sendAsyncMessage on the Pdfjs actor to detect
// the PDFJS:Save message without triggering an actual download.
const actor = browser.browsingContext.currentWindowGlobal.getActor("Pdfjs");
const { promise, resolve } = Promise.withResolvers();
actor.sendAsyncMessage = (name, data) => {
delete actor.sendAsyncMessage; // restore the prototype method
if (name === "PDFJS:Save") {
resolve();
return;
}
actor.sendAsyncMessage(name, data);
};
EventUtils.synthesizeKey("s", { ctrlKey: true }, window);
await promise;
Assert.ok(true, "Ctrl+S in PDF content tab sent PDFJS:Save to the viewer");
} finally {
tabmail.closeTab(contentTab);
}
});