PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

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

http://github.com/zpao/v8monkey
Unknown | 131 lines | 111 code | 20 blank | 0 comment | 0 complexity | 35a5ce54d5a98f90d5f92d3003f6bfb9 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 Download Manager UI Test Code.
 17 *
 18 * The Initial Developer of the Original Code is
 19 * Edward Lee <edward.lee@engineering.uiuc.edu>.
 20 * Portions created by the Initial Developer are Copyright (C) 2008
 21 * the Initial Developer. All Rights Reserved.
 22 *
 23 * Contributor(s):
 24 *
 25 * Alternatively, the contents of this file may be used under the terms of
 26 * either the GNU General Public License Version 2 or later (the "GPL"), or
 27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 28 * in which case the provisions of the GPL or the LGPL are applicable instead
 29 * of those above. If you wish to allow use of your version of this file only
 30 * under the terms of either the GPL or the LGPL, and not to allow others to
 31 * use your version of this file under the terms of the MPL, indicate your
 32 * decision by deleting the provisions above and replace them with the notice
 33 * and other provisions required by the GPL or the LGPL. If you do not delete
 34 * the provisions above, a recipient may use your version of this file under
 35 * the terms of any one of the MPL, the GPL or the LGPL.
 36 *
 37 * ***** END LICENSE BLOCK ***** */
 38
 39/**
 40 * Test bug 397935 to make sure the download manager ui window stays open when
 41 * it's opened by the user clicking the alert and has the close-when-done pref
 42 * set.
 43 */
 44-->
 45
 46<window title="Download Manager Test"
 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
 58function test()
 59{
 60  var dmui = getDMUI();
 61  if (!dmui) {
 62    todo(false, "skip test for toolkit download manager UI");
 63    return;
 64  }
 65
 66  let dm = Cc["@mozilla.org/download-manager;1"].
 67           getService(Ci.nsIDownloadManager);
 68
 69  // Empty any old downloads
 70  dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
 71
 72  let setClose = function(aVal) Cc["@mozilla.org/preferences-service;1"].
 73    getService(Ci.nsIPrefBranch).
 74    setBoolPref("browser.download.manager.closeWhenDone", aVal);
 75
 76  // Close the UI if necessary
 77  let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
 78           getService(Ci.nsIWindowMediator);
 79  let win = wm.getMostRecentWindow("Download:Manager");
 80  if (win) win.close();
 81
 82  let os = Cc["@mozilla.org/observer-service;1"].
 83           getService(Ci.nsIObserverService);
 84  const DLMGR_UI_DONE = "download-manager-ui-done";
 85
 86  let testObs = {
 87    observe: function(aSubject, aTopic, aData)
 88    {
 89      if (aTopic != DLMGR_UI_DONE)
 90        return;
 91
 92      let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
 93      win.focus();
 94
 95      // Note:  This test will not be valid if the download list is built
 96      //        synchronously in Startup in downloads.js
 97      // Make sure the window stays open
 98      ok(dmui.visible, "Download Manager stays open on alert click");
 99
100      win.close();
101      setClose(false);
102      os.removeObserver(testObs, DLMGR_UI_DONE);
103
104      try {
105        Cc["@mozilla.org/preferences-service;1"].
106        getService(Ci.nsIPrefBranch).
107        clearUserPref("browser.download.manager.closeWhenDone");
108      } catch (err) { }
109      SimpleTest.finish();
110    }
111  };
112
113  // Register with the observer service
114  os.addObserver(testObs, DLMGR_UI_DONE, false);
115
116  // Simulate an alert click with pref set to true
117  setClose(true);
118  dm.QueryInterface(Ci.nsIObserver).observe(null, "alertclickcallback", null);
119
120  SimpleTest.waitForExplicitFinish();
121}
122
123  ]]>
124  </script>
125
126  <body xmlns="http://www.w3.org/1999/xhtml">
127    <p id="display"></p>
128    <div id="content" style="display:none;"></div>
129    <pre id="test"></pre>
130  </body>
131</window>