/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. * This tests that the Windows 7 Taskbar Progress is correctly updated when
  41. * windows are opened and closed.
  42. */
  43. -->
  44. <window title="Win7 Taskbar Progress"
  45. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  46. onload="test();">
  47. <script type="application/javascript"
  48. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  49. <script type="application/javascript"
  50. src="utils.js"/>
  51. <script type="application/javascript">
  52. <![CDATA[
  53. const kTaskbarID = "@mozilla.org/windows-taskbar;1";
  54. const DOWNLOAD_MANAGER_URL = "chrome://mozapps/content/downloads/downloads.xul";
  55. const DLMGR_UI_DONE = "download-manager-ui-done";
  56. let DownloadTaskbarProgress, TaskbarService, observerService, wwatch, chromeWindow;
  57. let gGen = null;
  58. function test() {
  59. let isWin7OrHigher = false;
  60. try {
  61. let version = Cc["@mozilla.org/system-info;1"]
  62. .getService(Ci.nsIPropertyBag2)
  63. .getProperty("version");
  64. isWin7OrHigher = (parseFloat(version) >= 6.1);
  65. } catch (ex) { }
  66. if (!isWin7OrHigher) {
  67. return;
  68. }
  69. SimpleTest.waitForExplicitFinish();
  70. gGen = doTest();
  71. gGen.next();
  72. }
  73. function continueTest() {
  74. gGen.next();
  75. }
  76. function doTest() {
  77. let tempScope = {};
  78. Components.utils.import("resource://gre/modules/DownloadTaskbarProgress.jsm", tempScope);
  79. DownloadTaskbarProgress = tempScope.DownloadTaskbarProgress;
  80. TaskbarService = Cc[kTaskbarID].getService(Ci.nsIWinTaskbar);
  81. observerService = Cc["@mozilla.org/observer-service;1"].
  82. getService(Ci.nsIObserverService);
  83. wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].
  84. getService(Ci.nsIWindowWatcher);
  85. isnot(DownloadTaskbarProgress, null, "Download taskbar progress service exists");
  86. is(TaskbarService.available, true, "Taskbar Service is available");
  87. let DMWindow = getDMWindow();
  88. if (DMWindow)
  89. DMWindow.close();
  90. //Manually call onBrowserWindowLoad because this is delayed in 10sec
  91. chromeWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  92. getInterface(Components.interfaces.nsIWebNavigation).
  93. QueryInterface(Components.interfaces.nsIDocShellTreeItem).
  94. rootTreeItem.
  95. QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  96. getInterface(Components.interfaces.nsIDOMWindow);
  97. DownloadTaskbarProgress.onBrowserWindowLoad(chromeWindow);
  98. is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, false,
  99. "DownloadTaskbarProgress window is not the Download window");
  100. checkActiveTaskbar(false, window);
  101. openDownloadManager(continueTest);
  102. yield;
  103. let DMWindow = getDMWindow();
  104. ok(DMWindow, "Download Manager window was opened");
  105. checkActiveTaskbar(true, DMWindow);
  106. DMWindow.close();
  107. setTimeout(continueTest, 100);
  108. yield;
  109. checkActiveTaskbar(false, window);
  110. let browserWindow = openBrowserWindow(continueTest);
  111. yield;
  112. ok(browserWindow, "Browser window was opened");
  113. DownloadTaskbarProgress.onBrowserWindowLoad(browserWindow);
  114. // The owner window should not have changed, since our
  115. // original window still exists
  116. checkActiveTaskbar(false, window);
  117. browserWindow.close();
  118. SimpleTest.finish();
  119. yield;
  120. }
  121. function checkActiveTaskbar(isDownloadManager, ownerWindow) {
  122. isnot(DownloadTaskbarProgress.activeTaskbarProgress, null, "DownloadTaskbarProgress has an active taskbar");
  123. is(DownloadTaskbarProgress.activeWindowIsDownloadWindow, isDownloadManager,
  124. "The active taskbar progress " + (isDownloadManager ? "is" : "is not") + " the Download Manager");
  125. if (ownerWindow) {
  126. let ownerWindowDocShell = ownerWindow.QueryInterface(Ci.nsIInterfaceRequestor).
  127. getInterface(Ci.nsIWebNavigation).
  128. QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.
  129. QueryInterface(Ci.nsIInterfaceRequestor).
  130. getInterface(Ci.nsIXULWindow).docShell;
  131. let windowTaskbarProgress = TaskbarService.getTaskbarProgress(ownerWindowDocShell);
  132. is(DownloadTaskbarProgress.activeTaskbarProgress, windowTaskbarProgress,
  133. "DownloadTaskbarProgress has the expected taskbar as active");
  134. }
  135. }
  136. function openBrowserWindow(callback) {
  137. let browserWindow = openDialog(chromeWindow.location, "_blank",
  138. "chrome,all,dialog=no", "about:blank");
  139. let helperFunc = function() {
  140. callback();
  141. browserWindow.removeEventListener("load", helperFunc, false);
  142. }
  143. browserWindow.addEventListener("load", helperFunc, false);
  144. return browserWindow;
  145. }
  146. function openDownloadManager(callback) {
  147. let testObs = {
  148. observe: function(aSubject, aTopic, aData) {
  149. if (aTopic != DLMGR_UI_DONE) {
  150. return;
  151. }
  152. callback();
  153. observerService.removeObserver(testObs, DLMGR_UI_DONE);
  154. }
  155. };
  156. observerService.addObserver(testObs, DLMGR_UI_DONE, false);
  157. Cc["@mozilla.org/download-manager-ui;1"].
  158. getService(Ci.nsIDownloadManagerUI).show();
  159. }
  160. ]]>
  161. </script>
  162. <body xmlns="http://www.w3.org/1999/xhtml">
  163. <p id="display"></p>
  164. <div id="content" style="display:none;"></div>
  165. <pre id="test"></pre>
  166. </body>
  167. </window>