toolkit/mozapps/downloads/tests/chrome/test_bug_429247.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 429247 to make sure clicking on whitespace in the Download
     7  * Manager doesn't run the default action on the selected download.
     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="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    18   <script type="application/javascript"
    19           src="utils.js"/>
    21   <script type="application/javascript">
    22   <![CDATA[
    24 function test()
    25 {
    26   var dmui = getDMUI();
    27   if (!dmui) {
    28     todo(false, "skip test for toolkit download manager UI");
    29     return;
    30   }
    32   let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    33   let dmFile = Cc["@mozilla.org/file/directory_service;1"].
    34                getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
    35   dmFile.append("dm-ui-test.file");
    36   dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    37   let gTestPath = ios.newFileURI(dmFile).spec;
    39   // Data to populate the download manager with
    40   const DownloadData = {
    41     name: "381603.patch",
    42     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    43     target: gTestPath,
    44     startTime: 1180493839859230,
    45     endTime: 1180493839859239,
    46     state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
    47     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0
    48   }
    50   let dm = Cc["@mozilla.org/download-manager;1"].
    51            getService(Ci.nsIDownloadManager);
    52   let db = dm.DBConnection;
    54   // Empty any old downloads
    55   db.executeSimpleSQL("DELETE FROM moz_downloads");
    57   let stmt = db.createStatement(
    58     "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
    59       "state, currBytes, maxBytes, preferredAction, autoResume) " +
    60     "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
    61       ":currBytes, :maxBytes, :preferredAction, :autoResume)");
    62   for (let prop in DownloadData)
    63     stmt.params[prop] = DownloadData[prop];
    65   stmt.execute();
    66   stmt.finalize();
    68   // Close the UI if necessary
    69   let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
    70            getService(Ci.nsIWindowMediator);
    71   let win = wm.getMostRecentWindow("Download:Manager");
    72   if (win) win.close();
    74   let obs = Cc["@mozilla.org/observer-service;1"].
    75             getService(Ci.nsIObserverService);
    76   const DLMGR_UI_DONE = "download-manager-ui-done";
    78   let testObs = {
    79     observe: function(aSubject, aTopic, aData) {
    80       if (aTopic != DLMGR_UI_DONE)
    81         return;
    83       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    84       win.focus();
    85       let $ = function(aId) win.document.getElementById(aId);
    86       let downloadView = $("downloadView");
    88       // Default test/check for invocations
    89       let invokeCount = 0;
    90       let counter = function() invokeCount++;
    92       // Array of tests that consist of the download manager
    93       // function to temporarily replace, method to use in its place, value to
    94       // use when checking correctness
    95       let defaultForSelectedTest = ["doDefaultForSelected", counter, counter];
    97       // All the expected results
    98       let allExpected = [0, "The default action was not performed"];
   100       // Select the first download
   101       downloadView.selectedIndex = 0;
   103       let [func, test, value] = defaultForSelectedTest;
   104       // Make a copy of the original function and replace it with a test
   105       let copy = win[func];
   106       win[func] = test;
   108       // Get the offsetY of the whitespace under the download
   109       let downloadItem = downloadView.getItemAtIndex(0);
   110       let boxOffset = downloadItem.boxObject.height + 1;
   111       // The last download in the download manager + 1 is whitespace
   112       synthesizeMouse(downloadItem, 0, boxOffset, {clickCount: 2}, win);
   114       // Make sure the value is as expected
   115       let [correct, message] = allExpected;
   116       ok(value() == correct, message);
   118       // Restore original values
   119       invokeCount = 0;
   120       win[func] = copy;
   122       // We're done!
   123       win.close();
   124       obs.removeObserver(testObs, DLMGR_UI_DONE);
   125       SimpleTest.finish();
   126     }
   127   };
   128   obs.addObserver(testObs, DLMGR_UI_DONE, false);
   130   // Show the Download Manager UI
   131   dmui.show();
   133   SimpleTest.waitForExplicitFinish();
   134 }
   136   ]]>
   137   </script>
   139   <body xmlns="http://www.w3.org/1999/xhtml">
   140     <p id="display"></p>
   141     <div id="content" style="display:none;"></div>
   142     <pre id="test"></pre>
   143   </body>
   144 </window>

mercurial