toolkit/mozapps/downloads/tests/chrome/test_bug_462172.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  * Assure download manager can load valid list item as
     7  * "application/moz-x-file"
     9 https://bugzilla.mozilla.org/show_bug.cgi?id=462172
    11 create a file with unique name
    12 create another file with unique name and delete it
    13 load into downloads database
    14 open download manager
    15 synthesize drag on both files
    16 missing file should not init drag
    17 real file should return transferdata with application/x-moz-file
    18 close window
    20 -->
    21 <window title="Mozilla Bug 462172"
    22         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    23         onload="test();">
    24   <script type="application/javascript"
    25           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    26   <script type="application/javascript"
    27           src="utils.js"/>
    28   <script type="application/javascript"
    29           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    30   <script type="application/javascript"
    31           src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
    32   <script type="application/javascript">
    33   <![CDATA[
    35   /** Test for Bug 462172 **/
    36 var missingFileElid;
    37 var realFileElid;
    38 const kFiller = "notApplicable";
    39 const kFillerURL = "https://bugzilla.mozilla.org/show_bug.cgi?id=462172"
    40 var realFile = Cc["@mozilla.org/file/directory_service;1"].
    41                   getService(Ci.nsIProperties).get("CurWorkD", Ci.nsIFile);
    42 var missingFile = Cc["@mozilla.org/file/directory_service;1"].
    43                      getService(Ci.nsIProperties).get("CurWorkD", Ci.nsIFile);
    45 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    47 realFile.append(kFiller);
    48 realFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    49 var realFilePath = ios.newFileURI(realFile).spec;
    51 missingFile.append(kFiller);
    52 missingFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    53 var missingFilePath = ios.newFileURI(missingFile).spec;
    54 missingFile.remove(false);
    56 // Dummy data for our files.
    57 // 'source' field must be in form of an URL.
    58 const DownloadData = [
    59   { name: kFiller,
    60     source: kFillerURL,
    61     target: realFilePath,
    62     state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED},
    63   { name: kFiller,
    64     source: kFillerURL,
    65     target: missingFilePath,
    66     state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED}
    67 ];
    69 function compareStrFunc(actualData, expectedData) {
    70   return expectedData === actualData;
    71 }
    73 function compareFunc(actualData, expectedData) {
    74   return expectedData.equals(actualData);
    75 }
    77 var dragRealFile = [[
    78   { type  :"application/x-moz-file",
    79     data  : realFile,
    80     eqTest  : compareFunc },
    81   { type  : "text/uri-list",
    82     data  : realFilePath,
    83     eqTest  : compareStrFunc },
    84   { type  : "text/plain",
    85     data  : realFilePath,
    86     eqTest  : compareStrFunc }
    87 ]];
    88 var dragMissingFile = [[
    89   { type  :"application/x-moz-file",
    90     data  : missingFile,
    91     eqTest  : compareFunc },
    92   { type  : "text/uri-list",
    93     data  : missingFilePath,
    94     eqTest  : compareStrFunc },
    95   { type  : "text/plain",
    96     data  : missingFilePath,
    97     eqTest  : compareStrFunc }
    98 ]];
   100 function test() {
   102   var dmui = getDMUI();
   103   if (!dmui) {
   104     todo(false, "skip test for toolkit download manager UI");
   105     return;
   106   }
   108   // load files into db
   109   var dm = Cc["@mozilla.org/download-manager;1"].
   110            getService(Ci.nsIDownloadManager);
   111   var db = dm.DBConnection;
   113   var stmt = db.createStatement(
   114     "INSERT INTO moz_downloads ( name,  source,  target,  state)" +
   115     "VALUES                    (:name, :source, :target, :state)");
   116   for each (var dl in DownloadData) {
   117     for (var prop in dl)
   118       stmt.params[prop] = dl[prop];
   119     stmt.execute();
   120     if (dl.target == missingFilePath)
   121       missingFileElid = "dl" + db.lastInsertRowID;
   122     else if (dl.target == realFilePath)
   123       realFileElid = "dl" + db.lastInsertRowID;
   124   }
   125   stmt.finalize();
   127   // See if the DM is already open, and if it is, close it!
   128   var win = getDMWindow();
   129   if (win) win.close();
   131   var os = Cc["@mozilla.org/observer-service;1"].
   132            getService(Ci.nsIObserverService);
   133   const DLMGR_UI_DONE = "download-manager-ui-done";
   135   var testObs = {
   136     observe: function(aSubject, aTopic, aData) {
   137       if (aTopic != DLMGR_UI_DONE)
   138         return;
   140       var win = aSubject.QueryInterface(Ci.nsIDOMWindow);
   141       win.focus();
   143       // Now we can run our tests
   144       var result = synthesizeDragStart(win.document.getElementById(realFileElid), dragRealFile, win);
   145       is(result, null, "Checking for Real file match");
   146       result = synthesizeDragStart(win.document.getElementById(missingFileElid), dragMissingFile, win);
   147       isnot(result, null, "Drag start did not return item for missing file");
   149       // Done.
   150       win.close();
   151       realFile.remove(false);
   152       os.removeObserver(testObs, DLMGR_UI_DONE);
   153       SimpleTest.finish();
   154     }
   155   };
   157   // Register with the observer service
   158   os.addObserver(testObs, DLMGR_UI_DONE, false);
   160   // Show the Download Manager UI
   161   dmui.show();
   163   SimpleTest.waitForExplicitFinish();
   164 }
   166   ]]>
   167   </script>
   169   <body xmlns="http://www.w3.org/1999/xhtml">
   170     <p id="display"></p>
   171     <div id="content" style="display:none;"></div>
   172     <pre id="test"></pre>
   173   </body>
   174 </window>

mercurial