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 | * This tests that the Windows 7 Taskbar Progress is correctly updated when |
michael@0 | 7 | * windows are opened and closed. |
michael@0 | 8 | --> |
michael@0 | 9 | |
michael@0 | 10 | <window title="Win7 Taskbar Progress" |
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="utils.js"/> |
michael@0 | 18 | |
michael@0 | 19 | <script type="application/javascript"> |
michael@0 | 20 | <![CDATA[ |
michael@0 | 21 | |
michael@0 | 22 | const kTaskbarID = "@mozilla.org/windows-taskbar;1"; |
michael@0 | 23 | const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul"; |
michael@0 | 24 | const DLMGR_UI_DONE = "download-manager-ui-done"; |
michael@0 | 25 | |
michael@0 | 26 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 27 | |
michael@0 | 28 | let DownloadTaskbarProgress, TaskbarService, observerService, wwatch, chromeWindow; |
michael@0 | 29 | let gGen = null; |
michael@0 | 30 | |
michael@0 | 31 | function test() { |
michael@0 | 32 | var dmui = getDMUI(); |
michael@0 | 33 | if (!dmui) { |
michael@0 | 34 | todo(false, "skip test for toolkit download manager UI"); |
michael@0 | 35 | return; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | let isWin7OrHigher = false; |
michael@0 | 39 | try { |
michael@0 | 40 | let version = Cc["@mozilla.org/system-info;1"] |
michael@0 | 41 | .getService(Ci.nsIPropertyBag2) |
michael@0 | 42 | .getProperty("version"); |
michael@0 | 43 | isWin7OrHigher = (parseFloat(version) >= 6.1); |
michael@0 | 44 | } catch (ex) { } |
michael@0 | 45 | |
michael@0 | 46 | if (!isWin7OrHigher) { |
michael@0 | 47 | ok(true, "This test only runs on Windows 7 or higher"); |
michael@0 | 48 | return; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 52 | gGen = doTest(); |
michael@0 | 53 | gGen.next(); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | function continueTest() { |
michael@0 | 57 | gGen.next(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function doTest() { |
michael@0 | 61 | // Ensure that the download manager callbacks always use the window UI instead |
michael@0 | 62 | // of the panel in the browser's window. |
michael@0 | 63 | Services.prefs.setBoolPref("browser.download.useToolkitUI", true); |
michael@0 | 64 | |
michael@0 | 65 | let tempScope = {}; |
michael@0 | 66 | Components.utils.import("resource://gre/modules/DownloadTaskbarProgress.jsm", tempScope); |
michael@0 | 67 | |
michael@0 | 68 | DownloadTaskbarProgress = tempScope.DownloadTaskbarProgress; |
michael@0 | 69 | TaskbarService = Cc[kTaskbarID].getService(Ci.nsIWinTaskbar); |
michael@0 | 70 | |
michael@0 | 71 | observerService = Cc["@mozilla.org/observer-service;1"]. |
michael@0 | 72 | getService(Ci.nsIObserverService); |
michael@0 | 73 | |
michael@0 | 74 | wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"]. |
michael@0 | 75 | getService(Ci.nsIWindowWatcher); |
michael@0 | 76 | |
michael@0 | 77 | isnot(DownloadTaskbarProgress, null, "Download taskbar progress service exists"); |
michael@0 | 78 | is(TaskbarService.available, true, "Taskbar Service is available"); |
michael@0 | 79 | |
michael@0 | 80 | let DMWindow = getDMWindow(); |
michael@0 | 81 | if (DMWindow) |
michael@0 | 82 | DMWindow.close(); |
michael@0 | 83 | |
michael@0 | 84 | //Manually call onBrowserWindowLoad because this is delayed in 10sec |
michael@0 | 85 | chromeWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
michael@0 | 86 | getInterface(Components.interfaces.nsIWebNavigation). |
michael@0 | 87 | QueryInterface(Components.interfaces.nsIDocShellTreeItem). |
michael@0 | 88 | rootTreeItem. |
michael@0 | 89 | QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
michael@0 | 90 | getInterface(Components.interfaces.nsIDOMWindow); |
michael@0 | 91 | |
michael@0 | 92 | DownloadTaskbarProgress.onBrowserWindowLoad(chromeWindow); |
michael@0 | 93 | |
michael@0 | 94 | is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, false, |
michael@0 | 95 | "DownloadTaskbarProgress window is not the Download window"); |
michael@0 | 96 | |
michael@0 | 97 | checkActiveTaskbar(false, window); |
michael@0 | 98 | openDownloadManager(continueTest); |
michael@0 | 99 | yield; |
michael@0 | 100 | |
michael@0 | 101 | let DMWindow = getDMWindow(); |
michael@0 | 102 | |
michael@0 | 103 | ok(DMWindow, "Download Manager window was opened"); |
michael@0 | 104 | checkActiveTaskbar(true, DMWindow); |
michael@0 | 105 | |
michael@0 | 106 | DMWindow.close(); |
michael@0 | 107 | setTimeout(continueTest, 100); |
michael@0 | 108 | yield; |
michael@0 | 109 | |
michael@0 | 110 | checkActiveTaskbar(false, window); |
michael@0 | 111 | |
michael@0 | 112 | let browserWindow = openBrowserWindow(continueTest); |
michael@0 | 113 | yield; |
michael@0 | 114 | |
michael@0 | 115 | ok(browserWindow, "Browser window was opened"); |
michael@0 | 116 | DownloadTaskbarProgress.onBrowserWindowLoad(browserWindow); |
michael@0 | 117 | |
michael@0 | 118 | // The owner window should not have changed, since our |
michael@0 | 119 | // original window still exists |
michael@0 | 120 | checkActiveTaskbar(false, window); |
michael@0 | 121 | |
michael@0 | 122 | Services.prefs.clearUserPref("browser.download.useToolkitUI"); |
michael@0 | 123 | |
michael@0 | 124 | browserWindow.close(); |
michael@0 | 125 | SimpleTest.finish(); |
michael@0 | 126 | yield; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | function checkActiveTaskbar(isDownloadManager, ownerWindow) { |
michael@0 | 130 | |
michael@0 | 131 | isnot(DownloadTaskbarProgress.activeTaskbarProgress, null, "DownloadTaskbarProgress has an active taskbar"); |
michael@0 | 132 | |
michael@0 | 133 | is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, isDownloadManager, |
michael@0 | 134 | "The active taskbar progress " + (isDownloadManager ? "is" : "is not") + " the Download Manager"); |
michael@0 | 135 | |
michael@0 | 136 | if (ownerWindow) { |
michael@0 | 137 | let ownerWindowDocShell = ownerWindow.QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 138 | getInterface(Ci.nsIWebNavigation). |
michael@0 | 139 | QueryInterface(Ci.nsIDocShellTreeItem).treeOwner. |
michael@0 | 140 | QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 141 | getInterface(Ci.nsIXULWindow).docShell; |
michael@0 | 142 | |
michael@0 | 143 | let windowTaskbarProgress = TaskbarService.getTaskbarProgress(ownerWindowDocShell); |
michael@0 | 144 | |
michael@0 | 145 | is(DownloadTaskbarProgress.activeTaskbarProgress, windowTaskbarProgress, |
michael@0 | 146 | "DownloadTaskbarProgress has the expected taskbar as active"); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | function openBrowserWindow(callback) { |
michael@0 | 152 | |
michael@0 | 153 | let browserWindow = openDialog(chromeWindow.location, "_blank", |
michael@0 | 154 | "chrome,all,dialog=no", "about:blank"); |
michael@0 | 155 | |
michael@0 | 156 | let helperFunc = function() { |
michael@0 | 157 | callback(); |
michael@0 | 158 | browserWindow.removeEventListener("load", helperFunc, false); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | browserWindow.addEventListener("load", helperFunc, false); |
michael@0 | 162 | |
michael@0 | 163 | return browserWindow; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | function openDownloadManager(callback) { |
michael@0 | 167 | |
michael@0 | 168 | let testObs = { |
michael@0 | 169 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 170 | if (aTopic != DLMGR_UI_DONE) { |
michael@0 | 171 | return; |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | callback(); |
michael@0 | 175 | observerService.removeObserver(testObs, DLMGR_UI_DONE); |
michael@0 | 176 | } |
michael@0 | 177 | }; |
michael@0 | 178 | |
michael@0 | 179 | observerService.addObserver(testObs, DLMGR_UI_DONE, false); |
michael@0 | 180 | |
michael@0 | 181 | Cc["@mozilla.org/download-manager-ui;1"]. |
michael@0 | 182 | getService(Ci.nsIDownloadManagerUI).show(); |
michael@0 | 183 | |
michael@0 | 184 | } |
michael@0 | 185 | ]]> |
michael@0 | 186 | </script> |
michael@0 | 187 | |
michael@0 | 188 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 189 | <p id="display"></p> |
michael@0 | 190 | <div id="content" style="display:none;"></div> |
michael@0 | 191 | <pre id="test"></pre> |
michael@0 | 192 | </body> |
michael@0 | 193 | </window> |