browser_gridPatterns.js (5035B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /* eslint-disable camelcase */ 8 const RowOrColumnMajor_RowMajor = 0; 9 /* eslint-enable camelcase */ 10 11 const SNIPPET = ` 12 <table id="table"> 13 <tr><th id="a">a</th><th id="b">b</th><th id="c">c</th></tr> 14 <tr><th id="dg" rowspan="2">dg</th><td id="ef" colspan="2" headers="b c">ef</td></tr> 15 <tr><th id="h">h</th><td id="i" headers="dg h">i</td></tr> 16 <tr><td id="jkl" colspan="3" headers="a b c">jkl</td></tr> 17 </table> 18 <button id="button">button</button> 19 `; 20 21 async function testGridGetItem(row, col, cellId) { 22 is( 23 await runPython(`pattern.GetItem(${row}, ${col}).CurrentAutomationId`), 24 cellId, 25 `GetItem with row ${row} and col ${col} returned ${cellId}` 26 ); 27 } 28 29 async function testGridItemProps(id, row, col, rowSpan, colSpan, gridId) { 30 await assignPyVarToUiaWithId(id); 31 await definePyVar("pattern", `getUiaPattern(${id}, "GridItem")`); 32 ok(await runPython(`bool(pattern)`), `${id} has GridItem pattern`); 33 is(await runPython(`pattern.CurrentRow`), row, `${id} has correct Row`); 34 is(await runPython(`pattern.CurrentColumn`), col, `${id} has correct Column`); 35 is( 36 await runPython(`pattern.CurrentRowSpan`), 37 rowSpan, 38 `${id} has correct RowSpan` 39 ); 40 is( 41 await runPython(`pattern.CurrentColumnSpan`), 42 colSpan, 43 `${id} has correct ColumnSpan` 44 ); 45 is( 46 await runPython(`pattern.CurrentContainingGrid.CurrentAutomationId`), 47 gridId, 48 `${id} ContainingGridItem is ${gridId}` 49 ); 50 } 51 52 async function testTableItemProps(id, rowHeaders, colHeaders) { 53 await assignPyVarToUiaWithId(id); 54 await definePyVar("pattern", `getUiaPattern(${id}, "TableItem")`); 55 ok(await runPython(`bool(pattern)`), `${id} has TableItem pattern`); 56 await isUiaElementArray( 57 `pattern.GetCurrentRowHeaderItems()`, 58 rowHeaders, 59 `${id} has correct RowHeaderItems` 60 ); 61 await isUiaElementArray( 62 `pattern.GetCurrentColumnHeaderItems()`, 63 colHeaders, 64 `${id} has correct ColumnHeaderItems` 65 ); 66 } 67 68 /** 69 * Test the Grid pattern. 70 */ 71 addUiaTask(SNIPPET, async function testGrid() { 72 await definePyVar("doc", `getDocUia()`); 73 await assignPyVarToUiaWithId("table"); 74 await definePyVar("pattern", `getUiaPattern(table, "Grid")`); 75 ok(await runPython(`bool(pattern)`), "table has Grid pattern"); 76 is( 77 await runPython(`pattern.CurrentRowCount`), 78 4, 79 "table has correct RowCount" 80 ); 81 is( 82 await runPython(`pattern.CurrentColumnCount`), 83 3, 84 "table has correct ColumnCount" 85 ); 86 await testGridGetItem(0, 0, "a"); 87 await testGridGetItem(0, 1, "b"); 88 await testGridGetItem(0, 2, "c"); 89 await testGridGetItem(1, 0, "dg"); 90 await testGridGetItem(1, 1, "ef"); 91 await testGridGetItem(1, 2, "ef"); 92 await testGridGetItem(2, 0, "dg"); 93 await testGridGetItem(2, 1, "h"); 94 await testGridGetItem(2, 2, "i"); 95 96 await testPatternAbsent("button", "Grid"); 97 }); 98 99 /** 100 * Test the GridItem pattern. 101 */ 102 addUiaTask(SNIPPET, async function testGridItem() { 103 await definePyVar("doc", `getDocUia()`); 104 await testGridItemProps("a", 0, 0, 1, 1, "table"); 105 await testGridItemProps("b", 0, 1, 1, 1, "table"); 106 await testGridItemProps("c", 0, 2, 1, 1, "table"); 107 await testGridItemProps("dg", 1, 0, 2, 1, "table"); 108 await testGridItemProps("ef", 1, 1, 1, 2, "table"); 109 await testGridItemProps("jkl", 3, 0, 1, 3, "table"); 110 111 await testPatternAbsent("button", "GridItem"); 112 }); 113 114 /** 115 * Test the Table pattern. 116 */ 117 addUiaTask( 118 SNIPPET, 119 async function testTable() { 120 await definePyVar("doc", `getDocUia()`); 121 await assignPyVarToUiaWithId("table"); 122 await definePyVar("pattern", `getUiaPattern(table, "Table")`); 123 ok(await runPython(`bool(pattern)`), "table has Table pattern"); 124 await isUiaElementArray( 125 `pattern.GetCurrentRowHeaders()`, 126 ["dg", "h"], 127 "table has correct RowHeaders" 128 ); 129 await isUiaElementArray( 130 `pattern.GetCurrentColumnHeaders()`, 131 ["a", "b", "c"], 132 "table has correct ColumnHeaders" 133 ); 134 is( 135 await runPython(`pattern.CurrentRowOrColumnMajor`), 136 RowOrColumnMajor_RowMajor, 137 "table has correct RowOrColumnMajor" 138 ); 139 140 await testPatternAbsent("button", "Table"); 141 }, 142 // The IA2 -> UIA proxy doesn't support the Row/ColumnHeaders properties. 143 { uiaEnabled: true, uiaDisabled: false } 144 ); 145 146 /** 147 * Test the TableItem pattern. 148 */ 149 addUiaTask(SNIPPET, async function testTableItem() { 150 await definePyVar("doc", `getDocUia()`); 151 await testTableItemProps("a", [], []); 152 await testTableItemProps("b", [], []); 153 await testTableItemProps("c", [], []); 154 await testTableItemProps("dg", [], ["a"]); 155 await testTableItemProps("ef", ["dg"], ["b", "c"]); 156 await testTableItemProps("h", ["dg"], ["b"]); 157 await testTableItemProps("i", ["dg", "h"], ["c"]); 158 await testTableItemProps("jkl", [], ["a", "b", "c"]); 159 160 await testPatternAbsent("button", "TableItem"); 161 });