/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. * Test bug 397935 to make sure the download manager ui window stays open when
  40. * it's opened by the user clicking the alert and has the close-when-done pref
  41. * set.
  42. */
  43. -->
  44. <window title="Download Manager Test"
  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. function test()
  54. {
  55. var dmui = getDMUI();
  56. if (!dmui) {
  57. todo(false, "skip test for toolkit download manager UI");
  58. return;
  59. }
  60. let dm = Cc["@mozilla.org/download-manager;1"].
  61. getService(Ci.nsIDownloadManager);
  62. // Empty any old downloads
  63. dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
  64. let setClose = function(aVal) Cc["@mozilla.org/preferences-service;1"].
  65. getService(Ci.nsIPrefBranch).
  66. setBoolPref("browser.download.manager.closeWhenDone", aVal);
  67. // Close the UI if necessary
  68. let wm = Cc["@mozilla.org/appshell/window-mediator;1"].
  69. getService(Ci.nsIWindowMediator);
  70. let win = wm.getMostRecentWindow("Download:Manager");
  71. if (win) win.close();
  72. let os = Cc["@mozilla.org/observer-service;1"].
  73. getService(Ci.nsIObserverService);
  74. const DLMGR_UI_DONE = "download-manager-ui-done";
  75. let testObs = {
  76. observe: function(aSubject, aTopic, aData)
  77. {
  78. if (aTopic != DLMGR_UI_DONE)
  79. return;
  80. let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
  81. win.focus();
  82. // Note: This test will not be valid if the download list is built
  83. // synchronously in Startup in downloads.js
  84. // Make sure the window stays open
  85. ok(dmui.visible, "Download Manager stays open on alert click");
  86. win.close();
  87. setClose(false);
  88. os.removeObserver(testObs, DLMGR_UI_DONE);
  89. try {
  90. Cc["@mozilla.org/preferences-service;1"].
  91. getService(Ci.nsIPrefBranch).
  92. clearUserPref("browser.download.manager.closeWhenDone");
  93. } catch (err) { }
  94. SimpleTest.finish();
  95. }
  96. };
  97. // Register with the observer service
  98. os.addObserver(testObs, DLMGR_UI_DONE, false);
  99. // Simulate an alert click with pref set to true
  100. setClose(true);
  101. dm.QueryInterface(Ci.nsIObserver).observe(null, "alertclickcallback", null);
  102. SimpleTest.waitForExplicitFinish();
  103. }
  104. ]]>
  105. </script>
  106. <body xmlns="http://www.w3.org/1999/xhtml">
  107. <p id="display"></p>
  108. <div id="content" style="display:none;"></div>
  109. <pre id="test"></pre>
  110. </body>
  111. </window>