|
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 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> |
|
19 |
|
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> |
|
28 |
|
29 <pre id="test"> |
|
30 <script type="application/javascript"> |
|
31 |
|
32 /** Test for Bug 263683 **/ |
|
33 |
|
34 SimpleTest.waitForExplicitFinish(); |
|
35 |
|
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"; |
|
42 |
|
43 function onLoad() { |
|
44 SpecialPowers.pushPrefEnv({'set': [[prefNameBG, "#EF0FFF"], [prefNameFG, "#FFFFFF"]]}, startTest); |
|
45 } |
|
46 |
|
47 function startTest() { |
|
48 var textToSelect = document.getElementById("selecttext"); |
|
49 |
|
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); |
|
53 |
|
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); |
|
60 |
|
61 // Get selection |
|
62 var findSelection = controller.getSelection(controller.SELECTION_FIND); |
|
63 |
|
64 // Lastly add range |
|
65 var range = document.createRange(); |
|
66 range.selectNodeContents(textToSelect); |
|
67 findSelection.addRange(range); |
|
68 |
|
69 // Take a snapshot of the highlighting |
|
70 var highlighted = snapshotWindow(window); |
|
71 |
|
72 // Clear the highlighting, and take another snapshot |
|
73 findSelection.removeAllRanges(); |
|
74 var removedHighlight = snapshotWindow(window); |
|
75 |
|
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); |
|
80 |
|
81 // Test 1: Did the highlighting render correctly? |
|
82 var res = compareSnapshots(highlighted, manualHighlight, true); |
|
83 ok(res[0], "SELECTION_FIND highlighting renders correctly"); |
|
84 |
|
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"); |
|
89 |
|
90 SimpleTest.finish(); |
|
91 } |
|
92 |
|
93 </script> |
|
94 </pre> |
|
95 |
|
96 <p><span id="selecttext">Text to be selected</span></p> |
|
97 </body> |
|
98 </html> |