summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/focus-selection-input.html
blob: d7c8c2b878ffc6869b0982177faecf806d862fc8 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<body onload="runTest()">
<script src="../../resources/js-test.js"></script>

<script>
function runTest()
{
    if (!window.testRunner)
        return;

    testRunner.dumpEditingCallbacks();
    testRunner.dumpAsText();

    shouldBe("first.selectionStart", "12");
    shouldBe("first.selectionEnd", "19");
    eventSender.keyDown("\t");
    shouldBe("first.selectionStart", "0");
    shouldBe("first.selectionEnd", "19");

    shouldBe("second.selectionStart", "11");
    shouldBe("second.selectionEnd", "18");
    eventSender.keyDown("J", "accessKey");
    shouldBe("second.selectionStart", "11");
    shouldBe("second.selectionEnd", "18");

    shouldBe("third.selectionStart", "11");
    shouldBe("third.selectionEnd", "18");
    third.focus();
    shouldBe("third.selectionStart", "11");
    shouldBe("third.selectionEnd", "18");

    shouldBe("fourth.selectionStart", "12");
    shouldBe("fourth.selectionEnd", "19");
    eventSender.mouseMoveTo(fourth.offsetLeft + 4, fourth.offsetTop + 4);
    eventSender.mouseDown();
    eventSender.mouseUp();
    shouldBe("fourth.selectionStart", "0");
    shouldBe("fourth.selectionEnd", "0");

    shouldBe("fifth.selectionStart", "11");
    shouldBe("fifth.selectionEnd", "18");
    var fifthLabel = document.getElementById("fifthLabel");
    eventSender.mouseMoveTo(fifthLabel.offsetLeft + 4, fifthLabel.offsetTop + 4);
    eventSender.mouseDown();
    eventSender.mouseUp();
    shouldBe("fifth.selectionStart", "11");
    shouldBe("fifth.selectionEnd", "18");

    shouldBe("sixth.selectionStart", "12");
    shouldBe("sixth.selectionEnd", "19");
    eventSender.keyDown("U", "accessKey");
    shouldBe("sixth.selectionStart", "0");
    shouldBe("sixth.selectionEnd", "19");

    shouldBe("seventh.selectionStart", "11");
    shouldBe("seventh.selectionEnd", "18");
    var seventLabel = document.getElementById("seventhLabel");
    seventhLabel.focus();
    shouldBe("seventh.selectionStart", "11");
    shouldBe("seventh.selectionEnd", "18");

    shouldBe("eighth.selectionStart", "12");
    shouldBe("eighth.selectionEnd", "19");
    var eighthLegend = document.getElementById("eighthLegend");
    eighthLegend.focus();
    shouldBe("eighth.selectionStart", "0");
    shouldBe("eighth.selectionEnd", "19");

    shouldBe("ninth.selectionStart", "12");
    shouldBe("ninth.selectionEnd", "19");
    eventSender.keyDown("I", "accessKey");
    shouldBe("ninth.selectionStart", "0");
    shouldBe("ninth.selectionEnd", "19");

}
</script>

<h2>&lt;input type="text"&gt; focus selection</h2>

<p>This test checks whether the selection is restored, cleared, or set
to the full range when using different ways to focus a text field. These
results all match Mozilla, except test 6, which selects
the whole field contents to match all other cases of keyboard
focus. When running manually, please follow the steps below. In the
test harness, the test runs automatically.</p>

1) Hit tab, the whole phrase "SUCCESS and SUCCESS" should be selected:
<input type="text" id="first" value="SUCCESS and SUCCESS">
<script>
    var first = document.getElementById("first");
    first.focus();
    first.setSelectionRange(12, 19);
    first.blur();
</script>

<br>

2) Hit Ctrl-Option-J (or Alt-J on Windows), the whole phrase "SUCCESS and SUCCESS" should be selected:
<input type="text" id="second" accesskey="j" value="SUCCESS and SUCCESS">
<script>
    var second = document.getElementById("second");
    second.focus();
    second.setSelectionRange(12, 19);
    second.blur();
</script>

<br>

3) <input type="button" onclick="document.getElementById('third').focus()" value="Click this button">, only the word "SUCCESS" should be selected:
<input type="text" id="third" value="FAILURE or SUCCESS">
<script>
    var third = document.getElementById("third");
    third.focus();
    third.setSelectionRange(11, 18);
    third.blur();
</script>

<br>

4) Click in the input field, nothing should be selected:
<input type="text" id="fourth" value="FAILURE and FAILURE">
<script>
    var fourth = document.getElementById("fourth");
    fourth.focus();
    fourth.setSelectionRange(12, 19);
    fourth.blur();
</script>

<br>

5) <label id="fifthLabel" for="fifth" style="color: blue">Click this label, only the word "SUCCESS" should be selected:</label>
<input type="text" id="fifth" value="FAILURE or SUCCESS">
<script>
    var second = document.getElementById("fifth");
    fifth.focus();
    fifth.setSelectionRange(11, 18);
    fifth.blur();
</script>

<br>

6) <label id="sixthLabel" for="sixth" accesskey="u">Hit Ctrl-Option-U (or Alt-U on Windows), the whole phrase "SUCCESS and SUCCESS" should be selected:</label>
<input type="text" id="sixth" value="SUCCESS and SUCCESS">
<script>
    var sixth = document.getElementById("sixth");
    sixth.focus();
    sixth.setSelectionRange(12, 19);
    sixth.blur();
</script>

<br>

7) <input type="button" onclick="document.getElementById('seventhLabel').focus()" value="Click this button"><label id="seventhLabel" for="seventh">, only the word "SUCCESS" should be selected:</label>
<input type="text" id="seventh" value="FAILURE or SUCCESS">
<script>
    var seventh = document.getElementById("seventh");
    seventh.focus();
    seventh.setSelectionRange(11, 18);
    seventh.blur();
</script>

<br>

8) <input type="button" onclick="document.getElementById('eighthLegend').focus()" value="Click this button">
<fieldset>
<legend id="eighthLegend">, the whole phrase "SUCCESS and SUCCESS" should be selected:</legend>
<input type="text" id="eighth" value="SUCCESS and SUCCESS">
<script>
    var eighth = document.getElementById("eighth");
    eighth.focus();
    eighth.setSelectionRange(12, 19);
    eighth.blur();
</script>
</fieldset>
<br>


9) <fieldset>
<legend id="eighthLegend" accesskey="i">Hit Ctrl-Option-I (or Alt-I on Windows), the whole phrase "SUCCESS and SUCCESS" should be selected:</legend>
<input type="text" id="ninth" value="SUCCESS and SUCCESS">
<script>
    var ninth = document.getElementById("ninth");
    ninth.focus();
    ninth.setSelectionRange(12, 19);
    ninth.blur();
</script>
</fieldset>
<br>

<p id="description"></p>
<div id="console"></div>

</body>