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