1<!DOCTYPE html>
2<html>
3<head>
4<script src="../../../resources/js-test.js"></script>
5<script src="../../../resources/ui-helper.js"></script>
6<style>
7body.hide-everything-except-test-container > :not(#test-container) {
8 display: none;
9}
10</style>
11</head>
12<body>
13<div id="test-container">
14 <p>Here's to the crazy ones.</p>
15 <p>The misfits.</p>
16 <p>The rebels.</p>
17</div>
18<script>
19let testContainer = document.getElementById("test-container");
20let paragraphs = testContainer.children;
21let selection = window.getSelection();
22
23function toggleOnlyShowTestContainer()
24{
25 document.body.classList.toggle("hide-everything-except-test-container");
26}
27
28async function testExtendSelectionToNextCharacter()
29{
30 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[0].firstChild, 0, paragraphs[0].firstChild, 1), document, "selectionchange");
31
32 debug("<br>Press Shift + right arrow to select the next character:");
33 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("rightArrow", ["shiftKey"]) , document, "selectionchange");
34 shouldBeEqualToString("window.getSelection().toString()", "He");
35}
36
37async function testExtendSelectionToPreviousCharacter()
38{
39 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[0].firstChild, 3, paragraphs[0].firstChild, 1), document, "selectionchange");
40
41 debug("<br>Press Shift + left arrow to select the previous character:");
42 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("leftArrow", ["shiftKey"]) , document, "selectionchange");
43 shouldBeEqualToString("window.getSelection().toString()", "Her");
44}
45
46async function testExtendSelectionToEndOfWord()
47{
48 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[0].firstChild, 0, paragraphs[0].firstChild, 1), document, "selectionchange");
49
50 debug("<br>Press Shift + Option + right arrow to select to the end of the word:");
51 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("rightArrow", ["shiftKey", "altKey"]) , document, "selectionchange");
52 shouldBeEqualToString("window.getSelection().toString()", "Here's ");
53}
54
55async function testExtendSelectionToBeginningOfWord()
56{
57 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[1].firstChild, 3, paragraphs[1].firstChild, 1), document, "selectionchange");
58
59 debug("<br>Press Shift + Option + left arrow to select to the beginning of the word:");
60 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("leftArrow", ["shiftKey", "altKey"]) , document, "selectionchange");
61 shouldBeEqualToString("window.getSelection().toString()", "The");
62}
63
64async function textExtendSelectionToEndOfLine()
65{
66 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[0].firstChild, 0, paragraphs[0].firstChild, 1), document, "selectionchange");
67
68 debug("<br>Press Shift + Control + right arrow to select to the end of the line:");
69 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("rightArrow", ["shiftKey", "ctrlKey"]) , document, "selectionchange");
70 shouldBeEqualToString("window.getSelection().toString()", "Here's to the crazy ones.");
71}
72
73async function testExtendSelectionToBeginningOfLine()
74{
75 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[1].firstChild, paragraphs[1].firstChild.length, paragraphs[1].firstChild, paragraphs[1].firstChild.length - 1), document, "selectionchange");
76
77 debug("<br>Press Shift + Control + left arrow to select to the beginning of the line:");
78 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("leftArrow", ["shiftKey", "ctrlKey"]) , document, "selectionchange");
79 shouldBeEqualToString("window.getSelection().toString()", "The misfits.");
80}
81
82async function testExtendSelectionUp()
83{
84 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[1].firstChild, 1, paragraphs[1].firstChild, 0), document, "selectionchange");
85
86 debug("<br>Press Shift + up arrow to select up:");
87 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("upArrow", ["shiftKey"]) , document, "selectionchange");
88 shouldBeEqualToString("window.getSelection().toString()", "Here's to the crazy ones.\n\nT");
89}
90
91async function testExtendSelectionDown()
92{
93 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[1].firstChild, 0, paragraphs[1].firstChild, 1), document, "selectionchange");
94
95 debug("<br>Press Shift + down arrow to select down:");
96 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("downArrow", ["shiftKey"]) , document, "selectionchange");
97 shouldBeEqualToString("window.getSelection().toString()", "The misfits.\n\nT");
98}
99
100async function testExtendSelectionToEndOfParagraph()
101{
102 toggleOnlyShowTestContainer();
103
104 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[0].firstChild, 0, paragraphs[0].firstChild, 1), document, "selectionchange");
105
106 debug("<br>Press Shift + Option + down arrow to select to the end of the paragraph:");
107 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("downArrow", ["shiftKey", "altKey"]) , document, "selectionchange");
108 shouldBeEqualToString("window.getSelection().toString()", "Here's to the crazy ones.");
109
110 toggleOnlyShowTestContainer();
111}
112
113async function testExtendSelectionToBeginningOfParagraph()
114{
115 toggleOnlyShowTestContainer();
116
117 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[2].firstChild, paragraphs[2].firstChild.length, paragraphs[2].firstChild, paragraphs[2].firstChild.length - 1), document, "selectionchange");
118
119 debug("<br>Press Shift + Option + up arrow to select to the beginning of the paragraph:");
120 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("upArrow", ["shiftKey", "altKey"]) , document, "selectionchange");
121 shouldBeEqualToString("window.getSelection().toString()", "The rebels.");
122
123 toggleOnlyShowTestContainer();
124}
125
126async function testExtendSelectionToEndOfDocument()
127{
128 toggleOnlyShowTestContainer();
129
130 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[0].firstChild, 0, paragraphs[0].firstChild, 1), document, "selectionchange");
131
132 debug("<br>Press Shift + Control + down arrow to select to the end of the document:");
133 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("downArrow", ["shiftKey", "ctrlKey"]) , document, "selectionchange");
134 shouldBeEqualToString("window.getSelection().toString()", "Here's to the crazy ones.\n\nThe misfits.\n\nThe rebels.");
135
136 toggleOnlyShowTestContainer();
137}
138
139async function testExtendSelectionToBeginningOfDocument()
140{
141 toggleOnlyShowTestContainer();
142
143 await UIHelper.callFunctionAndWaitForEvent(() => selection.setBaseAndExtent(paragraphs[1].firstChild, paragraphs[1].firstChild.length, paragraphs[1].firstChild, paragraphs[1].firstChild.length - 1), document, "selectionchange");
144
145 debug("<br>Press Shift + Control + up arrow to select to the beginning of the document:");
146 await UIHelper.callFunctionAndWaitForEvent(() => window.testRunner && UIHelper.keyDown("upArrow", ["shiftKey", "ctrlKey"]) , document, "selectionchange");
147 shouldBeEqualToString("window.getSelection().toString()", "Here's to the crazy ones.\n\nThe misfits.");
148
149 toggleOnlyShowTestContainer();
150}
151
152async function runTests()
153{
154 await testExtendSelectionToNextCharacter();
155 await testExtendSelectionToPreviousCharacter();
156 await testExtendSelectionToEndOfWord();
157 await testExtendSelectionToBeginningOfWord();
158 await textExtendSelectionToEndOfLine();
159 await testExtendSelectionToBeginningOfLine();
160 await testExtendSelectionUp();
161 await testExtendSelectionDown();
162 await testExtendSelectionToEndOfParagraph();
163 await testExtendSelectionToBeginningOfParagraph();
164 await testExtendSelectionToEndOfDocument();
165 await testExtendSelectionToBeginningOfDocument();
166
167 document.body.removeChild(document.getElementById("test-container"));
168 finishJSTest();
169}
170
171window.jsTestIsAsync = true;
172description("Test selecting non-editable text using the keyboard.");
173runTests();
174</script>
175</body>
176</html>