PageRenderTime 13ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/toolkit/mozapps/downloads/tests/chrome/test_taskbarprogress_service.xul

http://github.com/zpao/v8monkey
Unknown | 215 lines | 167 code | 48 blank | 0 comment | 0 complexity | 664a096d4925e5381f7a91dad2d7d988 MD5 | raw file
  1<?xml version="1.0"?>
  2<!--
  3/* ***** BEGIN LICENSE BLOCK *****
  4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5 *
  6 * The contents of this file are subject to the Mozilla Public License Version
  7 * 1.1 (the "License"); you may not use this file except in compliance with
  8 * the License. You may obtain a copy of the License at
  9 * http://www.mozilla.org/MPL/
 10 *
 11 * Software distributed under the License is distributed on an "AS IS" basis,
 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 13 * for the specific language governing rights and limitations under the
 14 * License.
 15 *
 16 * The Original Code is Windows Download Taskbar Progress.
 17 *
 18 * The Initial Developer of the Original Code is
 19 * the Mozilla Foundation.
 20 * Portions created by the Initial Developer are Copyright (C) 2010
 21 * the Initial Developer. All Rights Reserved.
 22 *
 23 * Contributor(s):
 24 *   Felipe Gomes <felipc@gmail.com>
 25 *
 26 * Alternatively, the contents of this file may be used under the terms of
 27 * either the GNU General Public License Version 2 or later (the "GPL"), or
 28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 29 * in which case the provisions of the GPL or the LGPL are applicable instead
 30 * of those above. If you wish to allow use of your version of this file only
 31 * under the terms of either the GPL or the LGPL, and not to allow others to
 32 * use your version of this file under the terms of the MPL, indicate your
 33 * decision by deleting the provisions above and replace them with the notice
 34 * and other provisions required by the GPL or the LGPL. If you do not delete
 35 * the provisions above, a recipient may use your version of this file under
 36 * the terms of any one of the MPL, the GPL or the LGPL.
 37 *
 38 * ***** END LICENSE BLOCK ***** */
 39
 40/**
 41 * This tests that the Windows 7 Taskbar Progress is correctly updated when
 42 * windows are opened and closed.
 43 */
 44-->
 45
 46<window title="Win7 Taskbar Progress"
 47        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
 48        onload="test();">
 49
 50  <script type="application/javascript"
 51          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
 52  <script type="application/javascript"
 53          src="utils.js"/>
 54
 55  <script type="application/javascript">
 56  <![CDATA[
 57
 58const kTaskbarID = "@mozilla.org/windows-taskbar;1";
 59const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul";
 60const DLMGR_UI_DONE = "download-manager-ui-done";
 61
 62let DownloadTaskbarProgress, TaskbarService, observerService, wwatch, chromeWindow;
 63let gGen = null;
 64
 65function test() {
 66  let isWin7OrHigher = false;
 67  try {
 68    let version = Cc["@mozilla.org/system-info;1"]
 69                    .getService(Ci.nsIPropertyBag2)
 70                    .getProperty("version");
 71    isWin7OrHigher = (parseFloat(version) >= 6.1);
 72  } catch (ex) { }
 73
 74  if (!isWin7OrHigher) {
 75    return;
 76  }
 77
 78  SimpleTest.waitForExplicitFinish();
 79  gGen = doTest();
 80  gGen.next();
 81}
 82
 83function continueTest() {
 84  gGen.next();
 85}
 86
 87function doTest() {
 88
 89  let tempScope = {};
 90  Components.utils.import("resource://gre/modules/DownloadTaskbarProgress.jsm", tempScope);
 91
 92  DownloadTaskbarProgress = tempScope.DownloadTaskbarProgress;
 93  TaskbarService =  Cc[kTaskbarID].getService(Ci.nsIWinTaskbar);
 94
 95  observerService = Cc["@mozilla.org/observer-service;1"].
 96                      getService(Ci.nsIObserverService);
 97
 98  wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].
 99             getService(Ci.nsIWindowWatcher);
100
101  isnot(DownloadTaskbarProgress, null, "Download taskbar progress service exists");
102  is(TaskbarService.available, true, "Taskbar Service is available");
103
104  let DMWindow = getDMWindow();
105  if (DMWindow)
106    DMWindow.close();
107
108  //Manually call onBrowserWindowLoad because this is delayed in 10sec
109  chromeWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
110                   getInterface(Components.interfaces.nsIWebNavigation).
111                   QueryInterface(Components.interfaces.nsIDocShellTreeItem).
112                   rootTreeItem.
113                   QueryInterface(Components.interfaces.nsIInterfaceRequestor).
114                   getInterface(Components.interfaces.nsIDOMWindow);
115
116  DownloadTaskbarProgress.onBrowserWindowLoad(chromeWindow);
117
118  is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, false,
119     "DownloadTaskbarProgress window is not the Download window");
120
121  checkActiveTaskbar(false, window);
122  openDownloadManager(continueTest);
123  yield;
124
125  let DMWindow = getDMWindow();
126
127  ok(DMWindow, "Download Manager window was opened");
128  checkActiveTaskbar(true, DMWindow);
129
130  DMWindow.close();
131  setTimeout(continueTest, 100);
132  yield;
133
134  checkActiveTaskbar(false, window);
135
136  let browserWindow = openBrowserWindow(continueTest);
137  yield;
138
139  ok(browserWindow, "Browser window was opened");
140  DownloadTaskbarProgress.onBrowserWindowLoad(browserWindow);
141
142  // The owner window should not have changed, since our
143  // original window still exists
144  checkActiveTaskbar(false, window);
145
146  browserWindow.close();
147  SimpleTest.finish();
148  yield;
149}
150
151function checkActiveTaskbar(isDownloadManager, ownerWindow) {
152
153  isnot(DownloadTaskbarProgress.activeTaskbarProgress, null, "DownloadTaskbarProgress has an active taskbar");
154
155  is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, isDownloadManager,
156     "The active taskbar progress " + (isDownloadManager ? "is" : "is not") + " the Download Manager");
157
158  if (ownerWindow) {
159    let ownerWindowDocShell = ownerWindow.QueryInterface(Ci.nsIInterfaceRequestor).
160                                getInterface(Ci.nsIWebNavigation).
161                                QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.
162                                QueryInterface(Ci.nsIInterfaceRequestor).
163                                getInterface(Ci.nsIXULWindow).docShell;
164
165    let windowTaskbarProgress = TaskbarService.getTaskbarProgress(ownerWindowDocShell);
166
167    is(DownloadTaskbarProgress.activeTaskbarProgress, windowTaskbarProgress,
168       "DownloadTaskbarProgress has the expected taskbar as active");
169  }
170
171}
172
173function openBrowserWindow(callback) {
174
175  let browserWindow = openDialog(chromeWindow.location, "_blank",
176                                 "chrome,all,dialog=no", "about:blank");
177 
178  let helperFunc = function() {
179    callback();
180    browserWindow.removeEventListener("load", helperFunc, false);
181  }
182
183  browserWindow.addEventListener("load", helperFunc, false);
184
185  return browserWindow;
186}
187
188function openDownloadManager(callback) {
189
190  let testObs = {
191    observe: function(aSubject, aTopic, aData) {
192      if (aTopic != DLMGR_UI_DONE) {
193        return;
194      }
195
196      callback();
197      observerService.removeObserver(testObs, DLMGR_UI_DONE);
198    }
199  };
200
201  observerService.addObserver(testObs, DLMGR_UI_DONE, false);
202
203  Cc["@mozilla.org/download-manager-ui;1"].
204    getService(Ci.nsIDownloadManagerUI).show();
205
206}
207  ]]>
208  </script>
209
210  <body xmlns="http://www.w3.org/1999/xhtml">
211    <p id="display"></p>
212    <div id="content" style="display:none;"></div>
213    <pre id="test"></pre>
214  </body>
215</window>