diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/pdfjs/test/browser_pdfjs_savedialog.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/pdfjs/test/browser_pdfjs_savedialog.js')
-rw-r--r-- | toolkit/components/pdfjs/test/browser_pdfjs_savedialog.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/toolkit/components/pdfjs/test/browser_pdfjs_savedialog.js b/toolkit/components/pdfjs/test/browser_pdfjs_savedialog.js new file mode 100644 index 0000000000..4f0c952ebb --- /dev/null +++ b/toolkit/components/pdfjs/test/browser_pdfjs_savedialog.js @@ -0,0 +1,53 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const RELATIVE_DIR = "toolkit/components/pdfjs/test/"; +const TESTROOT = "http://example.com/browser/" + RELATIVE_DIR; + +function test() { + // When the always ask pref is disabled, we expect the PDF to be simply + // downloaded without a prompt, so ensure the pref is enabled here. + Services.prefs.setBoolPref( + "browser.download.always_ask_before_handling_new_types", + true + ); + var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true); + var tab = BrowserTestUtils.addTab(gBrowser, TESTROOT + "file_pdfjs_test.pdf"); + + // Test: "Open with" dialog comes up when pdf.js is not selected as the default + // handler. + addWindowListener( + "chrome://mozapps/content/downloads/unknownContentType.xhtml", + finish + ); + + waitForExplicitFinish(); + registerCleanupFunction(function () { + Services.prefs.clearUserPref( + "browser.download.always_ask_before_handling_new_types" + ); + changeMimeHandler(oldAction[0], oldAction[1]); + gBrowser.removeTab(tab); + }); +} + +function addWindowListener(aURL, aCallback) { + Services.wm.addListener({ + onOpenWindow(aXULWindow) { + info("window opened, waiting for focus"); + Services.wm.removeListener(this); + + var domwindow = aXULWindow.docShell.domWindow; + waitForFocus(function () { + is( + domwindow.document.location.href, + aURL, + "should have seen the right window open" + ); + domwindow.close(); + aCallback(); + }, domwindow); + }, + onCloseWindow(aXULWindow) {}, + }); +} |