OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <script src="../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | |
7 | |
8 <div id="contenteditable-textbox" role="textbox" contenteditable="true"> | |
9 <div id="contenteditable-line1">Line 1</div> | |
10 <textarea id="contenteditable-line2" rows="1" cols="40">Line 2</textarea> | |
11 </div> | |
12 | |
13 <div id="contenteditable-div" contenteditable> | |
14 <p id="paragraph1">Line 1<br>Line 2</p> | |
15 <p id="paragraph2">Line 3</p> | |
16 </div> | |
17 | |
18 <script> | |
19 description("This tests that caret position is reported correctly for co
ntenteditable elements."); | |
20 | |
21 if (window.accessibilityController) { | |
22 var selection = window.getSelection(); | |
23 var selectionRange = document.createRange(); | |
24 | |
25 var textbox = document.getElementById("contenteditable-textbox"); | |
26 textbox.focus(); | |
27 var textboxAccessible = | |
28 accessibilityController.accessibleElementById( | |
29 'contenteditable-textbox'); | |
30 | |
31 shouldBeZero("textboxAccessible.selectionStart"); | |
32 shouldBeZero("textboxAccessible.selectionEnd"); | |
33 | |
34 var line1 = document.getElementById("contenteditable-line1"); | |
35 selectionRange.setStart(line1.firstChild, 1); | |
36 selectionRange.setEnd(line1.firstChild, 1); | |
37 selection.removeAllRanges(); | |
38 selection.addRange(selectionRange); | |
39 shouldBeEqualToNumber("textboxAccessible.selectionStart", 1); | |
40 shouldBeEqualToNumber("textboxAccessible.selectionEnd", 1); | |
41 | |
42 var line2 = document.getElementById("contenteditable-line2"); | |
43 line2.focus(); | |
44 // The selection should have been removed from the line1 div. | |
45 shouldBeZero("textboxAccessible.selectionStart"); | |
46 shouldBeZero("textboxAccessible.selectionEnd"); | |
47 | |
48 var line2Accessible = accessibilityController.focusedElement; | |
49 shouldBeZero("line2Accessible.selectionStart"); | |
50 shouldBeZero("line2Accessible.selectionEnd"); | |
51 line2.setSelectionRange(3, 3); | |
52 shouldBeEqualToNumber("line2Accessible.selectionStart", 3); | |
53 shouldBeEqualToNumber("line2Accessible.selectionEnd", 3); | |
54 | |
55 var contenteditable = document.getElementById('contenteditable-div')
; | |
56 contenteditable.focus(); | |
57 var line1 = document.getElementById('paragraph1').firstChild; | |
58 var line2 = document.getElementById('paragraph1').lastChild; | |
59 var line3 = document.getElementById('paragraph2').firstChild; | |
60 var contenteditableLines = [ line1, line2, line3 ]; | |
61 var contenteditableAccessible = | |
62 accessibilityController.accessibleElementById( | |
63 'contenteditable-div'); | |
64 | |
65 for (var lineNumber = 0; lineNumber < 3; ++lineNumber) { | |
66 var lineOffset = lineNumber * 7; | |
67 // Paragraphs should have an extra blank line between them. | |
68 if (lineNumber == 2) | |
69 lineOffset += 1; | |
70 | |
71 for (var characterOffset = 0; characterOffset < 7; ++characterOf
fset) { | |
72 caretPosition = lineOffset + characterOffset; | |
73 | |
74 selectionRange.setStart(contenteditableLines[lineNumber], ch
aracterOffset); | |
75 selectionRange.setEnd(contenteditableLines[lineNumber], char
acterOffset); | |
76 selection.removeAllRanges(); | |
77 selection.addRange(selectionRange); | |
78 | |
79 shouldBeEqualToNumber("contenteditableAccessible.selectionSt
art", | |
80 caretPosition); | |
81 shouldBeEqualToNumber("contenteditableAccessible.selectionEn
d", | |
82 caretPosition); | |
83 shouldBeEqualToNumber("contenteditableAccessible.selectionSt
artLineNumber", | |
84 lineNumber); | |
85 shouldBeEqualToNumber("contenteditableAccessible.selectionEn
dLineNumber", | |
86 lineNumber); | |
87 } | |
88 } | |
89 | |
90 } | |
91 </script> | |
92 | |
93 </body> | |
94 </html> | |
OLD | NEW |