summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/editing/inserting/caret-position.html
blob: e7e60705d65a916e0dc710d583879c470a02e73d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<html>
<head>
<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
<script>

function log(str) {
    var li = document.createElement("li");
    li.appendChild(document.createTextNode(str));
    var console = document.getElementById("console");
    console.appendChild(li);
}

function assertEqual(test_name, actual, expected)
{
    if (actual != expected) {
        log("==================================");
        log("FAILED: " + test_name);
        log("actual: " + actual);
        log("expected: " + expected);
    }
}
function testCaretPosition(elementId, caretPosition)
{
    e = document.getElementById(elementId, caretPosition);
    e.focus();
    if (window.textInputController) {
        var caretRect = textInputController.firstRectForCharacterRange(0, 0);
        assertEqual(elementId, caretRect[0], caretPosition);
    }  
}

function runTest()
{
    if (window.layoutTestController)
        layoutTestController.dumpAsText();
    var e = document.getElementById("right-align-div");
    e.focus();
    selectAllCommand();
    typeCharacterCommand();
    if (window.textInputController) {
        var caretRect = textInputController.firstRectForCharacterRange(1, 0);
        assertEqual("right-align-div", caretRect[0], 208);
    }

    testCaretPosition("rtl-div", 208);
    testCaretPosition("0-right-padding-rtl-textarea", 206);
    testCaretPosition("ltr-div", 9);
    testCaretPosition("ltr-textarea", 10);
    testCaretPosition("no-wrapping-right-align-div", 208);
    testCaretPosition("no-wrapping-rtl-div", 208);
    testCaretPosition("no-wrapping-0-right-padding-rtl-textarea", 206);
    testCaretPosition("no-wrapping-ltr-div", 9);
    testCaretPosition("no-wrapping-ltr-textarea", 10);
}

</script>
</head>
<body>
<br>
Right aligned div.
<br>
<div CONTENTEDITABLE id="right-align-div" style="text-align: right; width:200px; border: solid thin;"></div> 
<br>
RTL div.
<br>
<div CONTENTEDITABLE id="rtl-div" style="direction: rtl; width:200px; border: solid thin; ">a</div> 
<br>
0px right padding RTL textarea.
<br>
<textarea id="0-right-padding-rtl-textarea" style="direction:rtl; padding: 1px 0px 1px 1px; width:200px">a</textarea>
<br>
LTR div and textarea.
<br>
<div CONTENTEDITABLE id="ltr-div" style="width:200px; border: solid thin; ">a</div> 
<br>
<textarea id="ltr-textarea" style="padding: 1px 0px 1px 1px; width:200px">a</textarea>
<br>
NO WRAPPING
<br>
No wrapping right aligned div.
<br>
<div CONTENTEDITABLE id="no-wrapping-right-align-div" style="white-space:nowrap; text-align: right; width:200px; border: solid thin;"></div> 
<br>
No wrapping RTL div.
<br>
<div CONTENTEDITABLE id="no-wrapping-rtl-div" style="white-space:nowrap; direction: rtl; width:200px; border: solid thin; ">a</div> 
<br>
No wrapping 0px right padding RTL textarea.
<br>
<textarea id="no-wrapping-0-right-padding-rtl-textarea" style="white-space:nowrap; direction:rtl; padding: 1px 0px 1px 1px; width:200px">a</textarea>
<br>
No wrapping LTR div and textarea.
<br>
<div CONTENTEDITABLE id="no-wrapping-ltr-div" style="white-space:nowrap; width:200px; border: solid thin; ">a</div> 
<br>
<textarea id="no-wrapping-ltr-textarea" style="white-space:nowrap; padding: 1px 0px 1px 1px; width:200px">a</textarea>
<br>
<ul id="console"></ul>
</body>
<script> runTest(); </script>
</html>