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