Bug 1942239 - Add option to explicitly enable incremental origin initialization in...
[gecko.git] / toolkit / components / pdfjs / test / browser_pdfjs_savedialog.js
blob67452427f142cd6c2d8bff89dc9f4562ccf6ec2c
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 function test() {
8 // When the always ask pref is disabled, we expect the PDF to be simply
9 // downloaded without a prompt, so ensure the pref is enabled here.
10 Services.prefs.setBoolPref(
11 "browser.download.always_ask_before_handling_new_types",
12 true
14 var oldAction = changeMimeHandler(Ci.nsIHandlerInfo.useSystemDefault, true);
15 var tab = BrowserTestUtils.addTab(gBrowser, TESTROOT + "file_pdfjs_test.pdf");
17 // Test: "Open with" dialog comes up when pdf.js is not selected as the default
18 // handler.
19 addWindowListener(
20 "chrome://mozapps/content/downloads/unknownContentType.xhtml",
21 finish
24 waitForExplicitFinish();
25 registerCleanupFunction(async function () {
26 Services.prefs.clearUserPref(
27 "browser.download.always_ask_before_handling_new_types"
29 changeMimeHandler(oldAction[0], oldAction[1]);
30 gBrowser.removeTab(tab);
31 });
34 function addWindowListener(aURL, aCallback) {
35 Services.wm.addListener({
36 onOpenWindow(aXULWindow) {
37 info("window opened, waiting for focus");
38 Services.wm.removeListener(this);
40 var domwindow = aXULWindow.docShell.domWindow;
41 waitForFocus(function () {
42 is(
43 domwindow.document.location.href,
44 aURL,
45 "should have seen the right window open"
47 domwindow.close();
48 aCallback();
49 }, domwindow);
51 onCloseWindow() {},
52 });