OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 | 5 |
6 <div id="container"> | 6 <div id="container"> |
7 | 7 |
8 <div> | 8 <div> |
9 <label id="label1" for="control1">Label 1</label> | 9 <label id="label1" for="control1">Label 1</label> |
10 <input id="control1" type="text"> | 10 <input id="control1" type="text"> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 <div id="console"></div> | 43 <div id="console"></div> |
44 <script> | 44 <script> |
45 description("This tests that titleUIElement works correctly even when things cha
nge dynamically."); | 45 description("This tests that titleUIElement works correctly even when things cha
nge dynamically."); |
46 | 46 |
47 if (window.testRunner && window.accessibilityController) { | 47 if (window.testRunner && window.accessibilityController) { |
48 testRunner.dumpAsText(); | 48 testRunner.dumpAsText(); |
49 | 49 |
50 function hasTitleUIElement(axElement) { | 50 function hasTitleUIElement(axElement) { |
51 var label1 = accessibilityController.accessibleElementById("label1"); | 51 var label1 = accessibilityController.accessibleElementById("label1"); |
52 var titleUIElement = axElement.deprecatedTitleUIElement(); | 52 var titleUIElement = axElement.nameElementAtIndex(0); |
53 if (titleUIElement == null) | 53 if (titleUIElement == null) |
54 return false; | 54 return false; |
55 return titleUIElement.role == label1.role; | 55 return titleUIElement.role == label1.role; |
56 } | 56 } |
57 | 57 |
58 function createLabelWithIdAndForAttribute(id, forAttributeValue) { | 58 function createLabelWithIdAndForAttribute(id, forAttributeValue) { |
59 var labelElement = document.createElement("label"); | 59 var labelElement = document.createElement("label"); |
60 labelElement.id = id; | 60 labelElement.id = id; |
61 labelElement.setAttribute("for", forAttributeValue); | 61 labelElement.setAttribute("for", forAttributeValue); |
62 labelElement.innerText = "Label for " + forAttributeValue; | 62 labelElement.innerText = "Label for " + forAttributeValue; |
63 return labelElement; | 63 return labelElement; |
64 } | 64 } |
65 | 65 |
66 function reparentNodeIntoContainer(node, container) { | 66 function reparentNodeIntoContainer(node, container) { |
67 node.parentElement.removeChild(node); | 67 node.parentElement.removeChild(node); |
68 container.appendChild(node); | 68 container.appendChild(node); |
69 } | 69 } |
70 | 70 |
71 function axElement(id) { | 71 function axElement(id) { |
72 return accessibilityController.accessibleElementById(id); | 72 return accessibilityController.accessibleElementById(id); |
73 } | 73 } |
74 | 74 |
75 shouldBe("axElement('control1').deprecatedTitleUIElement().isEqual(axElement
('label1'))", "true"); | 75 shouldBe("axElement('control1').nameElementAtIndex(0).isEqual(axElement('lab
el1'))", "true"); |
76 | 76 |
77 shouldBe("axElement('control2').deprecatedTitleUIElement().isEqual(axElement
('label2'))", "true"); | 77 shouldBe("axElement('control2').nameElementAtIndex(0).isEqual(axElement('lab
el2'))", "true"); |
78 | 78 |
79 // Test changing the "for" attribute dynamically. | 79 // Test changing the "for" attribute dynamically. |
80 shouldBe("hasTitleUIElement(axElement('control3'))", "false"); | 80 shouldBe("hasTitleUIElement(axElement('control3'))", "false"); |
81 shouldBe("document.getElementById('label3').setAttribute('for', 'control3');
axElement('control3').deprecatedTitleUIElement().isEqual(axElement('label3'))",
"true"); | 81 shouldBe("document.getElementById('label3').setAttribute('for', 'control3');
axElement('control3').nameElementAtIndex(0).isEqual(axElement('label3'))", "tru
e"); |
82 | 82 |
83 // Test unattached label element that's subsequently attached. | 83 // Test unattached label element that's subsequently attached. |
84 var label4Element = document.createElement("label"); | 84 var label4Element = document.createElement("label"); |
85 label4Element.id = "label4"; | 85 label4Element.id = "label4"; |
86 label4Element.setAttribute("for", "control4"); | 86 label4Element.setAttribute("for", "control4"); |
87 label4Element.innerText = "Label 4"; | 87 label4Element.innerText = "Label 4"; |
88 shouldBe("var label4Element = createLabelWithIdAndForAttribute('label4', 'co
ntrol4'); hasTitleUIElement(axElement('control4'))", "false"); | 88 shouldBe("var label4Element = createLabelWithIdAndForAttribute('label4', 'co
ntrol4'); hasTitleUIElement(axElement('control4'))", "false"); |
89 shouldBe("document.getElementById('container').appendChild(label4Element); h
asTitleUIElement(axElement('control4'))", "true"); | 89 shouldBe("document.getElementById('container').appendChild(label4Element); h
asTitleUIElement(axElement('control4'))", "true"); |
90 shouldBe("axElement('control4').deprecatedTitleUIElement().isEqual(axElement
('label4'))", "true"); | 90 shouldBe("axElement('control4').nameElementAtIndex(0).isEqual(axElement('lab
el4'))", "true"); |
91 | 91 |
92 // Test what happens when the label is detached. | 92 // Test what happens when the label is detached. |
93 shouldBe("label4Element.parentElement.removeChild(label4Element); hasTitleUI
Element(axElement('control4'))", "false"); | 93 shouldBe("label4Element.parentElement.removeChild(label4Element); hasTitleUI
Element(axElement('control4'))", "false"); |
94 | 94 |
95 // Test label that gets a control reparented into it. | 95 // Test label that gets a control reparented into it. |
96 shouldBe("hasTitleUIElement(axElement('control5'))", "false"); | 96 shouldBe("hasTitleUIElement(axElement('control5'))", "false"); |
97 | 97 |
98 shouldBe("reparentNodeIntoContainer(document.getElementById('control5'), doc
ument.getElementById('label5')); axElement('control5').deprecatedTitleUIElement(
) != null", "true"); | 98 shouldBe("reparentNodeIntoContainer(document.getElementById('control5'), doc
ument.getElementById('label5')); axElement('control5').nameElementAtIndex(0) !=
null", "true"); |
99 shouldBe("axElement('control5').deprecatedTitleUIElement().isEqual(axElement
('label5'))", "true"); | 99 shouldBe("axElement('control5').nameElementAtIndex(0).isEqual(axElement('lab
el5'))", "true"); |
100 | 100 |
101 // Make sure the first label is returned, even as labels are added and remov
ed. | 101 // Make sure the first label is returned, even as labels are added and remov
ed. |
102 shouldBe("axElement('control6').deprecatedTitleUIElement().isEqual(axElement
('label6b'))", "true"); | 102 shouldBe("axElement('control6').nameElementAtIndex(0).isEqual(axElement('lab
el6b'))", "true"); |
103 shouldBe("newLabel6Element = createLabelWithIdAndForAttribute('label6a', 'co
ntrol6'); document.body.insertBefore(newLabel6Element, document.body.firstChild)
; axElement('control6').deprecatedTitleUIElement().isEqual(axElement('label6a'))
", "true"); | 103 shouldBe("newLabel6Element = createLabelWithIdAndForAttribute('label6a', 'co
ntrol6'); document.body.insertBefore(newLabel6Element, document.body.firstChild)
; axElement('control6').nameElementAtIndex(0).isEqual(axElement('label6a'))", "t
rue"); |
104 shouldBe("document.body.removeChild(newLabel6Element); axElement('control6')
.deprecatedTitleUIElement().isEqual(axElement('label6b'))", "true"); | 104 shouldBe("document.body.removeChild(newLabel6Element); axElement('control6')
.nameElementAtIndex(0).isEqual(axElement('label6b'))", "true"); |
105 | 105 |
106 document.getElementById('container').style.display = 'none'; | 106 document.getElementById('container').style.display = 'none'; |
107 } | 107 } |
108 | 108 |
109 </script> | 109 </script> |
110 | 110 |
111 </body> | 111 </body> |
112 </html> | 112 </html> |
OLD | NEW |