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