michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This file tests Bug 395092 - specifically that dl-start event isn't michael@0: // dispatched for resumed downloads. michael@0: michael@0: const nsIDownloadManager = Ci.nsIDownloadManager; michael@0: const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager); michael@0: michael@0: var observer = { michael@0: mCount: 0, michael@0: id: 0, michael@0: observe: function observe(aSubject, aTopic, aData) michael@0: { michael@0: print("observering " + aTopic); michael@0: if ("dl-start" == aTopic) { michael@0: var dl = aSubject.QueryInterface(Ci.nsIDownload); michael@0: this.id = dl.id; michael@0: dm.pauseDownload(this.id); michael@0: this.mCount++; michael@0: do_check_eq(1, this.mCount); michael@0: } else if ("timer-callback" == aTopic) { michael@0: dm.resumeDownload(this.id); michael@0: } michael@0: } michael@0: }; michael@0: michael@0: var httpserv = null; michael@0: var timer = null; michael@0: function run_test() michael@0: { michael@0: if (oldDownloadManagerDisabled()) { michael@0: return; michael@0: } michael@0: michael@0: httpserv = new HttpServer(); michael@0: httpserv.registerDirectory("/", do_get_cwd()); michael@0: httpserv.start(-1); michael@0: michael@0: // our download listener michael@0: var listener = { michael@0: onDownloadStateChange: function(aOldState, aDownload) michael@0: { michael@0: if (Ci.nsIDownloadManager.DOWNLOAD_PAUSED == aDownload.state) { michael@0: // This is so hacky, but it let's the nsWebBrowserPersist catch up with michael@0: // the script... michael@0: timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); michael@0: timer.init(observer, 0, Ci.nsITimer.TYPE_ONE_SHOT); michael@0: } michael@0: michael@0: if (Ci.nsIDownloadManager.DOWNLOAD_FINISHED == aDownload.state) michael@0: do_test_finished(); michael@0: }, michael@0: onStateChange: function(a, b, c, d, e) { }, michael@0: onProgressChange: function(a, b, c, d, e, f, g) { }, michael@0: onSecurityChange: function(a, b, c, d) { } michael@0: }; michael@0: dm.addListener(listener); michael@0: dm.addListener(getDownloadListener()); michael@0: michael@0: var os = Cc["@mozilla.org/observer-service;1"]. michael@0: getService(Ci.nsIObserverService); michael@0: os.addObserver(observer, "dl-start", false); michael@0: michael@0: addDownload(httpserv); michael@0: do_test_pending(); michael@0: }