browser_select.js (4841B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from ../../mochitest/states.js */ 7 loadScripts({ name: "states.js", dir: MOCHITESTS_DIR }); 8 9 /* import-globals-from ../../mochitest/role.js */ 10 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR }); 11 12 /** 13 * Verify that the local accessible created in the parent process for the 14 * id=ContentSelectDropdown node has its parent spoofed to the relevant 15 * expanded select. 16 * Note: id=select2 is unused and serves only to ensure we don't return 17 * _just any_ select inside the document :) 18 */ 19 addAccessibleTask( 20 ` 21 <select id="select"> 22 <option id="a">optiona</option> 23 </select> 24 <select id="select2"> 25 <option id="b">optionb</option> 26 </select> 27 `, 28 async function testSelectAncestorChain(browser, accDoc) { 29 const LOCAL_DROPDOWN_ID = "ContentSelectDropdown"; 30 31 const rootAcc = getRootAccessible(document); 32 ok(rootAcc, "Root Accessible exists"); 33 34 const optA = findAccessibleChildByID(accDoc, "a"); 35 const select = findAccessibleChildByID(accDoc, "select"); 36 let remoteAccDropdown = select.firstChild; 37 ok(remoteAccDropdown, "Remote acc dropdown exists"); 38 let isRemote = true; 39 try { 40 remoteAccDropdown.id; 41 } catch (e) { 42 isRemote = false; 43 } 44 45 // Verify the remote dropdown: 46 // - is the role we expect 47 // - is not identical to the local dropdown via ID 48 // - is the parent of the remote accessible for the 49 // option the select contains 50 if (isRemote) { 51 is( 52 remoteAccDropdown.role, 53 ROLE_COMBOBOX_LIST, 54 "Select's first child is the combobox list" 55 ); 56 isnot( 57 remoteAccDropdown.id, 58 LOCAL_DROPDOWN_ID, 59 "Remote dropdown does not match local dropdown's ID." 60 ); 61 is( 62 remoteAccDropdown.firstChild, 63 optA, 64 "Remote dropdown contains remote acc of option A." 65 ); 66 } 67 68 // Attempt to fetch the local dropdown 69 let localAccDropdown = findAccessibleChildByID(rootAcc, LOCAL_DROPDOWN_ID); 70 is( 71 localAccDropdown, 72 null, 73 "Local dropdown cannot be reached while select is collapsed" 74 ); 75 76 // Focus the combo box. 77 await invokeFocus(browser, "select"); 78 79 // Expand the combobox dropdown. 80 let p = waitForEvent(EVENT_STATE_CHANGE, LOCAL_DROPDOWN_ID); 81 EventUtils.synthesizeKey("VK_SPACE"); 82 await p; 83 84 // Attempt to fetch the local dropdown 85 localAccDropdown = findAccessibleChildByID(rootAcc, LOCAL_DROPDOWN_ID); 86 ok(localAccDropdown, "Local dropdown exists when select is expanded."); 87 88 // Verify the dropdown rendered in the parent 89 // process is a child of the select 90 is(localAccDropdown.parent, select, "Dropdown is a child of the select"); 91 92 // Verify walking from the select produces the 93 // appropriate option 94 remoteAccDropdown = select.firstChild; 95 96 // Verify the remote dropdown: 97 // - is the role we expect 98 // - is not identical to the local dropdown via ID 99 // - is the parent of the remote accessible for the 100 // option the select contains 101 if (isRemote) { 102 is( 103 remoteAccDropdown.role, 104 ROLE_COMBOBOX_LIST, 105 "Select's first child is the combobox list" 106 ); 107 isnot( 108 remoteAccDropdown.id, 109 LOCAL_DROPDOWN_ID, 110 "Remote dropdown does not match local dropdown's ID." 111 ); 112 is( 113 remoteAccDropdown.firstChild, 114 optA, 115 "Remote dropdown contains remote acc of option A." 116 ); 117 } 118 119 // Close the dropdown. 120 p = waitForEvents({ 121 expected: [[EVENT_HIDE, LOCAL_DROPDOWN_ID]], 122 }); 123 124 EventUtils.synthesizeKey("VK_ESCAPE"); 125 await p; 126 127 // Verify walking down from the select produces the 128 // appropriate option 129 remoteAccDropdown = select.firstChild; 130 131 // Verify the remote dropdown: 132 // - is the role we expect 133 // - is not identical to the local dropdown via ID 134 // - is the parent of the remote accessible for the 135 // option the select contains 136 if (isRemote) { 137 is( 138 remoteAccDropdown.role, 139 ROLE_COMBOBOX_LIST, 140 "Select's first child is the combobox list" 141 ); 142 isnot( 143 remoteAccDropdown.id, 144 LOCAL_DROPDOWN_ID, 145 "Remote dropdown does not match local dropdown's ID." 146 ); 147 is( 148 remoteAccDropdown.firstChild, 149 optA, 150 "Remote dropdown contains remote acc of option A." 151 ); 152 } 153 154 // Attempt to fetch the local dropdown 155 localAccDropdown = findAccessibleChildByID(rootAcc, LOCAL_DROPDOWN_ID); 156 is( 157 localAccDropdown, 158 null, 159 "Local dropdown cannot be reached while select is collapsed" 160 ); 161 }, 162 { 163 chrome: true, 164 topLevel: true, 165 iframe: true, 166 remoteIframe: true, 167 } 168 );