1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
6 const TESTROOT = getRootDirectory(gTestPath).replace(
7 "chrome://mochitests/content/",
11 // The page we use to open the PDF.
12 const LINK_PAGE_URL = TESTROOT + "file_pdf_download_link.html";
14 add_task(async function test_filename_nonpdf_extension() {
15 var MockFilePicker = SpecialPowers.MockFilePicker;
16 MockFilePicker.init(window.browsingContext);
17 let filepickerNamePromise = new Promise(resolve => {
18 MockFilePicker.showCallback = function (fp) {
19 resolve(fp.defaultString);
20 return MockFilePicker.returnCancel;
23 registerCleanupFunction(() => MockFilePicker.cleanup());
25 await SpecialPowers.pushPrefEnv({
26 set: [["browser.download.open_pdf_attachments_inline", true]],
29 await BrowserTestUtils.withNewTab(
30 { gBrowser, url: LINK_PAGE_URL },
31 async function (browser) {
32 await SpecialPowers.spawn(browser, [], async () => {
33 let link = content.document.getElementById("custom_filename");
34 let response = await content.fetch(link.href, {
37 "Content-Type": "application/pdf",
40 let blob = await response.blob();
41 const url = content.URL.createObjectURL(blob);
43 link.download = "Fido-2022-04-28";
44 link.rel = "noopener";
47 let pdfLoaded = BrowserTestUtils.waitForNewTab(
49 url => url.startsWith("blob:"),
52 await BrowserTestUtils.synthesizeMouseAtCenter(
57 let newTab = await pdfLoaded;
59 info("Clicking on the download button...");
60 await SpecialPowers.spawn(newTab.linkedBrowser, [], () => {
61 content.document.getElementById("downloadButton").click();
63 info("Waiting for a filename to be picked from the file picker");
64 let defaultName = await filepickerNamePromise;
67 "Fido-2022-04-28.pdf",
68 "Should have gotten the provided filename with pdf suffixed."
70 await waitForPdfJSClose(newTab.linkedBrowser, /* closeTab = */ true);
74 await SpecialPowers.popPrefEnv();