| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var ActiveDescendantAttribute = [ 'activedescendant' ]; | |
| 6 var LinkAttributes = [ 'url' ]; | |
| 7 var DocumentAttributes = [ 'docUrl', | |
| 8 'docTitle', | |
| 9 'docLoaded', | |
| 10 'docLoadingProgress' ]; | |
| 11 var ScrollableAttributes = [ 'scrollX', | |
| 12 'scrollXMin', | |
| 13 'scrollXMax', | |
| 14 'scrollY', | |
| 15 'scrollYMin', | |
| 16 'scrollYMax' ]; | |
| 17 var EditableTextAttributes = [ 'textSelStart', | |
| 18 'textSelEnd' ]; | |
| 19 var RangeAttributes = [ 'valueForRange', | |
| 20 'minValueForRange', | |
| 21 'maxValueForRange' ]; | |
| 22 var TableAttributes = [ 'tableRowCount', | |
| 23 'tableColumnCount' ]; | |
| 24 var TableCellAttributes = [ 'tableCellColumnIndex', | |
| 25 'tableCellColumnSpan', | |
| 26 'tableCellRowIndex', | |
| 27 'tableCellRowSpan' ]; | |
| 28 | |
| 29 var allTests = [ | |
| 30 function testDocumentAndScrollAttributes() { | |
| 31 for (var i = 0; i < DocumentAttributes.length; i++) { | |
| 32 var attribute = DocumentAttributes[i]; | |
| 33 assertTrue(attribute in rootNode, | |
| 34 'rootNode should have a ' + attribute + ' attribute'); | |
| 35 } | |
| 36 for (var i = 0; i < ScrollableAttributes.length; i++) { | |
| 37 var attribute = ScrollableAttributes[i]; | |
| 38 assertTrue(attribute in rootNode, | |
| 39 'rootNode should have a ' + attribute + ' attribute'); | |
| 40 } | |
| 41 | |
| 42 assertEq(url, rootNode.docUrl); | |
| 43 assertEq('Automation Tests - Attributes', rootNode.docTitle); | |
| 44 assertEq(true, rootNode.docLoaded); | |
| 45 assertEq(1, rootNode.docLoadingProgress); | |
| 46 assertEq(0, rootNode.scrollX); | |
| 47 assertEq(0, rootNode.scrollXMin); | |
| 48 assertEq(0, rootNode.scrollXMax); | |
| 49 assertEq(0, rootNode.scrollY); | |
| 50 assertEq(0, rootNode.scrollYMin); | |
| 51 assertEq(0, rootNode.scrollYMax); | |
| 52 chrome.test.succeed(); | |
| 53 }, | |
| 54 | |
| 55 function testActiveDescendant() { | |
| 56 var combobox = rootNode.find({ role: 'comboBox' }); | |
| 57 assertTrue('activedescendant' in combobox, | |
| 58 'combobox should have an activedescendant attribute'); | |
| 59 var listbox = rootNode.find({ role: 'listBox' }); | |
| 60 var opt6 = listbox.children[5]; | |
| 61 assertEq(opt6, combobox.activedescendant); | |
| 62 chrome.test.succeed(); | |
| 63 }, | |
| 64 | |
| 65 function testLinkAttributes() { | |
| 66 var links = rootNode.findAll({ role: 'link' }); | |
| 67 assertEq(2, links.length); | |
| 68 | |
| 69 var realLink = links[0]; | |
| 70 assertEq('Real link', realLink.name); | |
| 71 assertTrue('url' in realLink, 'realLink should have a url attribute'); | |
| 72 assertEq('about://blank', realLink.url); | |
| 73 | |
| 74 var ariaLink = links[1]; | |
| 75 assertEq('ARIA link', ariaLink.name); | |
| 76 assertTrue('url' in ariaLink, 'ariaLink should have an empty url'); | |
| 77 assertEq(undefined, ariaLink.url); | |
| 78 chrome.test.succeed(); | |
| 79 }, | |
| 80 | |
| 81 function testEditableTextAttributes() { | |
| 82 var textFields = rootNode.findAll({ role: 'textField' }); | |
| 83 assertEq(3, textFields.length); | |
| 84 var EditableTextAttributes = [ 'textSelStart', 'textSelEnd' ]; | |
| 85 for (var i = 0; i < textFields.length; i++) { | |
| 86 var textField = textFields[i]; | |
| 87 var description = textField.description; | |
| 88 for (var j = 0; j < EditableTextAttributes.length; j++) { | |
| 89 var attribute = EditableTextAttributes[j]; | |
| 90 assertTrue(attribute in textField, | |
| 91 'textField (' + description + ') should have a ' + | |
| 92 attribute + ' attribute'); | |
| 93 } | |
| 94 } | |
| 95 var input = textFields[0]; | |
| 96 assertEq('text-input', input.description); | |
| 97 assertEq(2, input.textSelStart); | |
| 98 assertEq(8, input.textSelEnd); | |
| 99 | |
| 100 var textArea = textFields[1]; | |
| 101 assertEq('textarea', textArea.description); | |
| 102 for (var i = 0; i < EditableTextAttributes.length; i++) { | |
| 103 var attribute = EditableTextAttributes[i]; | |
| 104 assertTrue(attribute in textArea, | |
| 105 'textArea should have a ' + attribute + ' attribute'); | |
| 106 } | |
| 107 assertEq(0, textArea.textSelStart); | |
| 108 assertEq(0, textArea.textSelEnd); | |
| 109 | |
| 110 var ariaTextbox = textFields[2]; | |
| 111 assertEq('textbox-role', ariaTextbox.description); | |
| 112 assertEq(0, ariaTextbox.textSelStart); | |
| 113 assertEq(0, ariaTextbox.textSelEnd); | |
| 114 | |
| 115 chrome.test.succeed(); | |
| 116 }, | |
| 117 | |
| 118 function testRangeAttributes() { | |
| 119 var sliders = rootNode.findAll({ role: 'slider' }); | |
| 120 assertEq(2, sliders.length); | |
| 121 var spinButtons = rootNode.findAll({ role: 'spinButton' }); | |
| 122 assertEq(1, spinButtons.length); | |
| 123 var progressIndicators = rootNode.findAll({ role: 'progressIndicator' }); | |
| 124 assertEq(1, progressIndicators.length); | |
| 125 assertEq('progressbar-role', progressIndicators[0].description); | |
| 126 var scrollBars = rootNode.findAll({ role: 'scrollBar' }); | |
| 127 assertEq(1, scrollBars.length); | |
| 128 | |
| 129 var ranges = sliders.concat(spinButtons, progressIndicators, scrollBars); | |
| 130 assertEq(5, ranges.length); | |
| 131 | |
| 132 for (var i = 0; i < ranges.length; i++) { | |
| 133 var range = ranges[i]; | |
| 134 for (var j = 0; j < RangeAttributes.length; j++) { | |
| 135 var attribute = RangeAttributes[j]; | |
| 136 assertTrue(attribute in range, | |
| 137 range.role + ' (' + range.description + ') should have a ' | |
| 138 + attribute + ' attribute'); | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 var inputRange = sliders[0]; | |
| 143 assertEq('range-input', inputRange.description); | |
| 144 assertEq(4, inputRange.valueForRange); | |
| 145 assertEq(0, inputRange.minValueForRange); | |
| 146 assertEq(5, inputRange.maxValueForRange); | |
| 147 | |
| 148 var ariaSlider = sliders[1]; | |
| 149 assertEq('slider-role', ariaSlider.description); | |
| 150 assertEq(7, ariaSlider.valueForRange); | |
| 151 assertEq(1, ariaSlider.minValueForRange); | |
| 152 assertEq(10, ariaSlider.maxValueForRange); | |
| 153 | |
| 154 var spinButton = spinButtons[0]; | |
| 155 assertEq(14, spinButton.valueForRange); | |
| 156 assertEq(1, spinButton.minValueForRange); | |
| 157 assertEq(31, spinButton.maxValueForRange); | |
| 158 | |
| 159 assertEq('0.9', progressIndicators[0].valueForRange.toPrecision(1)); | |
| 160 assertEq(0, progressIndicators[0].minValueForRange); | |
| 161 assertEq(1, progressIndicators[0].maxValueForRange); | |
| 162 | |
| 163 assertEq(0, scrollBars[0].valueForRange); | |
| 164 assertEq(0, scrollBars[0].minValueForRange); | |
| 165 assertEq(1, scrollBars[0].maxValueForRange); | |
| 166 | |
| 167 chrome.test.succeed(); | |
| 168 }, | |
| 169 | |
| 170 function testTableAttributes() { | |
| 171 var table = rootNode.find({ role: 'table' });; | |
| 172 assertEq(3, table.tableRowCount); | |
| 173 assertEq(3, table.tableColumnCount); | |
| 174 | |
| 175 var row1 = table.firstChild; | |
| 176 var cell1 = row1.firstChild; | |
| 177 assertEq(0, cell1.tableCellColumnIndex); | |
| 178 assertEq(1, cell1.tableCellColumnSpan); | |
| 179 assertEq(0, cell1.tableCellRowIndex); | |
| 180 assertEq(1, cell1.tableCellRowSpan); | |
| 181 | |
| 182 var cell2 = cell1.nextSibling; | |
| 183 assertEq(1, cell2.tableCellColumnIndex); | |
| 184 assertEq(1, cell2.tableCellColumnSpan); | |
| 185 assertEq(0, cell2.tableCellRowIndex); | |
| 186 assertEq(1, cell2.tableCellRowSpan); | |
| 187 | |
| 188 var cell3 = cell2.nextSibling; | |
| 189 assertEq(2, cell3.tableCellColumnIndex); | |
| 190 assertEq(1, cell3.tableCellColumnSpan); | |
| 191 assertEq(0, cell3.tableCellRowIndex); | |
| 192 assertEq(1, cell3.tableCellRowSpan); | |
| 193 | |
| 194 var row2 = row1.nextSibling; | |
| 195 var cell4 = row2.firstChild; | |
| 196 assertEq(0, cell4.tableCellColumnIndex); | |
| 197 assertEq(2, cell4.tableCellColumnSpan); | |
| 198 assertEq(1, cell4.tableCellRowIndex); | |
| 199 assertEq(1, cell4.tableCellRowSpan); | |
| 200 | |
| 201 var cell5 = cell4.nextSibling; | |
| 202 assertEq(2, cell5.tableCellColumnIndex); | |
| 203 assertEq(1, cell5.tableCellColumnSpan); | |
| 204 assertEq(1, cell5.tableCellRowIndex); | |
| 205 assertEq(2, cell5.tableCellRowSpan); | |
| 206 | |
| 207 var row3 = row2.nextSibling; | |
| 208 var cell6 = row3.firstChild; | |
| 209 assertEq(0, cell6.tableCellColumnIndex); | |
| 210 assertEq(1, cell6.tableCellColumnSpan); | |
| 211 assertEq(2, cell6.tableCellRowIndex); | |
| 212 assertEq(1, cell6.tableCellRowSpan); | |
| 213 | |
| 214 var cell7 = cell6.nextSibling; | |
| 215 assertEq(1, cell7.tableCellColumnIndex); | |
| 216 assertEq(1, cell7.tableCellColumnSpan); | |
| 217 assertEq(2, cell7.tableCellRowIndex); | |
| 218 assertEq(1, cell7.tableCellRowSpan); | |
| 219 | |
| 220 chrome.test.succeed(); | |
| 221 }, | |
| 222 | |
| 223 function testNoAttributes() { | |
| 224 var div = rootNode.find({ attributes: { description: 'main' } }); | |
| 225 assertTrue(div !== undefined); | |
| 226 var allAttributes = [].concat(ActiveDescendantAttribute, | |
| 227 LinkAttributes, | |
| 228 DocumentAttributes, | |
| 229 ScrollableAttributes, | |
| 230 EditableTextAttributes, | |
| 231 RangeAttributes, | |
| 232 TableAttributes, | |
| 233 TableCellAttributes); | |
| 234 for (var attributeAttr in allAttributes) { | |
| 235 assertFalse(attributeAttr in div); | |
| 236 } | |
| 237 chrome.test.succeed(); | |
| 238 } | |
| 239 ]; | |
| 240 | |
| 241 setUpAndRunTests(allTests, 'attributes.html'); | |
| OLD | NEW |