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