8 function testTextIndent(testContent
, characterIndex
)
10 document
.body
.innerHTML
= testContent
;
11 var editor
= document
.getElementById('textIndentTest');
14 var caretRect
= textInputController
.firstRectForCharacterRange(0, 0);
15 var caretXPosition_withoutTextRender
= caretRect
[0];
17 editor
.setSelectionRange(0, 0);
18 document
.execCommand('InsertText', false, 'a');
20 caretRect
= textInputController
.firstRectForCharacterRange(characterIndex
, 0);
21 var caretXPosition_withTextRender
= caretRect
[0];
23 if (caretXPosition_withoutTextRender
== caretXPosition_withTextRender
)
24 return "Success. The caret's x positions of empty&nonempty input field were the same.\n";
26 return "Failure. The caret's x position of empty input field was " + caretXPosition_withoutTextRender
+ ", should have been " + caretXPosition_withTextRender
+ ".\n";
29 function testTextIndentWhenTextAlignsToCenter(textIndent
)
31 document
.body
.innerHTML
= "<input id='textIndentTest' type='text' style='text-align:center;'>";
32 var editor
= document
.getElementById('textIndentTest');
35 var caretRect
= textInputController
.firstRectForCharacterRange(0, 0);
36 var caretXPosition_withoutTextIndent
= caretRect
[0];
39 editor
.style
.textIndent
= textIndent
+ "px";
42 caretRect
= textInputController
.firstRectForCharacterRange(0, 0);
43 var caretXPosition_withTextIndent
= caretRect
[0];
45 var desiredCaretXPosition
= caretXPosition_withoutTextIndent
+ textIndent
/ 2;
46 if (desiredCaretXPosition
== caretXPosition_withTextIndent
)
47 return "Success. The caret's x positions was set to desired position when the text-align is center.\n";
49 return "Failure. The caret's x position of input field was " + caretXPosition_withTextIndent
+ ", should have been " + desiredCaretXPosition
+ ".\n";
52 if (window
.testRunner
)
53 window
.testRunner
.dumpAsText();
56 output
+= testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;'></input>", 0);
57 output
+= testTextIndent("<input id='textIndentTest' type='text' style='text-indent:-30px;'>", 0);
58 output
+= testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;text-align:left'>", 0);
59 output
+= testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;text-align:right'>", 1);
60 output
+= testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;direction:rtl;'>", 0);
61 output
+= testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;direction:rtl;text-align:right;'>", 0);
62 output
+= testTextIndentWhenTextAlignsToCenter(30);
63 output
+= testTextIndentWhenTextAlignsToCenter(-30);
64 document
.body
.innerText
= output
;