test_bug263683.html (3182B)
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 --> 9 10 <head> 11 <title>Test for Bug 263683</title> 12 <script src="/tests/SimpleTest/SimpleTest.js"></script> 13 <script src="/tests/SimpleTest/WindowSnapshot.js"></script> 14 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 15 </head> 16 17 <body onload="onLoad();" onunload="onUnload();"> 18 <a target="_blank" 19 href="https://bugzilla.mozilla.org/show_bug.cgi?id=263683"> 20 Mozilla Bug 263683 21 </a> 22 <p id="display"></p> 23 <div id="content" style="display: none"> 24 </div> 25 26 <pre id="test"> 27 <script type="application/javascript"> 28 29 /** Test for Bug 263683 */ 30 31 SimpleTest.waitForExplicitFinish(); 32 33 var userSetBG = false; 34 var userValueBG = null; 35 var prefNameBG = "ui.textHighlightBackground"; 36 var userSetFG = false; 37 var userValueFG = null; 38 var prefNameFG = "ui.textHighlightForeground"; 39 40 function onLoad() { 41 SpecialPowers.pushPrefEnv({'set': [[prefNameBG, "#EF0FFF"], [prefNameFG, "#FFFFFF"]]}, startTest); 42 } 43 44 function startTest() { 45 var textToSelect = document.getElementById("selecttext"); 46 47 // Take a snapshot now. This will be used to check that removing the 48 // ranges removes the highlighting correctly 49 var noHighlight = snapshotWindow(window); 50 51 var controller = SpecialPowers.wrap(window). 52 docShell. 53 QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor). 54 getInterface(SpecialPowers.Ci.nsISelectionDisplay). 55 QueryInterface(SpecialPowers.Ci.nsISelectionController); 56 57 // Get selection 58 var findSelection = controller.getSelection(controller.SELECTION_FIND); 59 60 // Lastly add range 61 var range = document.createRange(); 62 range.selectNodeContents(textToSelect); 63 findSelection.addRange(range); 64 65 // Take a snapshot of the highlighting 66 var highlighted = snapshotWindow(window); 67 68 // Clear the highlighting, and take another snapshot 69 findSelection.removeAllRanges(); 70 var removedHighlight = snapshotWindow(window); 71 72 // Manually "highlight" the text so we can check the rendering 73 textToSelect.style.backgroundColor="#EF0FFF"; 74 textToSelect.style.color="#FFFFFF"; 75 var manualHighlight = snapshotWindow(window); 76 77 // Test 1: Did the highlighting render correctly? 78 var res = compareSnapshots(highlighted, manualHighlight, true); 79 ok(res[0], "SELECTION_FIND highlighting renders correctly"); 80 81 // Test 2: Does removing the ranges from the SELECTION_FIND selection 82 // work as expected? 83 res = compareSnapshots(removedHighlight, noHighlight, true); 84 ok(res[0], "Removing ranges from FIND_SELECTION works correctly"); 85 86 SimpleTest.finish(); 87 } 88 89 </script> 90 </pre> 91 92 <p><span id="selecttext">Text to be selected</span></p> 93 </body> 94 </html>