toolkit/content/tests/chrome/bug451286_window.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <?xml version="1.0"?>
     3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     4    - License, v. 2.0. If a copy of the MPL was not distributed with this
     5    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     9 <window id="451286test"
    10         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    11         width="600"
    12         height="600"
    13         onload="SimpleTest.executeSoon(startTest);"
    14         title="451286 test (also tests bug 493658)">
    16   <script type="application/javascript"><![CDATA[
    17     const Ci = Components.interfaces;
    18     const Cc = Components.classes;
    19     const Cr = Components.results;
    20     const SEARCH_TEXT = "text";
    21     const DATAURI = "data:text/html," + SEARCH_TEXT;
    23     var gFindBar = null;
    24     var gBrowser;
    25     var gWin;
    27     var noHighlightSnapshot;
    28     var findSnapshot;
    30     var imports = ["SimpleTest", "ok", "snapshotWindow", "compareSnapshots",
    31                    "parentFinish"];
    32     for each (var name in imports) {
    33       window[name] = window.opener.wrappedJSObject[name];
    34     }
    36     function finish() {
    37       window.close();
    38       parentFinish();
    39     }
    41     function startTest() {
    42       gFindBar = document.getElementById("FindToolbar");
    43       gBrowser = document.getElementById("content");
    44       gBrowser.addEventListener("pageshow", onPageShow, false);
    46       // Bug 451286. An iframe that should be highlighted
    47       var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>";
    49       // Bug 493658. An invisible iframe that shouldn't interfere with
    50       // highlighting matches lying after it in the document
    51       var invisible = "<iframe id='invisible' style='display: none;' " +
    52                       "src='" + DATAURI + "'></iframe>";
    54       var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT;
    55       gBrowser.loadURI(uri);
    56     }
    58     function onPageShow(aEvent) {
    59       // Don't respond to pageshow events coming from the <iframes>
    60       if (aEvent.target != gBrowser.contentDocument)
    61         return;
    63       gBrowser.removeEventListener("pageshow", onPageShow, false);
    65       // First, take a snapshot of the window without highlighting
    66       // to be used later to test the unhighlighting case
    67       gWin = gBrowser.contentWindow;
    68       noHighlightSnapshot = snapshotWindow(gWin);
    70       gFindBar.open();
    71       gFindBar._findField.value = SEARCH_TEXT;
    72       var matchCase = gFindBar.getElement("find-case-sensitive");
    73       if (matchCase.checked)
    74         matchCase.doCommand();
    76       // Turn on highlighting
    77       gFindBar.toggleHighlight(true);
    78       gFindBar.close();
    79       gFindBar.addEventListener('transitionend', part2);
    80     }
    82     function part2(aEvent) {
    83       if (aEvent.propertyName != 'visibility') {
    84         return;
    85       }
    86       gFindBar.removeEventListener('transitionend', part2);
    87       // Take snapshot of highlighing
    88       findSnapshot = snapshotWindow(gWin);
    90       // Now, remove the highlighting, and take a snapshot to compare
    91       // to our original state
    92       gFindBar.open();
    93       gFindBar.toggleHighlight(false);
    94       gFindBar.close();
    95       gFindBar.addEventListener('transitionend', part3);
    96     }
    98     function part3(aEvent) {
    99       if (aEvent.propertyName != 'visibility') {
   100         return;
   101       }
   102       gFindBar.removeEventListener('transitionend', part3);
   103       var unhighlightSnapshot = snapshotWindow(gWin);
   105       // Select the matches that should have been highlighted manually
   106       var doc = gBrowser.contentDocument;
   108       // Create a manual highlight in the visible iframe to test bug 451286
   109       var iframe = doc.getElementById("visible");
   110       var ifBody = iframe.contentDocument.body;
   111       var range = iframe.contentDocument.createRange();
   112       range.selectNodeContents(ifBody.childNodes[0]);
   113       var ifWindow = iframe.contentWindow;
   114       var ifDocShell = ifWindow.QueryInterface(Ci.nsIInterfaceRequestor)
   115                                .getInterface(Ci.nsIWebNavigation)
   116                                .QueryInterface(Ci.nsIDocShell);
   118       var ifController = ifDocShell.QueryInterface(Ci.nsIInterfaceRequestor)
   119                                    .getInterface(Ci.nsISelectionDisplay)
   120                                    .QueryInterface(Ci.nsISelectionController);
   122       var frameFindSelection =
   123         ifController.getSelection(ifController.SELECTION_FIND);
   124       frameFindSelection.addRange(range);
   126       // Create manual highlights in the main document (the matches that lie
   127       // before/after the iframes
   128       var docShell = gWin.QueryInterface(Ci.nsIInterfaceRequestor)
   129                          .getInterface(Ci.nsIWebNavigation)
   130                           .QueryInterface(Ci.nsIDocShell);
   132       var controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
   133                                .getInterface(Ci.nsISelectionDisplay)
   134                                .QueryInterface(Ci.nsISelectionController);
   136       var docFindSelection =
   137         controller.getSelection(ifController.SELECTION_FIND);
   139       range = doc.createRange();
   140       range.selectNodeContents(doc.body.childNodes[0]);
   141       docFindSelection.addRange(range);
   142       range = doc.createRange();
   143       range.selectNodeContents(doc.body.childNodes[2]);
   144       docFindSelection.addRange(range);
   145       range = doc.createRange();
   146       range.selectNodeContents(doc.body.childNodes[4]);
   147       docFindSelection.addRange(range);
   149       // Take snapshot of manual highlighting
   150       var manualSnapshot = snapshotWindow(gBrowser.contentWindow);
   152       // Test 1: Were the matches in iframe correctly highlighted?
   153       var res = compareSnapshots(findSnapshot, manualSnapshot, true);
   154       ok(res[0], "Matches found in iframe correctly highlighted");
   156       // Test 2: Were the matches in iframe correctly unhighlighted?
   157       res = compareSnapshots(noHighlightSnapshot, unhighlightSnapshot, true);
   158       ok(res[0], "Highlighting in iframe correctly removed");
   160       finish();
   161     }
   162   ]]></script>
   164   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   165   <findbar id="FindToolbar" browserid="content"/>
   166 </window>

mercurial