4 if (window
.testRunner
) {
5 testRunner
.dumpAsText();
6 internals
.settings
.setSmartInsertDeleteEnabled(false);
7 internals
.settings
.setSelectTrailingWhitespaceEnabled(true);
10 function getPositionOfNode(id
)
12 var n
= document
.getElementById(id
);
13 var pos
= {x
: 0, y
: 0};
16 pos
.x
+= n
.offsetLeft
+ n
.clientLeft
;
17 pos
.y
+= n
.offsetTop
+ n
.clientTop
;
23 function doubleClickPosition(pos
)
25 // Our test cases will have at most a single leading tab or four spaces,
26 // followed by a word which is wider than 4 "X"s.
27 // So, pos.x + CHAR_WIDTH * 4 always hits the words.
28 eventSender
.mouseMoveTo(pos
.x
+ CHAR_WIDTH
* 4, pos
.y
+ LINE_HEIGHT
/ 2);
29 eventSender
.mouseDown();
30 eventSender
.leapForward(1);
31 eventSender
.mouseUp();
32 eventSender
.leapForward(50);
33 eventSender
.mouseDown();
34 eventSender
.leapForward(1);
35 eventSender
.mouseUp();
40 doubleClickPosition({x
:0, y
:0});
43 function findParentDiv(spanId
)
45 var n
= document
.getElementById(spanId
);
47 var parent
= n
.parentNode
;
48 if (parent
&& parent
.tagName
== "DIV")
56 function makeParentBlockEditable(spanId
)
58 var parent
= findParentDiv(spanId
);
59 parent
.contentEditable
= true;
62 function hideCaseBlockFor(spanId
)
64 var n
= document
.getElementById(spanId
);
67 if (n
&& n
.className
== "case") {
68 n
.style
.display
= "none";
75 function doTest(testId
, expectedText
, givenClickPosition
)
77 // Simulate a double click.
79 var pos
= givenClickPosition
|| getPositionOfNode(testId
);
80 doubleClickPosition(pos
);
82 // Get the text of the current selection.
83 var sel
= window
.getSelection();
84 var actualText
= sel
.getRangeAt(0).toString();
86 if (expectedText
== actualText
) {
87 log("Passed " + testId
);
89 log("Failed " + testId
);
90 log(" Expected: " + expectedText
);
91 log(" Actual: " + actualText
);
94 // Run the same case with contentEditable enabled.
95 makeParentBlockEditable(testId
);
98 doubleClickPosition(pos
);
100 sel
= window
.getSelection();
101 actualText
= sel
.getRangeAt(0).toString();
103 if (expectedText
== actualText
) {
104 log("Passed " + testId
+ " (with contentEditable)");
106 log("Failed " + testId
+ " (with contentEditable)");
107 log(" Expected: " + expectedText
);
108 log(" Actual: " + actualText
);
111 // Hide a container for the case to workaround limited window size
112 hideCaseBlockFor(testId
);
117 var l
= document
.getElementById('log');
118 l
.appendChild(document
.createTextNode(msg
));
119 l
.appendChild(document
.createElement('br'));
122 function initConstants()
124 var heightMeasure
= document
.getElementById("heightMeasure");
125 LINE_HEIGHT
= heightMeasure
.offsetHeight
;
126 LINE_LEFT
= heightMeasure
.offsetLeft
+ heightMeasure
.clientLeft
;
127 CHAR_WIDTH
= heightMeasure
.offsetWidth
;
128 heightMeasure
.style
.display
= "none"; // hide for readable test result
131 function getPositionOfNextLineHeadOf(spanId
)
133 var pos
= getPositionOfNode(spanId
)
135 pos
.y
+= LINE_HEIGHT
;
143 if (window
.testRunner
) {
144 doTest("totest_minimum", "select1");
145 // We may have to make EditorClient::isSelectTrailingWhitespaceEnabled false on
146 // DumpRenderTree to clarify cases...
147 doTest("totest_before_after", "select2 ");
149 doTest("totest_linebreak_out", "select3\n");
150 doTest("totest_tab_out", "select4\t");
151 doTest("totest_multiple_whitespaces_out", "select5 ");
152 doTest("totest_linebreak_in", "select6\n");
153 doTest("totest_tab_in", "select7\t");
154 doTest("totest_multiple_whitespaces_in", "select8 ");
156 doTest("totest_multiple_word_in_span", "select9 ");
157 doTest("totest_word_before_here_in_line", "select10 ");
158 doTest("totest_span_first_half", "select11 ");
159 doTest("totest_span_second_half", "selectHere12 ");
161 doTest("totest_linebreak_out_pre", "select1");
162 doTest("totest_tab_out_pre", "select2\t");
163 doTest("totest_multiple_whitespaces_out_pre", "select3 ");
164 doTest("totest_linebreak_in_pre", "select4", getPositionOfNextLineHeadOf("totest_linebreak_in_pre"));
165 doTest("totest_tab_in_pre", "select5\t");
166 doTest("totest_multiple_whitespaces_in_pre", "select6 ");
168 doTest("totest_linebreak_out_prewrap", "select1");
169 doTest("totest_tab_out_prewrap", "select2\t");
170 doTest("totest_multiple_whitespaces_out_prewrap", "select3 ");
171 doTest("totest_linebreak_in_prewrap", "select4", getPositionOfNextLineHeadOf("totest_linebreak_in_prewrap"));
172 doTest("totest_tab_in_prewrap", "select5\t", getPositionOfNextLineHeadOf("totest_tab_in_prewrap"));
173 doTest("totest_multiple_whitespaces_in_prewrap", "select6 ", getPositionOfNextLineHeadOf("totest_multiple_whitespaces_in_prewrap"));
175 doTest("totest_linebreak_out_preline", "select1\n");
176 doTest("totest_tab_out_preline", "select2\t");
177 doTest("totest_multiple_whitespaces_out_preline", "select3 ");
178 doTest("totest_linebreak_in_preline", "select4\n", getPositionOfNextLineHeadOf("totest_linebreak_in_preline"));
179 doTest("totest_tab_in_preline", "select5\t");
180 doTest("totest_multiple_whitespaces_in_preline", "select6 ");
182 doTest("totest_linebreak_out_nowrap", "select1\n");
183 doTest("totest_tab_out_nowrap", "select2\t");
184 doTest("totest_multiple_whitespaces_out_nowrap", "select3 ");
185 doTest("totest_linebreak_in_nowrap", "select4\n");
186 doTest("totest_tab_in_nowrap", "select5\t");
187 doTest("totest_multiple_whitespaces_in_nowrap", "select6 ");
195 <body onload=
"runTests()">
198 This tests that double-clicking a word that follows newline and span
202 <h3>minimum case
</h3>
203 <div style=
"width:100pt">
204 abcd efgh ijkl mnop
<b id=
"totest_minimum">select1
</b>
209 <h3>with another word after the span
</h3>
210 <div style=
"width:100pt">
211 abcd efgh ijkl mnop
<b id=
"totest_before_after">select2
</b> nottoselect
216 <h3>use linebreak as word separator (outside element)
</h3>
217 <div style=
"width:100pt">
219 <b id=
"totest_linebreak_out">select3
</b>
225 <h3>use tab as word separator (outside element)
</h3>
226 <div style=
"width:100pt">
227 abcd efgh ijkl mnop
<b id=
"totest_tab_out">select4
</b> nottoselect
232 <h3>use multiple whitespaces as word separator (outside element)
</h3>
233 <div style=
"width:100pt">
234 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_out">select5
</b> nottoselect
239 <h3>use linebreak as word separator (inside element)
</h3>
240 <div style=
"width:100pt">
241 abcd efgh ijkl mnop
<b id=
"totest_linebreak_in">
248 <h3>use tab as word separator (inside element)
</h3>
249 <div style=
"width:100pt">
250 abcd efgh ijkl mnop
<b id=
"totest_tab_in"> select7
</b>nottoselect
255 <h3>use multiple whitespaces as word separator (inside element)
</h3>
256 <div style=
"width:100pt">
257 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_in"> select8
</b>nottoselect
262 <h3>with another word in same the span
</h3>
263 <div style=
"width:100pt">
264 abcd efgh ijkl mnop
<b id=
"totest_multiple_word_in_span">select9 not
</b> notyet
269 <h3>with another word before the span, in the same line
</h3>
270 <div style=
"width:100pt">
271 abcd efgh ijkl mnop qrst
<b id=
"totest_word_before_here_in_line">select10
</b> notyet
276 <h3>a first half of word is inside b element
</h3>
277 <div style=
"width:100pt">
278 abcd efgh ijkl mnop qrst
<b id=
"totest_span_first_half">sel
</b>ect11 notyet
283 <h3>a second half of word is inside b element
</h3>
284 <!-- We choose selectHere12 instead select12 here
285 because <b>ect12</b> would be too short to be clicked by doubleClickPosition(). -->
286 <div style=
"width:150pt">
287 abcd efgh ijkl mnop qrst uvwx yz123 sel
<b id=
"totest_span_second_half">ectHere12
</b> notyet
291 <h2>cases for white-space: pre
</h2>
293 Note: Here for pre, we change width value to
200 to prevent layout change on contentEditable enabled.
297 <h3>use linebreak as word separator (outside element, white-space:pre)
</h3>
298 <div style=
"width:200pt;white-space:pre;">
300 <b id=
"totest_linebreak_out_pre">select1
</b>
306 <h3>use tab as word separator (outside element, white-space:pre)
</h3>
307 <div style=
"width:200pt;white-space:pre;">
308 abcd efgh ijkl mnop
<b id=
"totest_tab_out_pre">select2
</b> nottoselect
313 <h3>use multiple whitespaces as word separator (outside element, white-space:pre)
</h3>
314 <div style=
"width:200pt;white-space:pre;">
315 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_out_pre">select3
</b> nottoselect
320 <h3>use linebreak as word separator (inside element, white-space:pre)
</h3>
321 <div style=
"width:200pt;white-space:pre;">
322 abcd efgh ijkl mnop
<b id=
"totest_linebreak_in_pre">
329 <h3>use tab as word separator (inside element, white-space:pre)
</h3>
330 <div style=
"width:200pt;white-space:pre;">
331 abcd efgh ijkl mnop
<b id=
"totest_tab_in_pre"> select5
</b>nottoselect
336 <h3>use multiple whitespaces as word separator (inside element, white-space:pre)
</h3>
337 <div style=
"width:200pt;white-space:pre;">
338 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_in_pre"> select6
</b>nottoselect
342 <h2>cases for white-space: pre-wrap
</h2>
345 <h3>use linebreak as word separator (outside element, white-space:pre-wrap)
</h3>
346 <div style=
"width:100pt;white-space:pre-wrap;">
348 <b id=
"totest_linebreak_out_prewrap">select1
</b>
354 <h3>use tab as word separator (outside element, white-space:pre-wrap)
</h3>
355 <div style=
"width:100pt;white-space:pre-wrap;">
356 abcd efgh ijkl mnop
<b id=
"totest_tab_out_prewrap">select2
</b> nottoselect
361 <h3>use multiple whitespaces as word separator (outside element, white-space:pre-wrap)
</h3>
362 <div style=
"width:100pt;white-space:pre-wrap;">
363 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_out_prewrap">select3
</b> nottoselect
368 <h3>use linebreak as word separator (inside element, white-space:pre-wrap)
</h3>
369 <div style=
"width:100pt;white-space:pre-wrap;">
370 abcd efgh ijkl mnop
<b id=
"totest_linebreak_in_prewrap">
377 <h3>use tab as word separator (inside element, white-space:pre-wrap)
</h3>
378 <div style=
"width:100pt;white-space:pre-wrap;">
379 abcd efgh ijkl mnop
<b id=
"totest_tab_in_prewrap"> select5
</b>nottoselect
384 <h3>use multiple whitespaces as word separator (inside element, white-space:pre-wrap)
</h3>
385 <div style=
"width:100pt;white-space:pre-wrap;">
386 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_in_prewrap"> select6
</b>nottoselect
392 <h2>cases for white-space: pre-line
</h2>
395 <h3>use linebreak as word separator (outside element, white-space:pre-line)
</h3>
396 <div style=
"width:100pt;white-space:pre-line;">
398 <b id=
"totest_linebreak_out_preline">select1
</b>
404 <h3>use tab as word separator (outside element, white-space:pre-line)
</h3>
405 <div style=
"width:100pt;white-space:pre-line;">
406 abcd efgh ijkl mnop
<b id=
"totest_tab_out_preline">select2
</b> nottoselect
411 <h3>use multiple whitespaces as word separator (outside element, white-space:pre-line)
</h3>
412 <div style=
"width:100pt;white-space:pre-line;">
413 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_out_preline">select3
</b> nottoselect
418 <h3>use linebreak as word separator (inside element, white-space:pre-line)
</h3>
419 <div style=
"width:100pt;white-space:pre-line;">
420 abcd efgh ijkl mnop
<b id=
"totest_linebreak_in_preline">
427 <h3>use tab as word separator (inside element, white-space:pre-line)
</h3>
428 <div style=
"width:100pt;white-space:pre-line;">
429 abcd efgh ijkl mnop
<b id=
"totest_tab_in_preline"> select5
</b>nottoselect
434 <h3>use multiple whitespaces as word separator (inside element, white-space:pre-line)
</h3>
435 <div style=
"width:100pt;white-space:pre-line;">
436 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_in_preline"> select6
</b>nottoselect
440 <h2>cases for white-space: nowrap
</h2>
442 Note: Although following cases have no line-breaks that had caused problem reported bug28036,
443 we add these for comprehensiveness.
447 <h3>use linebreak as word separator (outside element, white-space:nowrap)
</h3>
448 <div style=
"width:100pt;white-space:nowrap;">
450 <b id=
"totest_linebreak_out_nowrap">select1
</b>
456 <h3>use tab as word separator (outside element, white-space:nowrap)
</h3>
457 <div style=
"width:100pt;white-space:nowrap;">
458 abcd efgh ijkl mnop
<b id=
"totest_tab_out_nowrap">select2
</b> nottoselect
463 <h3>use multiple whitespaces as word separator (outside element, white-space:nowrap)
</h3>
464 <div style=
"width:100pt;white-space:nowrap;">
465 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_out_nowrap">select3
</b> nottoselect
470 <h3>use linebreak as word separator (inside element, white-space:nowrap)
</h3>
471 <div style=
"width:100pt;white-space:nowrap;">
472 abcd efgh ijkl mnop
<b id=
"totest_linebreak_in_nowrap">
479 <h3>use tab as word separator (inside element, white-space:nowrap)
</h3>
480 <div style=
"width:100pt;white-space:nowrap;">
481 abcd efgh ijkl mnop
<b id=
"totest_tab_in_nowrap"> select5
</b>nottoselect
486 <h3>use multiple whitespaces as word separator (inside element, white-space:nowrap)
</h3>
487 <div style=
"width:100pt;white-space:nowrap;">
488 abcd efgh ijkl mnop
<b id=
"totest_multiple_whitespaces_in_nowrap"> select6
</b>nottoselect
494 <h2>cases for source-originated line-breaks with white-space: pre-* family</h2>
497 <h3>white-space:pre</h3>
498 <div style="width:200pt;white-space:pre;background-color:lightgray;">
500 <b id="totest_sourcebreak_pre">select1</b>
505 <h3>white-space:pre-wrap</h3>
506 <div style="width:200pt;white-space:pre-wrap;background-color:lightgray;">
508 <b id="totest_sourcebreak_prewrap">select2</b>
513 <h3>white-space:pre-line</h3>
514 <div style="width:200pt;white-space:pre-line;background-color:lightgray;">
516 <b id="totest_sourcebreak_preline">select3</b>
523 <div><span id=
"heightMeasure">x
</span></div>