Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / style / text-indent.html
blob89334a5f20f28055ddb2984493c601907e4d382a
1 <!DOCTYPE html>
2 <html>
3 <head>
4 </head>
5 <body>
6 </body>
7 <script>
8 function testTextIndent(testContent, characterIndex)
10 document.body.innerHTML = testContent;
11 var editor = document.getElementById('textIndentTest');
12 editor.focus();
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";
25 else
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');
33 editor.focus();
35 var caretRect = textInputController.firstRectForCharacterRange(0, 0);
36 var caretXPosition_withoutTextIndent = caretRect[0];
38 editor.blur();
39 editor.style.textIndent = textIndent + "px";
40 editor.focus();
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";
48 else
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();
55 var output = "";
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;
65 </script>
66 </html>