Wed, 31 Dec 2014 06:09:35 +0100
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 for bug 419403 that lets the download manager support multiple word
7 * search against the download name, source/referrer, date/time, file size,
8 * etc.
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 function test()
24 {
25 var dmui = getDMUI();
26 if (!dmui) {
27 todo(false, "skip test for toolkit download manager UI");
28 return;
29 }
31 let dm = Cc["@mozilla.org/download-manager;1"].
32 getService(Ci.nsIDownloadManager);
33 let db = dm.DBConnection;
35 // Empty any old downloads
36 db.executeSimpleSQL("DELETE FROM moz_downloads");
38 // Make a file name for the downloads
39 let file = Cc["@mozilla.org/file/directory_service;1"].
40 getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
41 file.append("multiWord");
42 let filePath = Cc["@mozilla.org/network/io-service;1"].
43 getService(Ci.nsIIOService).newFileURI(file).spec;
45 let stmt = db.createStatement(
46 "INSERT INTO moz_downloads (name, target, source, state, endTime, maxBytes) " +
47 "VALUES (?1, ?2, ?3, ?4, ?5, ?6)");
49 try {
50 for each (let site in ["ed.agadak.net", "mozilla.org"]) {
51 stmt.bindStringParameter(0, "Super Pimped Download");
52 stmt.bindStringParameter(1, filePath);
53 stmt.bindStringParameter(2, "http://" + site + "/file");
54 stmt.bindInt32Parameter(3, dm.DOWNLOAD_FINISHED);
55 stmt.bindInt64Parameter(4, new Date(1985, 7, 2) * 1000);
56 stmt.bindInt64Parameter(5, 111222333444);
58 // Add it!
59 stmt.execute();
60 }
61 } finally {
62 stmt.reset();
63 stmt.finalize();
64 }
66 // Close the UI if necessary
67 let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
68 getService(Ci.nsIWindowMediator);
69 let win = wm.getMostRecentWindow("Download:Manager");
70 if (win) win.close();
72 let obs = Cc["@mozilla.org/observer-service;1"].
73 getService(Ci.nsIObserverService);
74 const DLMGR_UI_DONE = "download-manager-ui-done";
76 let testPhase = -1;
77 let testObs = {
78 observe: function(aSubject, aTopic, aData) {
79 if (aTopic != DLMGR_UI_DONE)
80 return;
82 let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
83 win.focus();
84 let $ = function(aId) win.document.getElementById(aId);
85 let downloadView = $("downloadView");
86 let searchbox = $("searchbox");
88 let search = function(aTerms) {
89 searchbox.value = aTerms;
90 searchbox.doCommand();
91 };
93 let testResults = function(aExpected) {
94 is(downloadView.itemCount, aExpected,
95 "Phase " + testPhase + ": search matched " + aExpected + " download(s)");
96 };
98 // The list must have built, so figure out what test to do
99 switch (++testPhase) {
100 case 0:
101 // Search for multiple words in any order in all places
102 search("download super pimped 104 GB august 2");
104 break;
105 case 1:
106 // Done populating the two items
107 testResults(2);
109 // Do partial word matches including the site
110 search("Agadak.net aug 2 downl 104");
112 break;
113 case 2:
114 // Done populating the one result
115 testResults(1);
117 // The search term shouldn't be treated like a regular expression,
118 // e.g. "D.wnload" shouldn't match "Download".
119 search("D.wnload");
121 break;
122 case 3:
123 testResults(0);
125 // We're done!
126 win.close();
127 obs.removeObserver(testObs, DLMGR_UI_DONE);
128 SimpleTest.finish();
130 break;
131 }
132 }
133 };
134 obs.addObserver(testObs, DLMGR_UI_DONE, false);
136 // Show the Download Manager UI
137 dmui.show();
139 SimpleTest.waitForExplicitFinish();
140 }
142 ]]>
143 </script>
145 <body xmlns="http://www.w3.org/1999/xhtml">
146 <p id="display"></p>
147 <div id="content" style="display:none;"></div>
148 <pre id="test"></pre>
149 </body>
150 </window>