toolkit/mozapps/downloads/tests/chrome/test_basic_functionality.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  * Make sure the download manager can display downloads in the right order and
     7  * contains the expected data. The list has one of each download state ordered
     8  * by the start/end times.
     9 -->
    11 <window title="Download Manager Test"
    12         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    13         onload="test();">
    15   <script type="application/javascript"
    16           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    17   <script type="application/javascript"
    18           src="utils.js"/>
    20   <script type="application/javascript">
    21   <![CDATA[
    23 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    24 var dmFile = Cc["@mozilla.org/file/directory_service;1"].
    25              getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
    26 dmFile.append("dm-ui-test.file");
    27 dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    28 var gTestPath = ios.newFileURI(dmFile).spec;
    30 // Downloads are sorted by endTime, so make sure the end times are distinct
    31 const DownloadData = [
    32   /* Active states first */
    33   { name: "381603.patch",
    34     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    35     target: gTestPath,
    36     startTime: 1180493839859230,
    37     endTime: 1180493839859239,
    38     state: Ci.nsIDownloadManager.DOWNLOAD_NOTSTARTED,
    39     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    40   { name: "381603.patch",
    41     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    42     target: gTestPath,
    43     startTime: 1180493839859230,
    44     endTime: 1180493839859238,
    45     state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
    46     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    47   { name: "381603.patch",
    48     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    49     target: gTestPath,
    50     startTime: 1180493839859230,
    51     endTime: 1180493839859237,
    52     state: Ci.nsIDownloadManager.DOWNLOAD_PAUSED,
    53     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    54   { name: "381603.patch",
    55     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    56     target: gTestPath,
    57     startTime: 1180493839859230,
    58     endTime: 1180493839859236,
    59     state: Ci.nsIDownloadManager.DOWNLOAD_SCANNING,
    60     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    61   { name: "381603.patch",
    62     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    63     target: gTestPath,
    64     startTime: 1180493839859230,
    65     endTime: 1180493839859235,
    66     state: Ci.nsIDownloadManager.DOWNLOAD_QUEUED,
    67     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    68   /* Finished states */
    69   { name: "381603.patch",
    70     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    71     target: gTestPath,
    72     startTime: 1180493839859230,
    73     endTime: 1180493839859234,
    74     state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
    75     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    76   { name: "381603.patch",
    77     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    78     target: gTestPath,
    79     startTime: 1180493839859230,
    80     endTime: 1180493839859233,
    81     state: Ci.nsIDownloadManager.DOWNLOAD_FAILED,
    82     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    83   { name: "381603.patch",
    84     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    85     target: gTestPath,
    86     startTime: 1180493839859230,
    87     endTime: 1180493839859232,
    88     state: Ci.nsIDownloadManager.DOWNLOAD_CANCELED,
    89     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    90   { name: "381603.patch",
    91     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    92     target: gTestPath,
    93     startTime: 1180493839859230,
    94     endTime: 1180493839859231,
    95     state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL,
    96     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
    97   { name: "381603.patch",
    98     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    99     target: gTestPath,
   100     startTime: 1180493839859230,
   101     endTime: 1180493839859230,
   102     state: Ci.nsIDownloadManager.DOWNLOAD_DIRTY,
   103     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 },
   104   { name: "381603.patch",
   105     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
   106     target: gTestPath,
   107     startTime: 1180493839859229,
   108     endTime: 1180493839859229,
   109     state: Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY,
   110     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
   111 ];
   113 function test_numberOfRichlistitems(aWin)
   114 {
   115   var doc = aWin.document;
   116   var richlistbox = doc.getElementById("downloadView");
   117   is(richlistbox.children.length, DownloadData.length,
   118      "There is the correct number of richlistitems");
   119 }
   121 function test_properDownloadData(aWin)
   122 {
   123   // This also tests the ordering of the display
   124   var doc = aWin.document;
   125   var richlistbox = doc.getElementById("downloadView");
   126   for (var i = 0; i < richlistbox.children.length; i++) {
   127     var elm = richlistbox.children[i];
   128     is(elm.getAttribute("target"), DownloadData[i].name,
   129        "Download names match up");
   130     is(elm.getAttribute("state"), DownloadData[i].state,
   131        "Download states match up");
   132     is(elm.getAttribute("file"), DownloadData[i].target,
   133        "Download targets match up");
   134     is(elm.getAttribute("uri"), DownloadData[i].source,
   135        "Download sources match up");
   136   }
   137 }
   139 var testFuncs = [
   140     test_numberOfRichlistitems
   141   , test_properDownloadData
   142 ];
   144 function test()
   145 {
   146   var dmui = getDMUI();
   147   if (!dmui) {
   148     todo(false, "skip test for toolkit download manager UI");
   149     return;
   150   }
   152   var dm = Cc["@mozilla.org/download-manager;1"].
   153            getService(Ci.nsIDownloadManager);
   154   var db = dm.DBConnection;
   156   // First, we populate the database with some fake data
   157   db.executeSimpleSQL("DELETE FROM moz_downloads");
   158   var stmt = db.createStatement(
   159     "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
   160       "state, currBytes, maxBytes, preferredAction, autoResume) " +
   161     "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
   162       ":currBytes, :maxBytes, :preferredAction, :autoResume)");
   163   for each (var dl in DownloadData) {
   164     for (var prop in dl)
   165       stmt.params[prop] = dl[prop];
   167     stmt.execute();
   168   }
   169   stmt.finalize();
   171   // See if the DM is already open, and if it is, close it!
   172   var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
   173            getService(Ci.nsIWindowMediator);
   174   var win = wm.getMostRecentWindow("Download:Manager");
   175   if (win)
   176     win.close();
   178   let os = Cc["@mozilla.org/observer-service;1"].
   179            getService(Ci.nsIObserverService);
   180   const DLMGR_UI_DONE = "download-manager-ui-done";
   182   let testObs = {
   183     observe: function(aSubject, aTopic, aData)
   184     {
   185       if (aTopic != DLMGR_UI_DONE)
   186         return;
   188       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
   189       win.focus();
   191       // Now we can run our tests
   192       for each (let t in testFuncs)
   193         t(win);
   195       win.close();
   196       dmFile.remove(false);
   197       os.removeObserver(testObs, DLMGR_UI_DONE);
   198       SimpleTest.finish();
   199     }
   200   };
   202   // Register with the observer service
   203   os.addObserver(testObs, DLMGR_UI_DONE, false);
   205   // Show the Download Manager UI
   206   dmui.show();
   208   SimpleTest.waitForExplicitFinish();
   209 }
   211   ]]>
   212   </script>
   214   <body xmlns="http://www.w3.org/1999/xhtml">
   215     <p id="display"></p>
   216     <div id="content" style="display:none;"></div>
   217     <pre id="test"></pre>
   218   </body>
   219 </window>

mercurial