layout/generic/test/test_bug263683.html

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 <!DOCTYPE HTML>
     2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     3    - License, v. 2.0. If a copy of the MPL was not distributed with this
     4    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     5 <html>
     6 <!--
     7 https://bugzilla.mozilla.org/show_bug.cgi?id=263683
     8 -->
    10 <head>
    11   <title>Test for Bug 263683</title>
    12   <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
    13   <script type="application/javascript"
    14           src="/tests/SimpleTest/SimpleTest.js"></script>
    15   <script type="application/javascript"
    16           src="/tests/SimpleTest/WindowSnapshot.js"></script>
    17   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    18 </head>
    20 <body onload="onLoad();" onunload="onUnload();">
    21   <a target="_blank"
    22      href="https://bugzilla.mozilla.org/show_bug.cgi?id=263683">
    23     Mozilla Bug 263683
    24   </a>
    25   <p id="display"></p>
    26   <div id="content" style="display: none">
    27   </div>
    29   <pre id="test">
    30     <script type="application/javascript">
    32       /** Test for Bug 263683 **/
    34       SimpleTest.waitForExplicitFinish();
    36       var userSetBG = false;
    37       var userValueBG = null;
    38       var prefNameBG = "ui.textHighlightBackground";
    39       var userSetFG = false;
    40       var userValueFG = null;
    41       var prefNameFG = "ui.textHighlightForeground";
    43       function onLoad() {
    44         SpecialPowers.pushPrefEnv({'set': [[prefNameBG, "#EF0FFF"], [prefNameFG, "#FFFFFF"]]}, startTest);
    45       }
    47       function startTest() {
    48         var textToSelect = document.getElementById("selecttext");
    50         // Take a snapshot now. This will be used to check that removing the
    51         // ranges removes the highlighting correctly
    52         var noHighlight = snapshotWindow(window);
    54         var controller = SpecialPowers.wrap(window).
    55            QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
    56            getInterface(SpecialPowers.Ci.nsIWebNavigation).
    57            QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
    58            getInterface(SpecialPowers.Ci.nsISelectionDisplay).
    59            QueryInterface(SpecialPowers.Ci.nsISelectionController);
    61         // Get selection
    62         var findSelection = controller.getSelection(controller.SELECTION_FIND);
    64         // Lastly add range
    65         var range = document.createRange();
    66         range.selectNodeContents(textToSelect);
    67         findSelection.addRange(range);
    69         // Take a snapshot of the highlighting
    70         var highlighted = snapshotWindow(window);
    72         // Clear the highlighting, and take another snapshot
    73         findSelection.removeAllRanges();
    74         var removedHighlight = snapshotWindow(window);
    76         // Manually "highlight" the text so we can check the rendering
    77         textToSelect.style.backgroundColor="#EF0FFF";
    78         textToSelect.style.color="#FFFFFF";
    79         var manualHighlight = snapshotWindow(window);
    81         // Test 1: Did the highlighting render correctly?
    82         var res = compareSnapshots(highlighted, manualHighlight, true);
    83         ok(res[0], "SELECTION_FIND highlighting renders correctly");
    85         // Test 2: Does removing the ranges from the SELECTION_FIND selection
    86         // work as expected?
    87         res = compareSnapshots(removedHighlight, noHighlight, true);
    88         ok(res[0], "Removing ranges from FIND_SELECTION works correctly");
    90         SimpleTest.finish();
    91       }
    93     </script>
    94   </pre>
    96   <p><span id="selecttext">Text to be selected</span></p>
    97 </body>
    98 </html>

mercurial