toolkit/content/tests/chrome/bug451286_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/bug451286_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,166 @@
     1.4 +<?xml version="1.0"?>
     1.5 +
     1.6 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.9 +
    1.10 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
    1.11 +
    1.12 +<window id="451286test"
    1.13 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.14 +        width="600"
    1.15 +        height="600"
    1.16 +        onload="SimpleTest.executeSoon(startTest);"
    1.17 +        title="451286 test (also tests bug 493658)">
    1.18 +
    1.19 +  <script type="application/javascript"><![CDATA[
    1.20 +    const Ci = Components.interfaces;
    1.21 +    const Cc = Components.classes;
    1.22 +    const Cr = Components.results;
    1.23 +    const SEARCH_TEXT = "text";
    1.24 +    const DATAURI = "data:text/html," + SEARCH_TEXT;
    1.25 +
    1.26 +    var gFindBar = null;
    1.27 +    var gBrowser;
    1.28 +    var gWin;
    1.29 +
    1.30 +    var noHighlightSnapshot;
    1.31 +    var findSnapshot;
    1.32 +
    1.33 +    var imports = ["SimpleTest", "ok", "snapshotWindow", "compareSnapshots",
    1.34 +                   "parentFinish"];
    1.35 +    for each (var name in imports) {
    1.36 +      window[name] = window.opener.wrappedJSObject[name];
    1.37 +    }
    1.38 +
    1.39 +    function finish() {
    1.40 +      window.close();
    1.41 +      parentFinish();
    1.42 +    }
    1.43 +
    1.44 +    function startTest() {
    1.45 +      gFindBar = document.getElementById("FindToolbar");
    1.46 +      gBrowser = document.getElementById("content");
    1.47 +      gBrowser.addEventListener("pageshow", onPageShow, false);
    1.48 +
    1.49 +      // Bug 451286. An iframe that should be highlighted
    1.50 +      var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>";
    1.51 +
    1.52 +      // Bug 493658. An invisible iframe that shouldn't interfere with
    1.53 +      // highlighting matches lying after it in the document
    1.54 +      var invisible = "<iframe id='invisible' style='display: none;' " +
    1.55 +                      "src='" + DATAURI + "'></iframe>";
    1.56 +
    1.57 +      var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT;
    1.58 +      gBrowser.loadURI(uri);
    1.59 +    }
    1.60 +
    1.61 +    function onPageShow(aEvent) {
    1.62 +      // Don't respond to pageshow events coming from the <iframes>
    1.63 +      if (aEvent.target != gBrowser.contentDocument)
    1.64 +        return;
    1.65 +
    1.66 +      gBrowser.removeEventListener("pageshow", onPageShow, false);
    1.67 +
    1.68 +      // First, take a snapshot of the window without highlighting
    1.69 +      // to be used later to test the unhighlighting case
    1.70 +      gWin = gBrowser.contentWindow;
    1.71 +      noHighlightSnapshot = snapshotWindow(gWin);
    1.72 +
    1.73 +      gFindBar.open();
    1.74 +      gFindBar._findField.value = SEARCH_TEXT;
    1.75 +      var matchCase = gFindBar.getElement("find-case-sensitive");
    1.76 +      if (matchCase.checked)
    1.77 +        matchCase.doCommand();
    1.78 +
    1.79 +      // Turn on highlighting
    1.80 +      gFindBar.toggleHighlight(true);
    1.81 +      gFindBar.close();
    1.82 +      gFindBar.addEventListener('transitionend', part2);
    1.83 +    }
    1.84 +
    1.85 +    function part2(aEvent) {
    1.86 +      if (aEvent.propertyName != 'visibility') {
    1.87 +        return;
    1.88 +      }
    1.89 +      gFindBar.removeEventListener('transitionend', part2);
    1.90 +      // Take snapshot of highlighing
    1.91 +      findSnapshot = snapshotWindow(gWin);
    1.92 +
    1.93 +      // Now, remove the highlighting, and take a snapshot to compare
    1.94 +      // to our original state
    1.95 +      gFindBar.open();
    1.96 +      gFindBar.toggleHighlight(false);
    1.97 +      gFindBar.close();
    1.98 +      gFindBar.addEventListener('transitionend', part3);
    1.99 +    }
   1.100 +
   1.101 +    function part3(aEvent) {
   1.102 +      if (aEvent.propertyName != 'visibility') {
   1.103 +        return;
   1.104 +      }
   1.105 +      gFindBar.removeEventListener('transitionend', part3);
   1.106 +      var unhighlightSnapshot = snapshotWindow(gWin);
   1.107 +
   1.108 +      // Select the matches that should have been highlighted manually
   1.109 +      var doc = gBrowser.contentDocument;
   1.110 +
   1.111 +      // Create a manual highlight in the visible iframe to test bug 451286
   1.112 +      var iframe = doc.getElementById("visible");
   1.113 +      var ifBody = iframe.contentDocument.body;
   1.114 +      var range = iframe.contentDocument.createRange();
   1.115 +      range.selectNodeContents(ifBody.childNodes[0]);
   1.116 +      var ifWindow = iframe.contentWindow;
   1.117 +      var ifDocShell = ifWindow.QueryInterface(Ci.nsIInterfaceRequestor)
   1.118 +                               .getInterface(Ci.nsIWebNavigation)
   1.119 +                               .QueryInterface(Ci.nsIDocShell);
   1.120 +
   1.121 +      var ifController = ifDocShell.QueryInterface(Ci.nsIInterfaceRequestor)
   1.122 +                                   .getInterface(Ci.nsISelectionDisplay)
   1.123 +                                   .QueryInterface(Ci.nsISelectionController);
   1.124 +
   1.125 +      var frameFindSelection =
   1.126 +        ifController.getSelection(ifController.SELECTION_FIND);
   1.127 +      frameFindSelection.addRange(range);
   1.128 +
   1.129 +      // Create manual highlights in the main document (the matches that lie
   1.130 +      // before/after the iframes
   1.131 +      var docShell = gWin.QueryInterface(Ci.nsIInterfaceRequestor)
   1.132 +                         .getInterface(Ci.nsIWebNavigation)
   1.133 +                          .QueryInterface(Ci.nsIDocShell);
   1.134 +
   1.135 +      var controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
   1.136 +                               .getInterface(Ci.nsISelectionDisplay)
   1.137 +                               .QueryInterface(Ci.nsISelectionController);
   1.138 +
   1.139 +      var docFindSelection =
   1.140 +        controller.getSelection(ifController.SELECTION_FIND);
   1.141 +
   1.142 +      range = doc.createRange();
   1.143 +      range.selectNodeContents(doc.body.childNodes[0]);
   1.144 +      docFindSelection.addRange(range);
   1.145 +      range = doc.createRange();
   1.146 +      range.selectNodeContents(doc.body.childNodes[2]);
   1.147 +      docFindSelection.addRange(range);
   1.148 +      range = doc.createRange();
   1.149 +      range.selectNodeContents(doc.body.childNodes[4]);
   1.150 +      docFindSelection.addRange(range);
   1.151 +
   1.152 +      // Take snapshot of manual highlighting
   1.153 +      var manualSnapshot = snapshotWindow(gBrowser.contentWindow);
   1.154 +
   1.155 +      // Test 1: Were the matches in iframe correctly highlighted?
   1.156 +      var res = compareSnapshots(findSnapshot, manualSnapshot, true);
   1.157 +      ok(res[0], "Matches found in iframe correctly highlighted");
   1.158 +
   1.159 +      // Test 2: Were the matches in iframe correctly unhighlighted?
   1.160 +      res = compareSnapshots(noHighlightSnapshot, unhighlightSnapshot, true);
   1.161 +      ok(res[0], "Highlighting in iframe correctly removed");
   1.162 +
   1.163 +      finish();
   1.164 +    }
   1.165 +  ]]></script>
   1.166 +
   1.167 +  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   1.168 +  <findbar id="FindToolbar" browserid="content"/>
   1.169 +</window>

mercurial