PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/toolkit/content/tests/chrome/bug451286_window.xul

http://github.com/zpao/v8monkey
Unknown | 179 lines | 148 code | 31 blank | 0 comment | 0 complexity | a69e3bc3b2644950b2cd5787ef3a30c3 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="451286test"
 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="451286 test (also tests bug 493658)">
 48
 49  <script type="application/javascript"><![CDATA[
 50    const Ci = Components.interfaces;
 51    const Cc = Components.classes;
 52    const Cr = Components.results;
 53    const SEARCH_TEXT = "text";
 54    const DATAURI = "data:text/html," + SEARCH_TEXT;
 55
 56    var gFindBar = null;
 57    var gBrowser;
 58
 59    var imports = ["SimpleTest", "ok", "snapshotWindow", "compareSnapshots"];
 60    for each (var name in imports) {
 61      window[name] = window.opener.wrappedJSObject[name];
 62    }
 63
 64    function finish() {
 65      window.close();
 66      SimpleTest.finish();
 67    }
 68
 69    function startTest() {
 70      gFindBar = document.getElementById("FindToolbar");
 71      gBrowser = document.getElementById("content");
 72      gBrowser.addEventListener("pageshow", onPageShow, false);
 73
 74      // Bug 451286. An iframe that should be highlighted
 75      var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>";
 76
 77      // Bug 493658. An invisible iframe that shouldn't interfere with
 78      // highlighting matches lying after it in the document
 79      var invisible = "<iframe id='invisible' style='display: none;' " +
 80                      "src='" + DATAURI + "'></iframe>";
 81
 82      var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT;
 83      gBrowser.loadURI(uri);
 84    }
 85
 86    function onPageShow(aEvent) {
 87      // Don't respond to pageshow events coming from the <iframes>
 88      if (aEvent.target != gBrowser.contentDocument)
 89        return;
 90
 91      gBrowser.removeEventListener("pageshow", onPageShow, false);
 92
 93      // First, take a snapshot of the window without highlighting
 94      // to be used later to test the unhighlighting case
 95      var gWin = gBrowser.contentWindow;
 96      var noHighlightSnapshot = snapshotWindow(gWin);
 97
 98      gFindBar.open();
 99      gFindBar._findField.value = SEARCH_TEXT;
100      var matchCase = gFindBar.getElement("find-case-sensitive");
101      if (matchCase.checked)
102        matchCase.doCommand();
103
104      // Turn on highlighting
105      gFindBar.toggleHighlight(true);
106      gFindBar.close();
107    
108      // Take snapshot of highlighing
109      var findSnapshot = snapshotWindow(gWin);
110
111      // Now, remove the highlighting, and take a snapshot to compare
112      // to our original state
113      gFindBar.open();
114      gFindBar.toggleHighlight(false);
115      gFindBar.close();
116      var unhighlightSnapshot = snapshotWindow(gWin);
117
118      // Select the matches that should have been highlighted manually
119      var doc = gBrowser.contentDocument;
120
121      // Create a manual highlight in the visible iframe to test bug 451286
122      var iframe = doc.getElementById("visible");
123      var ifBody = iframe.contentDocument.body;
124      var range = iframe.contentDocument.createRange();
125      range.selectNodeContents(ifBody.childNodes[0]);
126      var ifWindow = iframe.contentWindow;
127      var ifDocShell = ifWindow.QueryInterface(Ci.nsIInterfaceRequestor)
128                               .getInterface(Ci.nsIWebNavigation)
129                               .QueryInterface(Ci.nsIDocShell);
130
131      var ifController = ifDocShell.QueryInterface(Ci.nsIInterfaceRequestor)
132                                   .getInterface(Ci.nsISelectionDisplay)
133                                   .QueryInterface(Ci.nsISelectionController);
134
135      var frameFindSelection =
136        ifController.getSelection(ifController.SELECTION_FIND);
137      frameFindSelection.addRange(range);
138
139      // Create manual highlights in the main document (the matches that lie
140      // before/after the iframes
141      var docShell = gWin.QueryInterface(Ci.nsIInterfaceRequestor)
142                         .getInterface(Ci.nsIWebNavigation)
143                          .QueryInterface(Ci.nsIDocShell);
144
145      var controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
146                               .getInterface(Ci.nsISelectionDisplay)
147                               .QueryInterface(Ci.nsISelectionController);
148
149      var docFindSelection =
150        controller.getSelection(ifController.SELECTION_FIND);
151
152      range = doc.createRange();
153      range.selectNodeContents(doc.body.childNodes[0]);
154      docFindSelection.addRange(range);
155      range = doc.createRange();
156      range.selectNodeContents(doc.body.childNodes[2]);
157      docFindSelection.addRange(range);
158      range = doc.createRange();
159      range.selectNodeContents(doc.body.childNodes[4]);
160      docFindSelection.addRange(range);
161
162      // Take snapshot of manual highlighting
163      var manualSnapshot = snapshotWindow(gBrowser.contentWindow);
164
165      // Test 1: Were the matches in iframe correctly highlighted?
166      var res = compareSnapshots(findSnapshot, manualSnapshot, true);
167      ok(res[0], "Matches found in iframe correctly highlighted");
168
169      // Test 2: Were the matches in iframe correctly unhighlighted?
170      res = compareSnapshots(noHighlightSnapshot, unhighlightSnapshot, true);
171      ok(res[0], "Highlighting in iframe correctly removed");
172
173      finish();
174    }
175  ]]></script>
176
177  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
178  <findbar id="FindToolbar" browserid="content"/>
179</window>