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.

     1 <?xml version="1.0"?>
     2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     3    - License, v. 2.0. If a copy of the MPL was not distributed with this
     4    - file, You can obtain one at http://mozilla.org/MPL/2.0/.  -->
     5 <!--
     6  * Test bug 394039 to make sure calling removeDownload of the
     7  * nsIDownloadManager service correctly updates the download window.
     8 -->
    10 <window title="Download Manager Test"
    11         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    12         onload="test();">
    14   <script type="application/javascript"
    15           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    16   <script type="application/javascript"
    17           src="utils.js"/>
    19   <script type="application/javascript">
    20   <![CDATA[
    22 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    23 var dmFile = Cc["@mozilla.org/file/directory_service;1"].
    24              getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
    25 dmFile.append("dm-ui-test.file");
    26 dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    27 var gTestPath = ios.newFileURI(dmFile).spec;
    29 const DownloadData = [
    30   { name: "381603.patch",
    31     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    32     target: gTestPath,
    33     startTime: 1180493839859230,
    34     endTime: 1180493839859239,
    35     state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
    36     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
    37 ];
    39 function test()
    40 {
    41   var dmui = getDMUI();
    42   if (!dmui) {
    43     todo(false, "skip test for toolkit download manager UI");
    44     return;
    45   }
    47   var dm = Cc["@mozilla.org/download-manager;1"].
    48            getService(Ci.nsIDownloadManager);
    49   var db = dm.DBConnection;
    51   // First, we populate the database with some fake data
    52   db.executeSimpleSQL("DELETE FROM moz_downloads");
    53   var stmt = db.createStatement(
    54     "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
    55       "state, currBytes, maxBytes, preferredAction, autoResume) " +
    56     "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
    57       ":currBytes, :maxBytes, :preferredAction, :autoResume)");
    58   for each (var dl in DownloadData) {
    59     for (var prop in dl)
    60       stmt.params[prop] = dl[prop];
    62     stmt.execute();
    63   }
    64   stmt.finalize();
    66   // See if the DM is already open, and if it is, close it!
    67   var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
    68            getService(Ci.nsIWindowMediator);
    69   var win = wm.getMostRecentWindow("Download:Manager");
    70   if (win)
    71     win.close();
    73   let os = Cc["@mozilla.org/observer-service;1"].
    74            getService(Ci.nsIObserverService);
    75   const DLMGR_UI_DONE = "download-manager-ui-done";
    77   let testObs = {
    78     observe: function(aSubject, aTopic, aData)
    79     {
    80       if (aTopic != DLMGR_UI_DONE)
    81         return;
    83       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    84       win.focus();
    85       let doc = win.document;
    87       // Note: This also tests the ordering of the display
    88       let stmt = db.createStatement("SELECT id FROM moz_downloads");
    89       let id = -1;
    90       try {
    91         stmt.executeStep();
    92         id = stmt.getInt64(0);
    93       }
    94       finally {
    95         stmt.reset();
    96         stmt.finalize();
    97       }
    99       dm.removeDownload(id);
   100       let richlistbox = doc.getElementById("downloadView");
   101       is(richlistbox.children.length, 0,
   102          "The download was properly removed");
   104       win.close();
   105       dmFile.remove(false);
   106       os.removeObserver(testObs, DLMGR_UI_DONE);
   107       SimpleTest.finish();
   108     }
   109   }
   111   // Register with the observer service
   112   os.addObserver(testObs, DLMGR_UI_DONE, false);
   114   // Show the Download Manager UI
   115   dmui.show();
   117   SimpleTest.waitForExplicitFinish();
   118 }
   120   ]]>
   121   </script>
   123   <body xmlns="http://www.w3.org/1999/xhtml">
   124     <p id="display"></p>
   125     <div id="content" style="display:none;"></div>
   126     <pre id="test"></pre>
   127   </body>
   128 </window>

mercurial