4 <title>Bug
383369 test
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <script type=
"text/javascript" src=
"mixedContentTest.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
9 <script class=
"testbody" type=
"text/javascript">
12 // We want to start this test from an insecure context
13 loadAsInsecure = true;
14 // We don't want to go through the navigation back/forward test
15 bypassNavigationTest = true;
17 async function runTest() {
18 let script = SpecialPowers.loadChromeScript(function() {
19 /* eslint-env mozilla/chrome-script */
20 // Force download to be w/o user assistance for our testing mime type
21 const mimeSvc = Cc[
"@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
23 mimeSvc.getFromTypeAndExtension(
"application/x-auto-download",
"auto");
24 handlerInfo.preferredAction = Ci.nsIHandlerInfo.saveToDisk;
25 handlerInfo.alwaysAskBeforeHandling = false;
26 handlerInfo.preferredApplicationHandler = null;
28 const handlerSvc = Cc[
"@mozilla.org/uriloader/handler-service;1"]
29 .getService(Ci.nsIHandlerService);
30 handlerSvc.store(handlerInfo);
32 let profileDir = Services.dirsvc.get(
"ProfDS", Ci.nsIFile);
33 profileDir.append(
"downloads");
35 let prefBranch = Services.prefs.getBranch(
"browser.download.");
37 prefBranch.setCharPref(
"dir", profileDir.path);
38 prefBranch.setBoolPref(
"useDownloadDir", true);
39 prefBranch.setIntPref(
"folderList",
2);
42 ChromeUtils.importESModule(
"resource://gre/modules/Downloads.sys.mjs");
43 Downloads.getList(Downloads.PUBLIC).then(list =
> {
45 onDownloadAdded(aDownload) {
46 list.removeView(this);
47 aDownload.whenSucceeded().then(() =
> {
48 list.removeFinished();
49 sendAsyncMessage(
"navigate",
"bug383369step2.html");
53 sendAsyncMessage(
"navigate",
"download.auto");
54 }).catch(console.error);
56 script.addMessageListener(
"navigate", function(url) {
57 window.location = url;
61 async function afterNavigationTest() {}
63 testCleanUp = function cleanup() {
64 SpecialPowers.loadChromeScript(function() {
65 const mimeSvc = Cc[
"@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
67 mimeSvc.getFromTypeAndExtension(
"application/x-auto-download",
"auto");
69 const handlerSvc = Cc[
"@mozilla.org/uriloader/handler-service;1"]
70 .getService(Ci.nsIHandlerService);
71 handlerSvc.remove(handlerInfo);
73 let prefBranch = Services.prefs.getBranch(
"browser.download.");
75 const prefKeys = [
"dir",
"useDownloadDir",
"folderList"];
76 for (let prefKey of prefKeys) {
77 if (prefBranch.prefHasUserValue(prefKey)) {
78 prefBranch.clearUserPref(prefKey);