1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/downloads/tests/chrome/test_removeDownload_updates_ui.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 +<?xml version="1.0"?> 1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.6 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.8 +<!-- 1.9 + * Test bug 394039 to make sure calling removeDownload of the 1.10 + * nsIDownloadManager service correctly updates the download window. 1.11 +--> 1.12 + 1.13 +<window title="Download Manager Test" 1.14 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.15 + onload="test();"> 1.16 + 1.17 + <script type="application/javascript" 1.18 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.19 + <script type="application/javascript" 1.20 + src="utils.js"/> 1.21 + 1.22 + <script type="application/javascript"> 1.23 + <![CDATA[ 1.24 + 1.25 +var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); 1.26 +var dmFile = Cc["@mozilla.org/file/directory_service;1"]. 1.27 + getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); 1.28 +dmFile.append("dm-ui-test.file"); 1.29 +dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); 1.30 +var gTestPath = ios.newFileURI(dmFile).spec; 1.31 + 1.32 +const DownloadData = [ 1.33 + { name: "381603.patch", 1.34 + source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", 1.35 + target: gTestPath, 1.36 + startTime: 1180493839859230, 1.37 + endTime: 1180493839859239, 1.38 + state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED, 1.39 + currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 } 1.40 +]; 1.41 + 1.42 +function test() 1.43 +{ 1.44 + var dmui = getDMUI(); 1.45 + if (!dmui) { 1.46 + todo(false, "skip test for toolkit download manager UI"); 1.47 + return; 1.48 + } 1.49 + 1.50 + var dm = Cc["@mozilla.org/download-manager;1"]. 1.51 + getService(Ci.nsIDownloadManager); 1.52 + var db = dm.DBConnection; 1.53 + 1.54 + // First, we populate the database with some fake data 1.55 + db.executeSimpleSQL("DELETE FROM moz_downloads"); 1.56 + var stmt = db.createStatement( 1.57 + "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " + 1.58 + "state, currBytes, maxBytes, preferredAction, autoResume) " + 1.59 + "VALUES (:name, :source, :target, :startTime, :endTime, :state, " + 1.60 + ":currBytes, :maxBytes, :preferredAction, :autoResume)"); 1.61 + for each (var dl in DownloadData) { 1.62 + for (var prop in dl) 1.63 + stmt.params[prop] = dl[prop]; 1.64 + 1.65 + stmt.execute(); 1.66 + } 1.67 + stmt.finalize(); 1.68 + 1.69 + // See if the DM is already open, and if it is, close it! 1.70 + var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. 1.71 + getService(Ci.nsIWindowMediator); 1.72 + var win = wm.getMostRecentWindow("Download:Manager"); 1.73 + if (win) 1.74 + win.close(); 1.75 + 1.76 + let os = Cc["@mozilla.org/observer-service;1"]. 1.77 + getService(Ci.nsIObserverService); 1.78 + const DLMGR_UI_DONE = "download-manager-ui-done"; 1.79 + 1.80 + let testObs = { 1.81 + observe: function(aSubject, aTopic, aData) 1.82 + { 1.83 + if (aTopic != DLMGR_UI_DONE) 1.84 + return; 1.85 + 1.86 + let win = aSubject.QueryInterface(Ci.nsIDOMWindow); 1.87 + win.focus(); 1.88 + let doc = win.document; 1.89 + 1.90 + // Note: This also tests the ordering of the display 1.91 + let stmt = db.createStatement("SELECT id FROM moz_downloads"); 1.92 + let id = -1; 1.93 + try { 1.94 + stmt.executeStep(); 1.95 + id = stmt.getInt64(0); 1.96 + } 1.97 + finally { 1.98 + stmt.reset(); 1.99 + stmt.finalize(); 1.100 + } 1.101 + 1.102 + dm.removeDownload(id); 1.103 + let richlistbox = doc.getElementById("downloadView"); 1.104 + is(richlistbox.children.length, 0, 1.105 + "The download was properly removed"); 1.106 + 1.107 + win.close(); 1.108 + dmFile.remove(false); 1.109 + os.removeObserver(testObs, DLMGR_UI_DONE); 1.110 + SimpleTest.finish(); 1.111 + } 1.112 + } 1.113 + 1.114 + // Register with the observer service 1.115 + os.addObserver(testObs, DLMGR_UI_DONE, false); 1.116 + 1.117 + // Show the Download Manager UI 1.118 + dmui.show(); 1.119 + 1.120 + SimpleTest.waitForExplicitFinish(); 1.121 +} 1.122 + 1.123 + ]]> 1.124 + </script> 1.125 + 1.126 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.127 + <p id="display"></p> 1.128 + <div id="content" style="display:none;"></div> 1.129 + <pre id="test"></pre> 1.130 + </body> 1.131 +</window>