OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <script src="../resources/js-test.js"></script> |
3 <head> | 3 |
4 <script src="../resources/js-test.js"></script> | 4 <div id="main" role="main"> |
5 </head> | |
6 <body> | |
7 | 5 |
8 <div id="contenteditable-textbox" role="textbox" contenteditable="true"> | 6 <div id="contenteditable-textbox" role="textbox" contenteditable="true"> |
9 <div id="contenteditable-line1">Line 1</div> | 7 <div id="contenteditable-line1">Line 1</div> |
10 <textarea id="contenteditable-line2" rows="1" cols="40">Line 2</textarea> | 8 <textarea id="contenteditable-line2" rows="1" cols="40">Line 2</textarea
> |
11 </div> | 9 </div> |
12 | 10 |
13 <div id="contenteditable-div" contenteditable> | 11 <div id="contenteditable-div" contenteditable> |
14 <p id="paragraph1">Line 1<br>Line 2</p> | 12 <p id="paragraph1">Line 1<br>Line 2</p> |
15 <p id="paragraph2">Line 3</p> | 13 <p id="paragraph2">Line 3</p> |
16 </div> | 14 </div> |
17 | 15 |
18 <script> | 16 </div> |
19 description("This tests that caret position is reported correctly for co
ntenteditable elements."); | |
20 | 17 |
21 if (window.accessibilityController) { | 18 <script> |
22 var selection = window.getSelection(); | 19 description("This tests that caret position is reported correctly for conten
teditable elements."); |
23 var selectionRange = document.createRange(); | |
24 | 20 |
25 var textbox = document.getElementById("contenteditable-textbox"); | 21 if (window.accessibilityController) { |
26 textbox.focus(); | 22 var selection = window.getSelection(); |
27 var textboxAccessible = | 23 var selectionRange = document.createRange(); |
28 accessibilityController.accessibleElementById( | 24 var mainAccessible = accessibilityController.accessibleElementById("main
"); |
29 'contenteditable-textbox'); | 25 var rootAccessible = accessibilityController.rootElement; |
30 | 26 |
31 shouldBeZero("textboxAccessible.selectionStart"); | 27 shouldBeZero("mainAccessible.selectionStart"); |
32 shouldBeZero("textboxAccessible.selectionEnd"); | 28 shouldBeZero("mainAccessible.selectionEnd"); |
| 29 shouldBeZero("mainAccessible.selectionStartLineNumber"); |
| 30 shouldBeZero("mainAccessible.selectionEndLineNumber"); |
33 | 31 |
34 var line1 = document.getElementById("contenteditable-line1"); | 32 shouldBeNull("rootAccessible.selectionAnchorObject"); |
35 selectionRange.setStart(line1.firstChild, 1); | 33 shouldBeEqualToNumber("rootAccessible.selectionAnchorOffset", -1); |
36 selectionRange.setEnd(line1.firstChild, 1); | 34 shouldBeNull("rootAccessible.selectionFocusObject"); |
37 selection.removeAllRanges(); | 35 shouldBeEqualToNumber("rootAccessible.selectionFocusOffset", -1); |
38 selection.addRange(selectionRange); | |
39 shouldBeEqualToNumber("textboxAccessible.selectionStart", 1); | |
40 shouldBeEqualToNumber("textboxAccessible.selectionEnd", 1); | |
41 | 36 |
42 var line2 = document.getElementById("contenteditable-line2"); | 37 var textbox = document.getElementById("contenteditable-textbox"); |
43 line2.focus(); | 38 textbox.focus(); |
44 // The selection should have been removed from the line1 div. | 39 var textboxAccessible = |
45 shouldBeZero("textboxAccessible.selectionStart"); | 40 accessibilityController.accessibleElementById( |
46 shouldBeZero("textboxAccessible.selectionEnd"); | 41 "contenteditable-textbox"); |
47 | 42 |
48 var line2Accessible = accessibilityController.focusedElement; | 43 shouldBeZero("textboxAccessible.selectionStart"); |
49 shouldBeZero("line2Accessible.selectionStart"); | 44 shouldBeZero("textboxAccessible.selectionEnd"); |
50 shouldBeZero("line2Accessible.selectionEnd"); | |
51 line2.setSelectionRange(3, 3); | |
52 shouldBeEqualToNumber("line2Accessible.selectionStart", 3); | |
53 shouldBeEqualToNumber("line2Accessible.selectionEnd", 3); | |
54 | 45 |
55 var contenteditable = document.getElementById('contenteditable-div')
; | 46 var line1 = document.getElementById("contenteditable-line1"); |
56 contenteditable.focus(); | 47 var line1Accessible = accessibilityController.accessibleElementById("lin
e1"); |
57 var line1 = document.getElementById('paragraph1').firstChild; | 48 var line1TextAccessible = line1Accessible.getChildAtIndex(0); |
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 | 49 |
65 for (var lineNumber = 0; lineNumber < 3; ++lineNumber) { | 50 selectionRange.setStart(line1.firstChild, 1); |
66 var lineOffset = lineNumber * 7; | 51 selectionRange.setEnd(line1.firstChild, 1); |
67 // Paragraphs should have an extra blank line between them. | 52 selection.removeAllRanges(); |
68 if (lineNumber == 2) | 53 selection.addRange(selectionRange); |
69 lineOffset += 1; | |
70 | 54 |
71 for (var characterOffset = 0; characterOffset < 7; ++characterOf
fset) { | 55 shouldBeEqualToNumber("textboxAccessible.selectionStart", 1); |
72 caretPosition = lineOffset + characterOffset; | 56 shouldBeEqualToNumber("textboxAccessible.selectionEnd", 1); |
73 | 57 |
74 selectionRange.setStart(contenteditableLines[lineNumber], ch
aracterOffset); | 58 shouldBeEqualToNumber("mainAccessible.selectionStart", 1); |
75 selectionRange.setEnd(contenteditableLines[lineNumber], char
acterOffset); | 59 shouldBeEqualToNumber("mainAccessible.selectionEnd", 1); |
76 selection.removeAllRanges(); | 60 shouldBeZero("mainAccessible.selectionStartLineNumber"); |
77 selection.addRange(selectionRange); | 61 shouldBeZero("mainAccessible.selectionEndLineNumber"); |
78 | 62 |
79 shouldBeEqualToNumber("contenteditableAccessible.selectionSt
art", | 63 shouldBeEqual("rootAccessible.selectionAnchorObject", "line1TextAccessib
le"); |
80 caretPosition); | 64 shouldBeEqualToNumber("rootAccessible.selectionAnchorOffset", 1); |
81 shouldBeEqualToNumber("contenteditableAccessible.selectionEn
d", | 65 shouldBeEqual("rootAccessible.selectionFocusObject", "line1TextAccessibl
e"); |
82 caretPosition); | 66 shouldBeEqualToNumber("rootAccessible.selectionFocusOffset", 1); |
83 shouldBeEqualToNumber("contenteditableAccessible.selectionSt
artLineNumber", | 67 |
84 lineNumber); | 68 |
85 shouldBeEqualToNumber("contenteditableAccessible.selectionEn
dLineNumber", | 69 var line2 = document.getElementById("contenteditable-line2"); |
86 lineNumber); | 70 line2.focus(); |
87 } | 71 |
| 72 // The selection should have been removed from the line1 div. |
| 73 shouldBeZero("textboxAccessible.selectionStart"); |
| 74 shouldBeZero("textboxAccessible.selectionEnd"); |
| 75 shouldBeZero("mainAccessible.selectionStart"); |
| 76 shouldBeZero("mainAccessible.selectionEnd"); |
| 77 shouldBeNull("rootAccessible.selectionAnchorObject"); |
| 78 shouldBeEqualToNumber("rootAccessible.selectionAnchorOffset", -1); |
| 79 shouldBeNull("rootAccessible.selectionFocusObject"); |
| 80 shouldBeEqualToNumber("rootAccessible.selectionFocusOffset", -1); |
| 81 |
| 82 var line2Accessible = accessibilityController.focusedElement; |
| 83 shouldBeZero("line2Accessible.selectionStart"); |
| 84 shouldBeZero("line2Accessible.selectionEnd"); |
| 85 line2.setSelectionRange(3, 3); |
| 86 |
| 87 shouldBeEqualToNumber("line2Accessible.selectionStart", 3); |
| 88 shouldBeEqualToNumber("line2Accessible.selectionEnd", 3); |
| 89 shouldBeZero("line2Accessible.selectionStartLineNumber"); |
| 90 shouldBeZero("line2Accessible.selectionEndLineNumber"); |
| 91 |
| 92 shouldBeEqualToNumber("mainAccessible.selectionStart", 3); |
| 93 shouldBeEqualToNumber("mainAccessible.selectionEnd", 3); |
| 94 shouldBeZero("mainAccessible.selectionStartLineNumber"); |
| 95 shouldBeZero("mainAccessible.selectionEndLineNumber"); |
| 96 |
| 97 shouldBeEqual("rootAccessible.selectionAnchorObject", "line2Accessible")
; |
| 98 shouldBeEqualToNumber("rootAccessible.selectionAnchorOffset", 1); |
| 99 shouldBeEqual("rootAccessible.selectionFocusObject", "line2Accessible"); |
| 100 shouldBeEqualToNumber("rootAccessible.selectionFocusOffset", 1); |
| 101 |
| 102 |
| 103 var contenteditable = document.getElementById("contenteditable-div"); |
| 104 contenteditable.focus(); |
| 105 // The offset from the beginning of the main div to the first character
of |
| 106 // contenteditable-div. The whole of the textarea is treated as a single
embedded object. |
| 107 var mainOffset = 9; |
| 108 var line1 = document.getElementById("paragraph1").firstChild; |
| 109 var line2 = document.getElementById("paragraph1").lastChild; |
| 110 var line3 = document.getElementById("paragraph2").firstChild; |
| 111 var contenteditableLines = [ line1, line2, line3 ]; |
| 112 var contenteditableAccessible = |
| 113 accessibilityController.accessibleElementById( |
| 114 "contenteditable-div"); |
| 115 |
| 116 for (var lineNumber = 0; lineNumber < 3; ++lineNumber) { |
| 117 var lineOffset = lineNumber * 7; |
| 118 // Paragraphs should have an extra blank line between them. |
| 119 if (lineNumber == 2) |
| 120 lineOffset += 1; |
| 121 |
| 122 for (var characterOffset = 0; characterOffset < 7; ++characterOffset
) { |
| 123 caretPosition = lineOffset + characterOffset; |
| 124 |
| 125 selectionRange.setStart(contenteditableLines[lineNumber], charac
terOffset); |
| 126 selectionRange.setEnd(contenteditableLines[lineNumber], characte
rOffset); |
| 127 selection.removeAllRanges(); |
| 128 selection.addRange(selectionRange); |
| 129 |
| 130 shouldBeEqualToNumber("contenteditableAccessible.selectionStart"
, |
| 131 caretPosition); |
| 132 shouldBeEqualToNumber("contenteditableAccessible.selectionEnd", |
| 133 caretPosition); |
| 134 shouldBeEqualToNumber("contenteditableAccessible.selectionStartL
ineNumber", |
| 135 lineNumber); |
| 136 shouldBeEqualToNumber("contenteditableAccessible.selectionEndLin
eNumber", |
| 137 lineNumber); |
| 138 |
| 139 shouldBeEqualToNumber("mainAccessible.selectionStart", |
| 140 mainOffset + caretPosition); |
| 141 shouldBeEqualToNumber("mainAccessible.selectionEnd", |
| 142 mainOffset + caretPosition); |
| 143 shouldBeEqualToNumber("mainAccessible.selectionStartLineNumber", |
| 144 lineNumber); |
| 145 shouldBeEqualToNumber("mainAccessible.selectionEndLineNumber", |
| 146 lineNumber); |
| 147 |
| 148 shouldBeEqualToString("rootAccessible.selectionAnchorObject.stri
ngValue", ""); |
| 149 shouldBeEqualToNumber("rootAccessible.selectionAnchorOffset", 1)
; |
| 150 shouldBeEqualToString("rootAccessible.selectionFocusObject.strin
gValue", ""); |
| 151 shouldBeEqualToNumber("rootAccessible.selectionFocusOffset", 1); |
88 } | 152 } |
| 153 } |
89 | 154 |
90 } | 155 } |
91 </script> | 156 </script> |
92 | |
93 </body> | |
94 </html> | |
OLD | NEW |