layout/generic/test/test_bug263683.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/generic/test/test_bug263683.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     1.8 +<html>
     1.9 +<!--
    1.10 +https://bugzilla.mozilla.org/show_bug.cgi?id=263683
    1.11 +-->
    1.12 +
    1.13 +<head>
    1.14 +  <title>Test for Bug 263683</title>
    1.15 +  <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
    1.16 +  <script type="application/javascript"
    1.17 +          src="/tests/SimpleTest/SimpleTest.js"></script>
    1.18 +  <script type="application/javascript"
    1.19 +          src="/tests/SimpleTest/WindowSnapshot.js"></script>
    1.20 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.21 +</head>
    1.22 +
    1.23 +<body onload="onLoad();" onunload="onUnload();">
    1.24 +  <a target="_blank"
    1.25 +     href="https://bugzilla.mozilla.org/show_bug.cgi?id=263683">
    1.26 +    Mozilla Bug 263683
    1.27 +  </a>
    1.28 +  <p id="display"></p>
    1.29 +  <div id="content" style="display: none">
    1.30 +  </div>
    1.31 +
    1.32 +  <pre id="test">
    1.33 +    <script type="application/javascript">
    1.34 +
    1.35 +      /** Test for Bug 263683 **/
    1.36 +    
    1.37 +      SimpleTest.waitForExplicitFinish();
    1.38 +
    1.39 +      var userSetBG = false;
    1.40 +      var userValueBG = null;
    1.41 +      var prefNameBG = "ui.textHighlightBackground";
    1.42 +      var userSetFG = false;
    1.43 +      var userValueFG = null;
    1.44 +      var prefNameFG = "ui.textHighlightForeground";
    1.45 +
    1.46 +      function onLoad() {
    1.47 +        SpecialPowers.pushPrefEnv({'set': [[prefNameBG, "#EF0FFF"], [prefNameFG, "#FFFFFF"]]}, startTest);
    1.48 +      }
    1.49 +
    1.50 +      function startTest() {
    1.51 +        var textToSelect = document.getElementById("selecttext");
    1.52 +
    1.53 +        // Take a snapshot now. This will be used to check that removing the
    1.54 +        // ranges removes the highlighting correctly
    1.55 +        var noHighlight = snapshotWindow(window);
    1.56 +
    1.57 +        var controller = SpecialPowers.wrap(window).
    1.58 +           QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
    1.59 +           getInterface(SpecialPowers.Ci.nsIWebNavigation).
    1.60 +           QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
    1.61 +           getInterface(SpecialPowers.Ci.nsISelectionDisplay).
    1.62 +           QueryInterface(SpecialPowers.Ci.nsISelectionController);
    1.63 +
    1.64 +        // Get selection
    1.65 +        var findSelection = controller.getSelection(controller.SELECTION_FIND);
    1.66 +
    1.67 +        // Lastly add range
    1.68 +        var range = document.createRange();
    1.69 +        range.selectNodeContents(textToSelect);
    1.70 +        findSelection.addRange(range);
    1.71 +
    1.72 +        // Take a snapshot of the highlighting
    1.73 +        var highlighted = snapshotWindow(window);
    1.74 +
    1.75 +        // Clear the highlighting, and take another snapshot
    1.76 +        findSelection.removeAllRanges();
    1.77 +        var removedHighlight = snapshotWindow(window);
    1.78 +
    1.79 +        // Manually "highlight" the text so we can check the rendering
    1.80 +        textToSelect.style.backgroundColor="#EF0FFF";
    1.81 +        textToSelect.style.color="#FFFFFF";
    1.82 +        var manualHighlight = snapshotWindow(window);
    1.83 +
    1.84 +        // Test 1: Did the highlighting render correctly?
    1.85 +        var res = compareSnapshots(highlighted, manualHighlight, true);
    1.86 +        ok(res[0], "SELECTION_FIND highlighting renders correctly");
    1.87 +
    1.88 +        // Test 2: Does removing the ranges from the SELECTION_FIND selection
    1.89 +        // work as expected?
    1.90 +        res = compareSnapshots(removedHighlight, noHighlight, true);
    1.91 +        ok(res[0], "Removing ranges from FIND_SELECTION works correctly");
    1.92 +
    1.93 +        SimpleTest.finish();
    1.94 +      }
    1.95 +
    1.96 +    </script>
    1.97 +  </pre>
    1.98 +
    1.99 +  <p><span id="selecttext">Text to be selected</span></p>
   1.100 +</body>
   1.101 +</html>

mercurial