security/manager/ssl/tests/mochitest/mixedcontent/test_bug383369.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Bug 383369 test</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="mixedContentTest.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8
michael@0 9 <script class="testbody" type="text/javascript">
michael@0 10
michael@0 11 // We want to start this test from an insecure context
michael@0 12 loadAsInsecure = true;
michael@0 13 // We don't want to go through the navigation back/forward test
michael@0 14 bypassNavigationTest = true;
michael@0 15
michael@0 16 function runTest()
michael@0 17 {
michael@0 18 // Force download to be w/o user assistance for our testing mime type
michael@0 19 const mimeSvc = SpecialPowers.Cc["@mozilla.org/mime;1"]
michael@0 20 .getService(SpecialPowers.Ci.nsIMIMEService);
michael@0 21 var handlerInfo = mimeSvc.getFromTypeAndExtension("application/x-auto-download", "auto");
michael@0 22 handlerInfo.preferredAction = SpecialPowers.Ci.nsIHandlerInfo.saveToDisk;
michael@0 23 handlerInfo.alwaysAskBeforeHandling = false;
michael@0 24 handlerInfo.preferredApplicationHandler = null;
michael@0 25
michael@0 26 const handlerSvc = SpecialPowers.Cc["@mozilla.org/uriloader/handler-service;1"]
michael@0 27 .getService(SpecialPowers.Ci.nsIHandlerService);
michael@0 28 handlerSvc.store(handlerInfo);
michael@0 29
michael@0 30 var dirProvider = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"]
michael@0 31 .getService(SpecialPowers.Ci.nsIProperties);
michael@0 32 var profileDir = dirProvider.get("ProfDS", SpecialPowers.Ci.nsIFile);
michael@0 33 profileDir.append("downloads");
michael@0 34
michael@0 35 var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
michael@0 36 .getService(SpecialPowers.Ci.nsIPrefService);
michael@0 37 prefs = prefs.getBranch("browser.download.");
michael@0 38
michael@0 39 prefs.setCharPref("dir", profileDir.path);
michael@0 40 prefs.setBoolPref("useDownloadDir", true);
michael@0 41 prefs.setIntPref("folderList", 2);
michael@0 42 prefs.setBoolPref("manager.closeWhenDone", true);
michael@0 43 prefs.setBoolPref("manager.showWhenStarting", false);
michael@0 44
michael@0 45 var theWindow = window;
michael@0 46
michael@0 47 var useJSTransfer = false;
michael@0 48 try {
michael@0 49 // This method throws an exception if the old Download Manager is disabled.
michael@0 50 Services.downloads.activeDownloadCount;
michael@0 51 } catch (ex) {
michael@0 52 useJSTransfer = true;
michael@0 53 }
michael@0 54
michael@0 55 if (useJSTransfer) {
michael@0 56 var Downloads = SpecialPowers.Cu.import("resource://gre/modules/Downloads.jsm").Downloads;
michael@0 57 Downloads.getList(Downloads.PUBLIC).then(list => {
michael@0 58 list = SpecialPowers.wrap(list);
michael@0 59 list.addView({
michael@0 60 onDownloadAdded: function (aDownload) {
michael@0 61 list.removeView(this);
michael@0 62 SpecialPowers.wrap(aDownload).whenSucceeded().then(() => {
michael@0 63 list.removeFinished();
michael@0 64 theWindow.location = "bug383369step2.html";
michael@0 65 });
michael@0 66 },
michael@0 67 });
michael@0 68 window.location = "download.auto";
michael@0 69 }).then(null, SpecialPowers.Cu.reportError);
michael@0 70
michael@0 71 return;
michael@0 72 }
michael@0 73
michael@0 74 var downloadManager = SpecialPowers.Cc["@mozilla.org/download-manager;1"]
michael@0 75 .getService(SpecialPowers.Ci.nsIDownloadManager);
michael@0 76 var observer = {
michael@0 77 observe: function(subject, topic, data) {
michael@0 78 switch (topic) {
michael@0 79 case "dl-done":
michael@0 80 case "dl-failed":
michael@0 81 case "dl-blocked":
michael@0 82 case "dl-dirty":
michael@0 83 downloadManager.cleanUp();
michael@0 84 theWindow.location = "bug383369step2.html";
michael@0 85 observerService.removeObserver(this, "dl-done");
michael@0 86 observerService.removeObserver(this, "dl-failed");
michael@0 87 observerService.removeObserver(this, "dl-blocked");
michael@0 88 observerService.removeObserver(this, "dl-dirty");
michael@0 89 break;
michael@0 90 }
michael@0 91 }
michael@0 92 };
michael@0 93 var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
michael@0 94 .getService(SpecialPowers.Ci.nsIObserverService);
michael@0 95 observerService.addObserver(observer, "dl-done", false);
michael@0 96 observerService.addObserver(observer, "dl-failed", false);
michael@0 97 observerService.addObserver(observer, "dl-blocked", false);
michael@0 98 observerService.addObserver(observer, "dl-dirty", false);
michael@0 99
michael@0 100 window.location = "download.auto";
michael@0 101 }
michael@0 102
michael@0 103 function afterNavigationTest()
michael@0 104 {
michael@0 105 }
michael@0 106
michael@0 107 testCleanUp = function cleanup()
michael@0 108 {
michael@0 109 const mimeSvc = SpecialPowers.Cc["@mozilla.org/mime;1"]
michael@0 110 .getService(SpecialPowers.Ci.nsIMIMEService);
michael@0 111 var handlerInfo = mimeSvc.getFromTypeAndExtension("application/x-auto-download", "auto");
michael@0 112
michael@0 113 const handlerSvc = SpecialPowers.Cc["@mozilla.org/uriloader/handler-service;1"]
michael@0 114 .getService(SpecialPowers.Ci.nsIHandlerService);
michael@0 115 handlerSvc.remove(handlerInfo);
michael@0 116
michael@0 117 var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"]
michael@0 118 .getService(SpecialPowers.Ci.nsIPrefService);
michael@0 119 prefs = prefs.getBranch("browser.download.");
michael@0 120
michael@0 121 var prefKeys = ["dir", "useDownloadDir", "folderList",
michael@0 122 "manager.closeWhenDone", "manager.showWhenStarting"];
michael@0 123 for (var i = 0; i < prefKeys.length; i++)
michael@0 124 if (prefs.prefHasUserValue(prefKeys[i]))
michael@0 125 prefs.clearUserPref(prefKeys[i]);
michael@0 126 }
michael@0 127
michael@0 128 </script>
michael@0 129 </head>
michael@0 130
michael@0 131 <body>
michael@0 132 </body>
michael@0 133 </html>

mercurial