Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>nsIDOMWindowUtils::sendQueryContentEvent w/QUERY_CARET_RECT test</title> |
michael@0 | 5 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
michael@0 | 7 | |
michael@0 | 8 | <style> |
michael@0 | 9 | #text { |
michael@0 | 10 | position: absolute; |
michael@0 | 11 | left: 0em; |
michael@0 | 12 | top: 0em; |
michael@0 | 13 | font-size: 10pt; |
michael@0 | 14 | font-family: monospace; |
michael@0 | 15 | line-height: 20px; |
michael@0 | 16 | letter-spacing: 0px; |
michael@0 | 17 | margin-top:-1px; /* nix the text area border */ |
michael@0 | 18 | overflow: hidden; |
michael@0 | 19 | width:800px; |
michael@0 | 20 | height:400px; |
michael@0 | 21 | } |
michael@0 | 22 | #div-hor { |
michael@0 | 23 | position: absolute; |
michael@0 | 24 | left: 0em; |
michael@0 | 25 | border-top:1px solid lightgray; |
michael@0 | 26 | width: 1000px; |
michael@0 | 27 | pointer-events:none; |
michael@0 | 28 | } |
michael@0 | 29 | #div-ver { |
michael@0 | 30 | position: absolute; |
michael@0 | 31 | top: 0em; |
michael@0 | 32 | border-left:1px solid lightgray; |
michael@0 | 33 | height: 500px; |
michael@0 | 34 | pointer-events:none; |
michael@0 | 35 | } |
michael@0 | 36 | </style> |
michael@0 | 37 | |
michael@0 | 38 | <script type="application/javascript;version=1.8"> |
michael@0 | 39 | let SimpleTest = window.opener.SimpleTest; |
michael@0 | 40 | let Ci = Components.interfaces; |
michael@0 | 41 | |
michael@0 | 42 | function ok() { window.opener.ok.apply(window.opener, arguments); } |
michael@0 | 43 | function done() { window.opener.done.apply(window.opener, arguments); } |
michael@0 | 44 | |
michael@0 | 45 | function dumpLn() { |
michael@0 | 46 | for (let idx = 0; idx < arguments.length; idx++) |
michael@0 | 47 | dump(arguments[idx] + " "); |
michael@0 | 48 | dump("\n"); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | // drawn grid is 20x20 |
michael@0 | 52 | function drawGrid() { |
michael@0 | 53 | for (var idx = 0; idx < 20; idx++) { |
michael@0 | 54 | var e = document.createElement("div"); |
michael@0 | 55 | e.setAttribute("id", "div-hor"); |
michael@0 | 56 | e.style.top = (idx*20) + "px"; |
michael@0 | 57 | document.getElementById("container").appendChild(e); |
michael@0 | 58 | } |
michael@0 | 59 | for (var idx = 0; idx < 40; idx++) { |
michael@0 | 60 | var e = document.createElement("div"); |
michael@0 | 61 | e.setAttribute("id", "div-ver"); |
michael@0 | 62 | e.style.left = (idx*20) + "px"; |
michael@0 | 63 | document.getElementById("container").appendChild(e); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function getSelection(aElement) { |
michael@0 | 68 | if (aElement instanceof Ci.nsIDOMNSEditableElement) { |
michael@0 | 69 | return aElement.QueryInterface(Ci.nsIDOMNSEditableElement) |
michael@0 | 70 | .editor.selection; |
michael@0 | 71 | } |
michael@0 | 72 | return null; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function testCaretPosition(aDomWinUtils, aOffset, aRectDims) { |
michael@0 | 76 | let rect = aDomWinUtils.sendQueryContentEvent( |
michael@0 | 77 | aDomWinUtils.QUERY_CARET_RECT, |
michael@0 | 78 | aOffset, 0, 0, 0, |
michael@0 | 79 | aDomWinUtils.QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK); |
michael@0 | 80 | ok(rect, "rect returned"); |
michael@0 | 81 | ok(rect.succeeded, "call succeeded"); |
michael@0 | 82 | |
michael@0 | 83 | info("left:" + rect.left + " top:" + rect.top); |
michael@0 | 84 | |
michael@0 | 85 | ok(rect.left > aRectDims.min.left, "rect.left > " + aRectDims.min.left); |
michael@0 | 86 | ok(rect.left < aRectDims.max.left, "rect.left < " + aRectDims.max.left); |
michael@0 | 87 | ok(rect.top > aRectDims.min.top, "rect.top > " + aRectDims.min.top); |
michael@0 | 88 | ok(rect.top < aRectDims.max.top, "rect.top < " + aRectDims.max.top); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function doTest() { |
michael@0 | 92 | let domWinUtils = window.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 93 | .getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 94 | |
michael@0 | 95 | let text = document.getElementById("text"); |
michael@0 | 96 | |
michael@0 | 97 | text.focus(); |
michael@0 | 98 | |
michael@0 | 99 | let textrect = text.getBoundingClientRect(); |
michael@0 | 100 | |
michael@0 | 101 | let cp = document.caretPositionFromPoint(10, 395); |
michael@0 | 102 | let input = cp.offsetNode; |
michael@0 | 103 | let offset = cp.offset; |
michael@0 | 104 | input.selectionStart = input.selectionEnd = offset; |
michael@0 | 105 | |
michael@0 | 106 | let selection = getSelection(text); |
michael@0 | 107 | |
michael@0 | 108 | testCaretPosition(domWinUtils, input.selectionStart, { |
michael@0 | 109 | min: { left: 5, top: 380 }, |
michael@0 | 110 | max: { left: 25, top: 390 }, |
michael@0 | 111 | }); |
michael@0 | 112 | |
michael@0 | 113 | testCaretPosition(domWinUtils, input.selectionEnd, { |
michael@0 | 114 | min: { left: 5, top: 380 }, |
michael@0 | 115 | max: { left: 25, top: 390 }, |
michael@0 | 116 | }); |
michael@0 | 117 | |
michael@0 | 118 | testCaretPosition(domWinUtils, text.selectionStart, { |
michael@0 | 119 | min: { left: 5, top: 380 }, |
michael@0 | 120 | max: { left: 25, top: 390 }, |
michael@0 | 121 | }); |
michael@0 | 122 | |
michael@0 | 123 | testCaretPosition(domWinUtils, text.selectionEnd, { |
michael@0 | 124 | min: { left: 5, top: 380 }, |
michael@0 | 125 | max: { left: 25, top: 390 }, |
michael@0 | 126 | }); |
michael@0 | 127 | |
michael@0 | 128 | testCaretPosition(domWinUtils, selection.anchorOffset, { |
michael@0 | 129 | min: { left: 5, top: 380 }, |
michael@0 | 130 | max: { left: 25, top: 390 }, |
michael@0 | 131 | }); |
michael@0 | 132 | |
michael@0 | 133 | testCaretPosition(domWinUtils, selection.focusOffset, { |
michael@0 | 134 | min: { left: 5, top: 380 }, |
michael@0 | 135 | max: { left: 25, top: 390 }, |
michael@0 | 136 | }); |
michael@0 | 137 | |
michael@0 | 138 | cp = document.caretPositionFromPoint(395, 395); |
michael@0 | 139 | input = cp.offsetNode; |
michael@0 | 140 | offset = cp.offset; |
michael@0 | 141 | input.selectionStart = input.selectionEnd = offset; |
michael@0 | 142 | |
michael@0 | 143 | let selection = getSelection(text); |
michael@0 | 144 | |
michael@0 | 145 | testCaretPosition(domWinUtils, input.selectionStart, { |
michael@0 | 146 | min: { left: 390, top: 380 }, |
michael@0 | 147 | max: { left: 400, top: 390 }, |
michael@0 | 148 | }); |
michael@0 | 149 | |
michael@0 | 150 | testCaretPosition(domWinUtils, input.selectionEnd, { |
michael@0 | 151 | min: { left: 390, top: 380 }, |
michael@0 | 152 | max: { left: 400, top: 390 }, |
michael@0 | 153 | }); |
michael@0 | 154 | |
michael@0 | 155 | testCaretPosition(domWinUtils, text.selectionStart, { |
michael@0 | 156 | min: { left: 390, top: 380 }, |
michael@0 | 157 | max: { left: 400, top: 390 }, |
michael@0 | 158 | }); |
michael@0 | 159 | |
michael@0 | 160 | testCaretPosition(domWinUtils, text.selectionEnd, { |
michael@0 | 161 | min: { left: 390, top: 380 }, |
michael@0 | 162 | max: { left: 400, top: 390 }, |
michael@0 | 163 | }); |
michael@0 | 164 | |
michael@0 | 165 | testCaretPosition(domWinUtils, selection.anchorOffset, { |
michael@0 | 166 | min: { left: 390, top: 380 }, |
michael@0 | 167 | max: { left: 400, top: 390 }, |
michael@0 | 168 | }); |
michael@0 | 169 | |
michael@0 | 170 | testCaretPosition(domWinUtils, selection.focusOffset, { |
michael@0 | 171 | min: { left: 390, top: 380 }, |
michael@0 | 172 | max: { left: 400, top: 390 }, |
michael@0 | 173 | }); |
michael@0 | 174 | |
michael@0 | 175 | done(); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | </script> |
michael@0 | 179 | |
michael@0 | 180 | <body onload="doTest()"> |
michael@0 | 181 | <textarea id="text" wrap="on"> |
michael@0 | 182 | Alice was beginning to get very tired of sitting by her sister on the bank, |
michael@0 | 183 | and of having nothing to do: once or twice she had peeped into the book |
michael@0 | 184 | her sister was reading, but it had no pictures or conversations in it, |
michael@0 | 185 | `and what is the use of a book,' thought Alice `without pictures or |
michael@0 | 186 | conversation?' |
michael@0 | 187 | |
michael@0 | 188 | So she was considering in her own mind (as well as she could, for the |
michael@0 | 189 | hot day made her feel very sleepy and stupid), whether the pleasure of |
michael@0 | 190 | making a daisy-chain would be worth the trouble of getting up and |
michael@0 | 191 | picking the daisies, when suddenly a White Rabbit with pink In another |
michael@0 | 192 | moment down went Alice after it, never once considering how in the world |
michael@0 | 193 | she was to get out again. |
michael@0 | 194 | |
michael@0 | 195 | The rabbit-hole went straight on like a tunnel for some way, and then |
michael@0 | 196 | dipped suddenly down, so suddenly that Alice had not a moment to think |
michael@0 | 197 | about stopping herself before she found herself falling down a very deep |
michael@0 | 198 | well. |
michael@0 | 199 | |
michael@0 | 200 | Either the well was very deep, or she fell very slowly, for she had |
michael@0 | 201 | plenty of time as she went down to look about her and to wonder what was |
michael@0 | 202 | going to happen next. First, she tried to look down and make out what |
michael@0 | 203 | she was coming to, but it was too dark to see anything; then she looked |
michael@0 | 204 | at the sides of the well, and noticed that they were filled with |
michael@0 | 205 | cupboards and book-shelves; here and there she saw maps and pictures |
michael@0 | 206 | hung upon pegs. She took down a jar from one of the shelves as she |
michael@0 | 207 | passed; it was labelled `ORANGE MARMALADE', but to her great |
michael@0 | 208 | disappointment it was empty: she did not like to drop the jar for fear |
michael@0 | 209 | of killing somebody, so managed to put it into one of the cupboards as |
michael@0 | 210 | she fell past it. |
michael@0 | 211 | </textarea> |
michael@0 | 212 | <div id="container"></div> |
michael@0 | 213 | </body> |
michael@0 | 214 | </html> |