toolkit/mozapps/downloads/tests/chrome/test_removeDownload_updates_ui.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 * Test bug 394039 to make sure calling removeDownload of the
michael@0 7 * nsIDownloadManager service correctly updates the download window.
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: "381603.patch",
michael@0 31 source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
michael@0 32 target: gTestPath,
michael@0 33 startTime: 1180493839859230,
michael@0 34 endTime: 1180493839859239,
michael@0 35 state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
michael@0 36 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
michael@0 37 ];
michael@0 38
michael@0 39 function test()
michael@0 40 {
michael@0 41 var dmui = getDMUI();
michael@0 42 if (!dmui) {
michael@0 43 todo(false, "skip test for toolkit download manager UI");
michael@0 44 return;
michael@0 45 }
michael@0 46
michael@0 47 var dm = Cc["@mozilla.org/download-manager;1"].
michael@0 48 getService(Ci.nsIDownloadManager);
michael@0 49 var db = dm.DBConnection;
michael@0 50
michael@0 51 // First, we populate the database with some fake data
michael@0 52 db.executeSimpleSQL("DELETE FROM moz_downloads");
michael@0 53 var stmt = db.createStatement(
michael@0 54 "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
michael@0 55 "state, currBytes, maxBytes, preferredAction, autoResume) " +
michael@0 56 "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
michael@0 57 ":currBytes, :maxBytes, :preferredAction, :autoResume)");
michael@0 58 for each (var dl in DownloadData) {
michael@0 59 for (var prop in dl)
michael@0 60 stmt.params[prop] = dl[prop];
michael@0 61
michael@0 62 stmt.execute();
michael@0 63 }
michael@0 64 stmt.finalize();
michael@0 65
michael@0 66 // See if the DM is already open, and if it is, close it!
michael@0 67 var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
michael@0 68 getService(Ci.nsIWindowMediator);
michael@0 69 var win = wm.getMostRecentWindow("Download:Manager");
michael@0 70 if (win)
michael@0 71 win.close();
michael@0 72
michael@0 73 let os = Cc["@mozilla.org/observer-service;1"].
michael@0 74 getService(Ci.nsIObserverService);
michael@0 75 const DLMGR_UI_DONE = "download-manager-ui-done";
michael@0 76
michael@0 77 let testObs = {
michael@0 78 observe: function(aSubject, aTopic, aData)
michael@0 79 {
michael@0 80 if (aTopic != DLMGR_UI_DONE)
michael@0 81 return;
michael@0 82
michael@0 83 let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
michael@0 84 win.focus();
michael@0 85 let doc = win.document;
michael@0 86
michael@0 87 // Note: This also tests the ordering of the display
michael@0 88 let stmt = db.createStatement("SELECT id FROM moz_downloads");
michael@0 89 let id = -1;
michael@0 90 try {
michael@0 91 stmt.executeStep();
michael@0 92 id = stmt.getInt64(0);
michael@0 93 }
michael@0 94 finally {
michael@0 95 stmt.reset();
michael@0 96 stmt.finalize();
michael@0 97 }
michael@0 98
michael@0 99 dm.removeDownload(id);
michael@0 100 let richlistbox = doc.getElementById("downloadView");
michael@0 101 is(richlistbox.children.length, 0,
michael@0 102 "The download was properly removed");
michael@0 103
michael@0 104 win.close();
michael@0 105 dmFile.remove(false);
michael@0 106 os.removeObserver(testObs, DLMGR_UI_DONE);
michael@0 107 SimpleTest.finish();
michael@0 108 }
michael@0 109 }
michael@0 110
michael@0 111 // Register with the observer service
michael@0 112 os.addObserver(testObs, DLMGR_UI_DONE, false);
michael@0 113
michael@0 114 // Show the Download Manager UI
michael@0 115 dmui.show();
michael@0 116
michael@0 117 SimpleTest.waitForExplicitFinish();
michael@0 118 }
michael@0 119
michael@0 120 ]]>
michael@0 121 </script>
michael@0 122
michael@0 123 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 124 <p id="display"></p>
michael@0 125 <div id="content" style="display:none;"></div>
michael@0 126 <pre id="test"></pre>
michael@0 127 </body>
michael@0 128 </window>

mercurial