1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/downloads/test/unit/test_bug_395092.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// This file tests Bug 395092 - specifically that dl-start event isn't 1.9 +// dispatched for resumed downloads. 1.10 + 1.11 +const nsIDownloadManager = Ci.nsIDownloadManager; 1.12 +const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager); 1.13 + 1.14 +var observer = { 1.15 + mCount: 0, 1.16 + id: 0, 1.17 + observe: function observe(aSubject, aTopic, aData) 1.18 + { 1.19 + print("observering " + aTopic); 1.20 + if ("dl-start" == aTopic) { 1.21 + var dl = aSubject.QueryInterface(Ci.nsIDownload); 1.22 + this.id = dl.id; 1.23 + dm.pauseDownload(this.id); 1.24 + this.mCount++; 1.25 + do_check_eq(1, this.mCount); 1.26 + } else if ("timer-callback" == aTopic) { 1.27 + dm.resumeDownload(this.id); 1.28 + } 1.29 + } 1.30 +}; 1.31 + 1.32 +var httpserv = null; 1.33 +var timer = null; 1.34 +function run_test() 1.35 +{ 1.36 + if (oldDownloadManagerDisabled()) { 1.37 + return; 1.38 + } 1.39 + 1.40 + httpserv = new HttpServer(); 1.41 + httpserv.registerDirectory("/", do_get_cwd()); 1.42 + httpserv.start(-1); 1.43 + 1.44 + // our download listener 1.45 + var listener = { 1.46 + onDownloadStateChange: function(aOldState, aDownload) 1.47 + { 1.48 + if (Ci.nsIDownloadManager.DOWNLOAD_PAUSED == aDownload.state) { 1.49 + // This is so hacky, but it let's the nsWebBrowserPersist catch up with 1.50 + // the script... 1.51 + timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 1.52 + timer.init(observer, 0, Ci.nsITimer.TYPE_ONE_SHOT); 1.53 + } 1.54 + 1.55 + if (Ci.nsIDownloadManager.DOWNLOAD_FINISHED == aDownload.state) 1.56 + do_test_finished(); 1.57 + }, 1.58 + onStateChange: function(a, b, c, d, e) { }, 1.59 + onProgressChange: function(a, b, c, d, e, f, g) { }, 1.60 + onSecurityChange: function(a, b, c, d) { } 1.61 + }; 1.62 + dm.addListener(listener); 1.63 + dm.addListener(getDownloadListener()); 1.64 + 1.65 + var os = Cc["@mozilla.org/observer-service;1"]. 1.66 + getService(Ci.nsIObserverService); 1.67 + os.addObserver(observer, "dl-start", false); 1.68 + 1.69 + addDownload(httpserv); 1.70 + do_test_pending(); 1.71 +}