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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial