1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/downloads/tests/chrome/test_pause_button_state.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,144 @@ 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 + * This tests bug 410289. Specifically, it tests that the pause button is 1.10 + * active for resumable downloads, and inactive for non-resumable ones. 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: "Firefox 2.0.0.11.dmg", 1.34 + source: "http://mozilla-mirror.naist.jp//firefox/releases/2.0.0.11/mac/en-US/Firefox%202.0.0.11.dmg", 1.35 + target: gTestPath, 1.36 + startTime: 1200185939538521, 1.37 + endTime: 1200185939538521, 1.38 + entityID: "%22216c12-1116bd8-440070d5d2700%22/17918936/Thu, 29 Nov 2007 01:15:40 GMT", 1.39 + state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING, 1.40 + currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }, 1.41 + { name: "Firefox 2.0.0.11.dmg", 1.42 + source: "http://mozilla-mirror.naist.jp//firefox/releases/2.0.0.11/mac/en-US/Firefox%202.0.0.11.dmg", 1.43 + target: gTestPath, 1.44 + startTime: 1200185939538520, 1.45 + endTime: 1200185939538520, 1.46 + entityID: "", 1.47 + state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING, 1.48 + currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 } 1.49 +]; 1.50 + 1.51 +function test() 1.52 +{ 1.53 + var dmui = getDMUI(); 1.54 + if (!dmui) { 1.55 + todo(false, "skip test for toolkit download manager UI"); 1.56 + return; 1.57 + } 1.58 + 1.59 + var dm = Cc["@mozilla.org/download-manager;1"]. 1.60 + getService(Ci.nsIDownloadManager); 1.61 + var db = dm.DBConnection; 1.62 + 1.63 + // First, we populate the database with some fake data 1.64 + db.executeSimpleSQL("DELETE FROM moz_downloads"); 1.65 + var stmt = db.createStatement( 1.66 + "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " + 1.67 + "state, currBytes, maxBytes, preferredAction, autoResume, entityID) " + 1.68 + "VALUES (:name, :source, :target, :startTime, :endTime, :state, " + 1.69 + ":currBytes, :maxBytes, :preferredAction, :autoResume, :entityID)"); 1.70 + for each (var dl in DownloadData) { 1.71 + for (var prop in dl) 1.72 + stmt.params[prop] = dl[prop]; 1.73 + 1.74 + stmt.execute(); 1.75 + } 1.76 + stmt.finalize(); 1.77 + 1.78 + // See if the DM is already open, and if it is, close it! 1.79 + var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. 1.80 + getService(Ci.nsIWindowMediator); 1.81 + var win = wm.getMostRecentWindow("Download:Manager"); 1.82 + if (win) 1.83 + win.close(); 1.84 + 1.85 + let os = Cc["@mozilla.org/observer-service;1"]. 1.86 + getService(Ci.nsIObserverService); 1.87 + const DLMGR_UI_DONE = "download-manager-ui-done"; 1.88 + 1.89 + let testObs = { 1.90 + observe: function(aSubject, aTopic, aData) 1.91 + { 1.92 + if (aTopic != DLMGR_UI_DONE) 1.93 + return; 1.94 + 1.95 + let win = aSubject.QueryInterface(Ci.nsIDOMWindow); 1.96 + win.focus(); 1.97 + let doc = win.document; 1.98 + 1.99 + let richlistbox = doc.getElementById("downloadView"); 1.100 + for (let i = 0; i < DownloadData.length; i++) { 1.101 + let dl = richlistbox.children[i]; 1.102 + let buttons = dl.buttons; 1.103 + for (let j = 0; j < buttons.length; j++) { 1.104 + let button = buttons[j]; 1.105 + if ("cmd_pause" == button.getAttribute("cmd")) { 1.106 + let id = dl.getAttribute("dlid"); 1.107 + 1.108 + // check if it should be disabled or not 1.109 + let resumable = dm.getDownload(id).resumable; 1.110 + is(DownloadData[i].entityID ? true : false, resumable, 1.111 + "Pause button is properly disabled"); 1.112 + 1.113 + // also check if tooltip text was updated 1.114 + if (!resumable) { 1.115 + let sb = doc.getElementById("downloadStrings"); 1.116 + is(button.getAttribute("tooltiptext"), sb.getString("cannotPause"), 1.117 + "Pause button has proper text"); 1.118 + } 1.119 + } 1.120 + } 1.121 + } 1.122 + 1.123 + win.close(); 1.124 + dmFile.remove(false); 1.125 + os.removeObserver(testObs, DLMGR_UI_DONE); 1.126 + SimpleTest.finish(); 1.127 + } 1.128 + } 1.129 + 1.130 + // Register with the observer service 1.131 + os.addObserver(testObs, DLMGR_UI_DONE, false); 1.132 + 1.133 + // Show the Download Manager UI 1.134 + dmui.show(); 1.135 + 1.136 + SimpleTest.waitForExplicitFinish(); 1.137 +} 1.138 + 1.139 + ]]> 1.140 + </script> 1.141 + 1.142 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.143 + <p id="display"></p> 1.144 + <div id="content" style="display:none;"></div> 1.145 + <pre id="test"></pre> 1.146 + </body> 1.147 +</window>