/toolkit/content/tests/chrome/bug263683_window.xul

http://github.com/zpao/v8monkey · Unknown · 116 lines · 99 code · 17 blank · 0 comment · 0 complexity · bbd6f61efcf47442aa0beedae0d38b80 MD5 · raw file

  1. <?xml version="1.0"?>
  2. <!-- ***** BEGIN LICENSE BLOCK *****
  3. - Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. -
  5. - The contents of this file are subject to the Mozilla Public License Version
  6. - 1.1 (the "License"); you may not use this file except in compliance with
  7. - the License. You may obtain a copy of the License at
  8. - http://www.mozilla.org/MPL/
  9. -
  10. - Software distributed under the License is distributed on an "AS IS" basis,
  11. - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. - for the specific language governing rights and limitations under the
  13. - License.
  14. -
  15. - The Original Code is Findbar Test code
  16. -
  17. - The Initial Developer of the Original Code is
  18. - Graeme McCutcheon <graememcc_firefox@graeme-online.co.uk>.
  19. - Portions created by the Initial Developer are Copyright (C) 2008
  20. - the Initial Developer. All Rights Reserved.
  21. -
  22. - Contributor(s):
  23. -
  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. <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  39. <window id="263683test"
  40. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  41. width="600"
  42. height="600"
  43. onload="SimpleTest.executeSoon(startTest);"
  44. title="263683 test">
  45. <script type="application/javascript"><![CDATA[
  46. const Ci = Components.interfaces;
  47. const Cc = Components.classes;
  48. const Cr = Components.results;
  49. var gFindBar = null;
  50. var gBrowser;
  51. var imports = ["SimpleTest", "ok"];
  52. for each (var name in imports) {
  53. window[name] = window.opener.wrappedJSObject[name];
  54. }
  55. function finish() {
  56. window.close();
  57. SimpleTest.finish();
  58. }
  59. function startTest() {
  60. gFindBar = document.getElementById("FindToolbar");
  61. gBrowser = document.getElementById("content");
  62. gBrowser.addEventListener("pageshow", onPageShow, false);
  63. gBrowser.loadURI('data:text/html,<h2>Text mozilla</h2><input id="inp" type="text" />');
  64. }
  65. function onPageShow() {
  66. gFindBar.open();
  67. var search = "mozilla";
  68. gFindBar._findField.value = search;
  69. var matchCase = gFindBar.getElement("find-case-sensitive");
  70. if (matchCase.checked)
  71. matchCase.doCommand();
  72. gFindBar._find();
  73. var highlightButton = gFindBar.getElement("highlight");
  74. if (!highlightButton.checked)
  75. highlightButton.click();
  76. var controller = gFindBar.browser.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
  77. .getInterface(Ci.nsISelectionDisplay)
  78. .QueryInterface(Ci.nsISelectionController);
  79. ok('SELECTION_FIND' in controller, "Correctly detects new selection type");
  80. var selection = controller.getSelection(controller.SELECTION_FIND);
  81. ok(selection.rangeCount == 1, "Correctly added a match to the selection type");
  82. ok(selection.getRangeAt(0).toString().toLowerCase() == search, "Added the correct match");
  83. highlightButton.click();
  84. ok(selection.rangeCount == 0, "Correctly removed the range");
  85. var input = gBrowser.contentDocument.getElementById("inp");
  86. input.value = search;
  87. highlightButton.click();
  88. var inputController = input.editor.selectionController;
  89. var inputSelection = inputController.getSelection(inputController.SELECTION_FIND);
  90. ok(inputSelection.rangeCount == 1, "Correctly added a match from input to the selection type");
  91. ok(inputSelection.getRangeAt(0).toString().toLowerCase() == search, "Added the correct match");
  92. highlightButton.click();
  93. ok(inputSelection.rangeCount == 0, "Correctly removed the range");
  94. finish();
  95. }
  96. ]]></script>
  97. <browser type="content-primary" flex="1" id="content" src="about:blank"/>
  98. <findbar id="FindToolbar" browserid="content"/>
  99. </window>