|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 // This file tests Bug 395092 - specifically that dl-start event isn't |
|
6 // dispatched for resumed downloads. |
|
7 |
|
8 const nsIDownloadManager = Ci.nsIDownloadManager; |
|
9 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager); |
|
10 |
|
11 var observer = { |
|
12 mCount: 0, |
|
13 id: 0, |
|
14 observe: function observe(aSubject, aTopic, aData) |
|
15 { |
|
16 print("observering " + aTopic); |
|
17 if ("dl-start" == aTopic) { |
|
18 var dl = aSubject.QueryInterface(Ci.nsIDownload); |
|
19 this.id = dl.id; |
|
20 dm.pauseDownload(this.id); |
|
21 this.mCount++; |
|
22 do_check_eq(1, this.mCount); |
|
23 } else if ("timer-callback" == aTopic) { |
|
24 dm.resumeDownload(this.id); |
|
25 } |
|
26 } |
|
27 }; |
|
28 |
|
29 var httpserv = null; |
|
30 var timer = null; |
|
31 function run_test() |
|
32 { |
|
33 if (oldDownloadManagerDisabled()) { |
|
34 return; |
|
35 } |
|
36 |
|
37 httpserv = new HttpServer(); |
|
38 httpserv.registerDirectory("/", do_get_cwd()); |
|
39 httpserv.start(-1); |
|
40 |
|
41 // our download listener |
|
42 var listener = { |
|
43 onDownloadStateChange: function(aOldState, aDownload) |
|
44 { |
|
45 if (Ci.nsIDownloadManager.DOWNLOAD_PAUSED == aDownload.state) { |
|
46 // This is so hacky, but it let's the nsWebBrowserPersist catch up with |
|
47 // the script... |
|
48 timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
|
49 timer.init(observer, 0, Ci.nsITimer.TYPE_ONE_SHOT); |
|
50 } |
|
51 |
|
52 if (Ci.nsIDownloadManager.DOWNLOAD_FINISHED == aDownload.state) |
|
53 do_test_finished(); |
|
54 }, |
|
55 onStateChange: function(a, b, c, d, e) { }, |
|
56 onProgressChange: function(a, b, c, d, e, f, g) { }, |
|
57 onSecurityChange: function(a, b, c, d) { } |
|
58 }; |
|
59 dm.addListener(listener); |
|
60 dm.addListener(getDownloadListener()); |
|
61 |
|
62 var os = Cc["@mozilla.org/observer-service;1"]. |
|
63 getService(Ci.nsIObserverService); |
|
64 os.addObserver(observer, "dl-start", false); |
|
65 |
|
66 addDownload(httpserv); |
|
67 do_test_pending(); |
|
68 } |