OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 | 7 |
8 <div id="contenteditable-textbox" role="textbox" contenteditable="true"> | 8 <div id="main" role="main"> |
9 <div id="contenteditable-line1">Line 1</div> | |
10 <textarea id="contenteditable-line2" rows="1" cols="40">Line 2</textarea> | |
11 </div> | |
12 | 9 |
13 <div id="contenteditable-div" contenteditable> | 10 <div id="contenteditable-textbox" role="textbox" contenteditable="true"> |
14 <p id="paragraph1">Line 1<br>Line 2</p> | 11 <div id="contenteditable-line1">Line 1</div> |
15 <p id="paragraph2">Line 3</p> | 12 <textarea id="contenteditable-line2" rows="1" cols="40">Line 2</textarea
> |
| 13 </div> |
| 14 |
| 15 <div id="contenteditable-div" contenteditable> |
| 16 <p id="paragraph1">Line 1<br>Line 2</p> |
| 17 <p id="paragraph2">Line 3</p> |
| 18 </div> |
| 19 |
16 </div> | 20 </div> |
17 | 21 |
18 <script> | 22 <script> |
19 description("This tests that caret position is reported correctly for co
ntenteditable elements."); | 23 description("This tests that caret position is reported correctly for co
ntenteditable elements."); |
20 | 24 |
21 if (window.accessibilityController) { | 25 if (window.accessibilityController) { |
22 var selection = window.getSelection(); | 26 var selection = window.getSelection(); |
23 var selectionRange = document.createRange(); | 27 var selectionRange = document.createRange(); |
| 28 var mainAccessible = accessibilityController.accessibleElementById("
main"); |
| 29 var rootAccessible = accessibilityController.rootElement; |
| 30 |
| 31 shouldBeZero("mainAccessible.selectionStart"); |
| 32 shouldBeZero("mainAccessible.selectionEnd"); |
24 | 33 |
25 var textbox = document.getElementById("contenteditable-textbox"); | 34 var textbox = document.getElementById("contenteditable-textbox"); |
26 textbox.focus(); | 35 textbox.focus(); |
27 var textboxAccessible = | 36 var textboxAccessible = |
28 accessibilityController.accessibleElementById( | 37 accessibilityController.accessibleElementById( |
29 'contenteditable-textbox'); | 38 "contenteditable-textbox"); |
30 | 39 |
31 shouldBeZero("textboxAccessible.selectionStart"); | 40 shouldBeZero("textboxAccessible.selectionStart"); |
32 shouldBeZero("textboxAccessible.selectionEnd"); | 41 shouldBeZero("textboxAccessible.selectionEnd"); |
33 | 42 |
34 var line1 = document.getElementById("contenteditable-line1"); | 43 var line1 = document.getElementById("contenteditable-line1"); |
35 selectionRange.setStart(line1.firstChild, 1); | 44 selectionRange.setStart(line1.firstChild, 1); |
36 selectionRange.setEnd(line1.firstChild, 1); | 45 selectionRange.setEnd(line1.firstChild, 1); |
37 selection.removeAllRanges(); | 46 selection.removeAllRanges(); |
38 selection.addRange(selectionRange); | 47 selection.addRange(selectionRange); |
39 shouldBeEqualToNumber("textboxAccessible.selectionStart", 1); | 48 shouldBeEqualToNumber("textboxAccessible.selectionStart", 1); |
40 shouldBeEqualToNumber("textboxAccessible.selectionEnd", 1); | 49 shouldBeEqualToNumber("textboxAccessible.selectionEnd", 1); |
| 50 shouldBeEqualToNumber("mainAccessible.selectionStart", 1); |
| 51 shouldBeEqualToNumber("mainAccessible.selectionEnd", 1); |
| 52 shouldBeZero("mainAccessible.selectionStartLineNumber"); |
| 53 shouldBeZero("mainAccessible.selectionEndLineNumber"); |
41 | 54 |
42 var line2 = document.getElementById("contenteditable-line2"); | 55 var line2 = document.getElementById("contenteditable-line2"); |
43 line2.focus(); | 56 line2.focus(); |
44 // The selection should have been removed from the line1 div. | 57 // The selection should have been removed from the line1 div. |
45 shouldBeZero("textboxAccessible.selectionStart"); | 58 shouldBeZero("textboxAccessible.selectionStart"); |
46 shouldBeZero("textboxAccessible.selectionEnd"); | 59 shouldBeZero("textboxAccessible.selectionEnd"); |
| 60 shouldBeZero("mainAccessible.selectionStart"); |
| 61 shouldBeZero("mainAccessible.selectionEnd"); |
47 | 62 |
48 var line2Accessible = accessibilityController.focusedElement; | 63 var line2Accessible = accessibilityController.focusedElement; |
49 shouldBeZero("line2Accessible.selectionStart"); | 64 shouldBeZero("line2Accessible.selectionStart"); |
50 shouldBeZero("line2Accessible.selectionEnd"); | 65 shouldBeZero("line2Accessible.selectionEnd"); |
51 line2.setSelectionRange(3, 3); | 66 line2.setSelectionRange(3, 3); |
52 shouldBeEqualToNumber("line2Accessible.selectionStart", 3); | 67 shouldBeEqualToNumber("line2Accessible.selectionStart", 3); |
53 shouldBeEqualToNumber("line2Accessible.selectionEnd", 3); | 68 shouldBeEqualToNumber("line2Accessible.selectionEnd", 3); |
54 | 69 |
55 var contenteditable = document.getElementById('contenteditable-div')
; | 70 // mainAccessible should return zero here because selection is in a
textarea. |
| 71 shouldBeZero("mainAccessible.selectionStart"); |
| 72 shouldBeZero("mainAccessible.selectionEnd"); |
| 73 shouldBeZero("mainAccessible.selectionStartLineNumber"); |
| 74 shouldBeZero("mainAccessible.selectionEndLineNumber"); |
| 75 |
| 76 var contenteditable = document.getElementById("contenteditable-div")
; |
56 contenteditable.focus(); | 77 contenteditable.focus(); |
57 var line1 = document.getElementById('paragraph1').firstChild; | 78 // The offset from the beginning of the main div to the first charac
ter of |
58 var line2 = document.getElementById('paragraph1').lastChild; | 79 // contenteditable-div. The whole of the textarea is treated as a si
ngle embedded object. |
59 var line3 = document.getElementById('paragraph2').firstChild; | 80 var mainOffset = 9; |
| 81 var line1 = document.getElementById("paragraph1").firstChild; |
| 82 var line2 = document.getElementById("paragraph1").lastChild; |
| 83 var line3 = document.getElementById("paragraph2").firstChild; |
60 var contenteditableLines = [ line1, line2, line3 ]; | 84 var contenteditableLines = [ line1, line2, line3 ]; |
61 var contenteditableAccessible = | 85 var contenteditableAccessible = |
62 accessibilityController.accessibleElementById( | 86 accessibilityController.accessibleElementById( |
63 'contenteditable-div'); | 87 "contenteditable-div"); |
64 | 88 |
65 for (var lineNumber = 0; lineNumber < 3; ++lineNumber) { | 89 for (var lineNumber = 0; lineNumber < 3; ++lineNumber) { |
66 var lineOffset = lineNumber * 7; | 90 var lineOffset = lineNumber * 7; |
67 // Paragraphs should have an extra blank line between them. | 91 // Paragraphs should have an extra blank line between them. |
68 if (lineNumber == 2) | 92 if (lineNumber == 2) |
69 lineOffset += 1; | 93 lineOffset += 1; |
70 | 94 |
71 for (var characterOffset = 0; characterOffset < 7; ++characterOf
fset) { | 95 for (var characterOffset = 0; characterOffset < 7; ++characterOf
fset) { |
72 caretPosition = lineOffset + characterOffset; | 96 caretPosition = lineOffset + characterOffset; |
73 | 97 |
74 selectionRange.setStart(contenteditableLines[lineNumber], ch
aracterOffset); | 98 selectionRange.setStart(contenteditableLines[lineNumber], ch
aracterOffset); |
75 selectionRange.setEnd(contenteditableLines[lineNumber], char
acterOffset); | 99 selectionRange.setEnd(contenteditableLines[lineNumber], char
acterOffset); |
76 selection.removeAllRanges(); | 100 selection.removeAllRanges(); |
77 selection.addRange(selectionRange); | 101 selection.addRange(selectionRange); |
78 | 102 |
79 shouldBeEqualToNumber("contenteditableAccessible.selectionSt
art", | 103 shouldBeEqualToNumber("contenteditableAccessible.selectionSt
art", |
80 caretPosition); | 104 caretPosition); |
81 shouldBeEqualToNumber("contenteditableAccessible.selectionEn
d", | 105 shouldBeEqualToNumber("contenteditableAccessible.selectionEn
d", |
82 caretPosition); | 106 caretPosition); |
83 shouldBeEqualToNumber("contenteditableAccessible.selectionSt
artLineNumber", | 107 shouldBeEqualToNumber("contenteditableAccessible.selectionSt
artLineNumber", |
84 lineNumber); | 108 lineNumber); |
85 shouldBeEqualToNumber("contenteditableAccessible.selectionEn
dLineNumber", | 109 shouldBeEqualToNumber("contenteditableAccessible.selectionEn
dLineNumber", |
86 lineNumber); | 110 lineNumber); |
| 111 |
| 112 shouldBeEqualToNumber("mainAccessible.selectionStart", |
| 113 mainOffset + caretPosition); |
| 114 shouldBeEqualToNumber("mainAccessible.selectionEnd", |
| 115 mainOffset + caretPosition); |
| 116 shouldBeEqualToNumber("mainAccessible.selectionStartLineNumb
er", |
| 117 lineNumber); |
| 118 shouldBeEqualToNumber("mainAccessible.selectionEndLineNumber
", |
| 119 lineNumber); |
87 } | 120 } |
88 } | 121 } |
89 | 122 |
90 } | 123 } |
91 </script> | 124 </script> |
92 | 125 |
93 </body> | 126 </body> |
94 </html> | 127 </html> |
OLD | NEW |