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.

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

mercurial