a376878f57e6fa97b47789f3e4499cdecbf6b5b3
[WebKit-https.git] / LayoutTests / accessibility / mac / text-marker-word-nav.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <meta charset="utf-8"> 
5 <script src="../../resources/js-test-pre.js"></script>
6 </head>
7 <style>
8 .userselect { user-select: none; -webkit-user-select: none; }
9 </style>
10 <body id="body">
11
12 <div id="text" tabindex="0">word1 test</div>
13 <span id="span">Thisis</span>longword I<span>'ll try.</span>
14 Test Content<span id="target" contenteditable="true">editable is working.</span>
15
16 <div id="text2">
17 c <img src="#" aria-label="blah" style="background-color: #aaaaaa; width: 100px; height: 100px;">d
18 </div>
19
20 <div class="userselect" id="text3">can't select</div>
21
22 <div id="text4">
23 巧克力是食物吗?
24 </div>
25 <div id="text4a">
26 كيف حالك؟
27 </div>
28
29 <pre id="text5">
30 both   spaces
31 line breaks
32 </pre>
33
34 <div id="text6">
35 some<br>text
36 </div>
37
38 <div id="text7">
39 test audio <audio controls><source src="test.mp3" type="audio/mpeg"></audio>file
40 </div>
41
42 <p id="description"></p>
43 <div id="console"></div>
44
45 <script>
46
47     description("This tests that word navigation is working correctly.");
48     
49     if (window.accessibilityController) {
50         
51         var text = accessibilityController.accessibleElementById("text");
52         // Get the actual text node.
53         text = text.childAtIndex(0);
54         
55         // Check that we can get the word range. Land at "w" in "word1 test".
56         var textMarkerRange = text.textMarkerRangeForElement(text);
57         var startMarker = text.startTextMarkerForTextMarkerRange(textMarkerRange);
58         var currentMarker = advanceAndVerify(startMarker, 1, text);
59         
60         // Check that we are at the end of paragraph, so right word should be empty
61         currentMarker = advanceAndVerify(currentMarker, 9, text);
62         
63         // Check the case with span
64         // At "T" in "Thisis", should return the word as "Thisislongword".
65         currentMarker = advanceAndVerify(currentMarker, 2, text);
66         // At " " before "I", the word should be "I'll".
67         currentMarker = advanceAndVerify(currentMarker, 15, text);
68         // At " " before "try", the word should excludes "."
69         currentMarker = advanceAndVerify(currentMarker, 6, text);
70         
71         // Check the case with contenteditable
72         // At "e" in "editable", the word should NOT include "Content" before it.
73         currentMarker = advanceAndVerify(currentMarker, 19, text);
74         
75         // Check the case with replaced node, the replaced node should be considered a word.
76         var text2 = accessibilityController.accessibleElementById("text2");
77         textMarkerRange = text2.textMarkerRangeForElement(text2);
78         currentMarker = text2.startTextMarkerForTextMarkerRange(textMarkerRange);
79         currentMarker = advanceAndVerify(currentMarker, 2, text2);
80         currentMarker = advanceAndVerify(currentMarker, 1, text2);
81         
82         // Check user-select:none is also working.
83         var text3 = accessibilityController.accessibleElementById("text3");
84         textMarkerRange = text3.textMarkerRangeForElement(text3);
85         currentMarker = text3.startTextMarkerForTextMarkerRange(textMarkerRange);
86         currentMarker = advanceAndVerify(currentMarker, 1, text3);
87         
88         // Check multi-language, Chinese here.
89         var text4 = accessibilityController.accessibleElementById("text4");
90         textMarkerRange = text4.textMarkerRangeForElement(text4);
91         currentMarker = text4.startTextMarkerForTextMarkerRange(textMarkerRange);
92         currentMarker = advanceAndVerify(currentMarker, 2, text4);
93         currentMarker = advanceAndVerify(currentMarker, 1, text4);
94         currentMarker = advanceAndVerify(currentMarker, 1, text4);
95         // And Arabic
96         var text4a = accessibilityController.accessibleElementById("text4a");
97         textMarkerRange = text4a.textMarkerRangeForElement(text4a);
98         currentMarker = text4a.startTextMarkerForTextMarkerRange(textMarkerRange);
99         currentMarker = advanceAndVerify(currentMarker, 3, text4a);
100         currentMarker = advanceAndVerify(currentMarker, 1, text4a);
101         
102         // Check text in pre tag with line breaks.
103         var text5 = accessibilityController.accessibleElementById("text5");
104         textMarkerRange = text5.textMarkerRangeForElement(text5);
105         currentMarker = text5.startTextMarkerForTextMarkerRange(textMarkerRange);
106         // At "h" in "both", right word should be "   ".
107         currentMarker = advanceAndVerify(currentMarker, 4, text5);
108         // At the end of first line, right word should be new line.
109         currentMarker = advanceAndVerify(currentMarker, 9, text5);
110         
111         // Check text with br tag in it.
112         var text6 = accessibilityController.accessibleElementById("text6");
113         textMarkerRange = text6.textMarkerRangeForElement(text6);
114         currentMarker = text6.startTextMarkerForTextMarkerRange(textMarkerRange);
115         currentMarker = advanceAndVerify(currentMarker, 4, text6);
116         currentMarker = advanceAndVerify(currentMarker, 1, text6);
117         
118         // Check <audio> element.
119         var text7 = accessibilityController.accessibleElementById("text7");
120         textMarkerRange = text7.textMarkerRangeForElement(text7);
121         currentMarker = text7.startTextMarkerForTextMarkerRange(textMarkerRange);
122         currentMarker = advanceAndVerify(currentMarker, 11, text7);
123         currentMarker = advanceAndVerify(currentMarker, 1, text7);
124         currentMarker = advanceAndVerify(currentMarker, 1, text7);
125         
126         // Check the word marker runs from start to end, and backwards.
127         // Make sure it won't hang.
128         verifyDocument(text);
129         
130         function advanceAndVerify(currentMarker, offset, obj) {
131             var previousMarker;
132             for (var i = 0; i < offset; i++) {
133                 previousMarker = currentMarker;
134                 currentMarker = obj.nextTextMarker(previousMarker);
135             }
136             verifyWordRangeForTextMarker(previousMarker, currentMarker, obj);
137             return currentMarker;
138         }
139         
140         function replaceAttachmentInString(str) {
141             var newline = '\n';
142             str =  str.replace(String.fromCharCode(65532), "[ATTACHMENT]");
143             str = str.replace(newline, "'line break'");
144             return str;
145         }
146         
147         function verifyWordRangeForTextMarker(preMarker, textMarker, obj) {
148             var markerRange = obj.textMarkerRangeForMarkers(preMarker, textMarker);
149             var currentCharacter = replaceAttachmentInString(obj.stringForTextMarkerRange(markerRange));
150             debug("Current character is: " + currentCharacter);
151             
152             var previousWordRange = obj.leftWordTextMarkerRangeForTextMarker(textMarker);
153             var nextWordRange = obj.rightWordTextMarkerRangeForTextMarker(textMarker);
154             var preWord = replaceAttachmentInString(obj.stringForTextMarkerRange(previousWordRange));
155             var nextWord = replaceAttachmentInString(obj.stringForTextMarkerRange(nextWordRange));
156             debug("Left word is: " + preWord);
157             debug("Right word is: " + nextWord);
158             
159             var preWordStart = obj.previousWordStartTextMarkerForTextMarker(textMarker);
160             var nextWordEnd = obj.nextWordEndTextMarkerForTextMarker(textMarker);
161             var preAndNextWordRange = obj.textMarkerRangeForMarkers(preWordStart, nextWordEnd);
162             var preAndNextWord = replaceAttachmentInString(obj.stringForTextMarkerRange(preAndNextWordRange));
163             debug("Pre word start to next word end: " + preAndNextWord + "\n");
164         }
165         
166         function verifyDocument(obj) {
167             var start = obj.startTextMarker;
168             
169             // Going forward.
170             debug("Test going forward.");
171             var current = start;
172             var endWord = "file";
173             var currWord = "";
174             while(currWord != endWord) {
175                 var nextWordRange = obj.rightWordTextMarkerRangeForTextMarker(current);
176                 currWord = obj.stringForTextMarkerRange(nextWordRange);
177                 current = obj.nextWordEndTextMarkerForTextMarker(current);
178             }
179             debug("End word: " + replaceAttachmentInString(currWord));
180             
181             // Going backwards.
182             debug("\nTest going backwards.");
183             var startWord = "word1";
184             currWord = ""; 
185             while(currWord != startWord) {
186                 var previousWordRange = obj.leftWordTextMarkerRangeForTextMarker(current);
187                 currWord = obj.stringForTextMarkerRange(previousWordRange);
188                 current = obj.previousWordStartTextMarkerForTextMarker(current);
189             }
190             debug("Start word: " + replaceAttachmentInString(currWord));
191         }
192     }
193
194 </script>
195
196 <script src="../../resources/js-test-post.js"></script>
197 </body>
198 </html>