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

/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
  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 Findbar Test code
 17   -
 18   - The Initial Developer of the Original Code is
 19   - Graeme McCutcheon <graememcc_firefox@graeme-online.co.uk>.
 20   - Portions created by the Initial Developer are Copyright (C) 2008
 21   - the Initial Developer. All Rights Reserved.
 22   -
 23   - Contributor(s):
 24   -     
 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<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 41
 42<window id="263683test"
 43        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
 44        width="600"
 45        height="600"
 46        onload="SimpleTest.executeSoon(startTest);"
 47        title="263683 test">
 48
 49  <script type="application/javascript"><![CDATA[
 50    const Ci = Components.interfaces;
 51    const Cc = Components.classes;
 52    const Cr = Components.results;
 53
 54    var gFindBar = null;
 55    var gBrowser;
 56
 57    var imports = ["SimpleTest", "ok"];
 58    for each (var name in imports) {
 59      window[name] = window.opener.wrappedJSObject[name];
 60    }
 61
 62    function finish() {
 63      window.close();
 64      SimpleTest.finish();
 65    }
 66
 67    function startTest() {
 68      gFindBar = document.getElementById("FindToolbar");
 69      gBrowser = document.getElementById("content");
 70      gBrowser.addEventListener("pageshow", onPageShow, false);
 71      gBrowser.loadURI('data:text/html,<h2>Text mozilla</h2><input id="inp" type="text" />');
 72    }
 73
 74    function onPageShow() {
 75      gFindBar.open();
 76      var search = "mozilla";
 77      gFindBar._findField.value = search;
 78      var matchCase = gFindBar.getElement("find-case-sensitive");
 79      if (matchCase.checked)
 80        matchCase.doCommand();
 81
 82      gFindBar._find();
 83      var highlightButton = gFindBar.getElement("highlight");
 84      if (!highlightButton.checked)
 85        highlightButton.click();
 86
 87      var controller = gFindBar.browser.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
 88                                       .getInterface(Ci.nsISelectionDisplay)
 89                                       .QueryInterface(Ci.nsISelectionController);
 90      ok('SELECTION_FIND' in controller, "Correctly detects new selection type");
 91      var selection = controller.getSelection(controller.SELECTION_FIND);
 92      
 93      ok(selection.rangeCount == 1, "Correctly added a match to the selection type");
 94      ok(selection.getRangeAt(0).toString().toLowerCase() == search, "Added the correct match");
 95      highlightButton.click();
 96      ok(selection.rangeCount == 0, "Correctly removed the range");
 97
 98      var input = gBrowser.contentDocument.getElementById("inp");
 99      input.value = search;
100 
101      highlightButton.click();
102
103      var inputController = input.editor.selectionController;
104      var inputSelection = inputController.getSelection(inputController.SELECTION_FIND);
105
106      ok(inputSelection.rangeCount == 1, "Correctly added a match from input to the selection type");
107      ok(inputSelection.getRangeAt(0).toString().toLowerCase() == search, "Added the correct match");
108      highlightButton.click();
109      ok(inputSelection.rangeCount == 0, "Correctly removed the range");
110      finish();
111    }
112  ]]></script>
113
114  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
115  <findbar id="FindToolbar" browserid="content"/>
116</window>