toolkit/mozapps/downloads/tests/chrome/test_pause_button_state.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 - License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
michael@0 5 <!--
michael@0 6 * This tests bug 410289. Specifically, it tests that the pause button is
michael@0 7 * active for resumable downloads, and inactive for non-resumable ones.
michael@0 8 -->
michael@0 9
michael@0 10 <window title="Download Manager Test"
michael@0 11 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 12 onload="test();">
michael@0 13
michael@0 14 <script type="application/javascript"
michael@0 15 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 16 <script type="application/javascript"
michael@0 17 src="utils.js"/>
michael@0 18
michael@0 19 <script type="application/javascript">
michael@0 20 <![CDATA[
michael@0 21
michael@0 22 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
michael@0 23 var dmFile = Cc["@mozilla.org/file/directory_service;1"].
michael@0 24 getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
michael@0 25 dmFile.append("dm-ui-test.file");
michael@0 26 dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
michael@0 27 var gTestPath = ios.newFileURI(dmFile).spec;
michael@0 28
michael@0 29 const DownloadData = [
michael@0 30 { name: "Firefox 2.0.0.11.dmg",
michael@0 31 source: "http://mozilla-mirror.naist.jp//firefox/releases/2.0.0.11/mac/en-US/Firefox%202.0.0.11.dmg",
michael@0 32 target: gTestPath,
michael@0 33 startTime: 1200185939538521,
michael@0 34 endTime: 1200185939538521,
michael@0 35 entityID: "%22216c12-1116bd8-440070d5d2700%22/17918936/Thu, 29 Nov 2007 01:15:40 GMT",
michael@0 36 state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
michael@0 37 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
michael@0 38 { name: "Firefox 2.0.0.11.dmg",
michael@0 39 source: "http://mozilla-mirror.naist.jp//firefox/releases/2.0.0.11/mac/en-US/Firefox%202.0.0.11.dmg",
michael@0 40 target: gTestPath,
michael@0 41 startTime: 1200185939538520,
michael@0 42 endTime: 1200185939538520,
michael@0 43 entityID: "",
michael@0 44 state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
michael@0 45 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
michael@0 46 ];
michael@0 47
michael@0 48 function test()
michael@0 49 {
michael@0 50 var dmui = getDMUI();
michael@0 51 if (!dmui) {
michael@0 52 todo(false, "skip test for toolkit download manager UI");
michael@0 53 return;
michael@0 54 }
michael@0 55
michael@0 56 var dm = Cc["@mozilla.org/download-manager;1"].
michael@0 57 getService(Ci.nsIDownloadManager);
michael@0 58 var db = dm.DBConnection;
michael@0 59
michael@0 60 // First, we populate the database with some fake data
michael@0 61 db.executeSimpleSQL("DELETE FROM moz_downloads");
michael@0 62 var stmt = db.createStatement(
michael@0 63 "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
michael@0 64 "state, currBytes, maxBytes, preferredAction, autoResume, entityID) " +
michael@0 65 "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
michael@0 66 ":currBytes, :maxBytes, :preferredAction, :autoResume, :entityID)");
michael@0 67 for each (var dl in DownloadData) {
michael@0 68 for (var prop in dl)
michael@0 69 stmt.params[prop] = dl[prop];
michael@0 70
michael@0 71 stmt.execute();
michael@0 72 }
michael@0 73 stmt.finalize();
michael@0 74
michael@0 75 // See if the DM is already open, and if it is, close it!
michael@0 76 var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
michael@0 77 getService(Ci.nsIWindowMediator);
michael@0 78 var win = wm.getMostRecentWindow("Download:Manager");
michael@0 79 if (win)
michael@0 80 win.close();
michael@0 81
michael@0 82 let os = Cc["@mozilla.org/observer-service;1"].
michael@0 83 getService(Ci.nsIObserverService);
michael@0 84 const DLMGR_UI_DONE = "download-manager-ui-done";
michael@0 85
michael@0 86 let testObs = {
michael@0 87 observe: function(aSubject, aTopic, aData)
michael@0 88 {
michael@0 89 if (aTopic != DLMGR_UI_DONE)
michael@0 90 return;
michael@0 91
michael@0 92 let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
michael@0 93 win.focus();
michael@0 94 let doc = win.document;
michael@0 95
michael@0 96 let richlistbox = doc.getElementById("downloadView");
michael@0 97 for (let i = 0; i < DownloadData.length; i++) {
michael@0 98 let dl = richlistbox.children[i];
michael@0 99 let buttons = dl.buttons;
michael@0 100 for (let j = 0; j < buttons.length; j++) {
michael@0 101 let button = buttons[j];
michael@0 102 if ("cmd_pause" == button.getAttribute("cmd")) {
michael@0 103 let id = dl.getAttribute("dlid");
michael@0 104
michael@0 105 // check if it should be disabled or not
michael@0 106 let resumable = dm.getDownload(id).resumable;
michael@0 107 is(DownloadData[i].entityID ? true : false, resumable,
michael@0 108 "Pause button is properly disabled");
michael@0 109
michael@0 110 // also check if tooltip text was updated
michael@0 111 if (!resumable) {
michael@0 112 let sb = doc.getElementById("downloadStrings");
michael@0 113 is(button.getAttribute("tooltiptext"), sb.getString("cannotPause"),
michael@0 114 "Pause button has proper text");
michael@0 115 }
michael@0 116 }
michael@0 117 }
michael@0 118 }
michael@0 119
michael@0 120 win.close();
michael@0 121 dmFile.remove(false);
michael@0 122 os.removeObserver(testObs, DLMGR_UI_DONE);
michael@0 123 SimpleTest.finish();
michael@0 124 }
michael@0 125 }
michael@0 126
michael@0 127 // Register with the observer service
michael@0 128 os.addObserver(testObs, DLMGR_UI_DONE, false);
michael@0 129
michael@0 130 // Show the Download Manager UI
michael@0 131 dmui.show();
michael@0 132
michael@0 133 SimpleTest.waitForExplicitFinish();
michael@0 134 }
michael@0 135
michael@0 136 ]]>
michael@0 137 </script>
michael@0 138
michael@0 139 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 140 <p id="display"></p>
michael@0 141 <div id="content" style="display:none;"></div>
michael@0 142 <pre id="test"></pre>
michael@0 143 </body>
michael@0 144 </window>

mercurial