summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/editing/selection/move-vertically-with-paddings-borders.html
blob: 3b30645fd4c6b83b5f5ab72769f3e825af8de072 (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
<!DOCTYPE html>
<html>
<head>
<style>

#tests p {
    font-size: 20px;
    width: 12ex;
    word-wrap: normal;
}

</style>
<script src="../../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<p>This test ensures WebKit takes paddings and borders into account when moving vertically.</p>
<ol id="tests">
<li><p contenteditable>left1 <a href="">right1 left2</a> right2</p></li>
<li><p contenteditable>left1 <a style="border: solid 5px blue;" href="">right1 left2</a> right2</p></li>
<li><p contenteditable>left1 <a style="padding: 5px;" href="">right1 left2</a> right2</p></li>
<li><p contenteditable>left1 <a style="padding: 5px;" href="">right1 left2 right2 left3</a> right3</p></li>
</ol>
<div id="console"></div>
<script>

function moveToMiddleOfWord(node, word) {
    window.getSelection().setPosition(node, 0);
    if (!window.find(word))
        return false;
    window.getSelection().modify('move', 'backward', 'character');
    window.getSelection().modify('move', 'forward', 'character');
    window.getSelection().modify('move', 'forward', 'character');
    return true;
}

function selectWord() {
    window.getSelection().modify('move', 'backward', 'word');
    window.getSelection().modify('extend', 'forward', 'word');
    return getSelection().toString().trim();
}

function moveVerticallyAndVerify(node, direction, from, to) {
    if (node.innerText.indexOf(from) === -1 || node.innerText.indexOf(to) === -1)
        return;
    if (!moveToMiddleOfWord(node, from))
        return;
    window.getSelection().modify('move', direction, 'line');
    shouldBe('selectWord()', '"' + to + '"');
}

var tests = document.getElementById('tests').getElementsByTagName('p');
for (var i = 0; i < tests.length; i++) {
    var node = tests[i];

    debug('test ' + (i + 1));

    node.focus();
    for (var j = 1; j <= 2; j++) {
        moveVerticallyAndVerify(node, 'forward', 'left' + j, 'left' + (j + 1));
        moveVerticallyAndVerify(node, 'forward', 'right' + j, 'right' + (j + 1));
        moveVerticallyAndVerify(node, 'backward', 'left' + (j + 1), 'left' + j);
        moveVerticallyAndVerify(node, 'backward', 'right' + (j + 1), 'right' + j);
    }

    debug('');
}

document.getElementById('tests').style.display = 'none';

</script>
<script src="../../fast/js/resources/js-test-post.js"></script>
</body>
</html>