test_focus_radio.xhtml (2787B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 4 type="text/css"?> 5 6 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 7 title="Tests for Accessible TakeFocus on Radio Elements"> 8 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 10 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 11 12 <script type="application/javascript" 13 src="../common.js" /> 14 <script type="application/javascript" 15 src="../role.js" /> 16 <script type="application/javascript" 17 src="../states.js" /> 18 <script type="application/javascript" 19 src="../promisified-events.js" /> 20 21 <script type="application/javascript"> 22 <![CDATA[ 23 async function doTests() { 24 let radio1 = getAccessible("radio1"); 25 let focused = waitForEvent(EVENT_FOCUS, radio1); 26 radio1.takeFocus(); 27 await focused; 28 // radio1 wasn't selected. Ensure that takeFocus didn't change that. 29 testStates(radio1, STATE_FOCUSED, 0, STATE_CHECKED); 30 31 // Test focusing another radio in the group while the group is still 32 // focused. 33 let radio2 = getAccessible("radio2"); 34 focused = waitForEvent(EVENT_FOCUS, radio2); 35 radio2.takeFocus(); 36 await focused; 37 testStates(radio2, STATE_FOCUSED | STATE_CHECKED); 38 39 let groupEl = document.getElementById("radiogroup"); 40 // Selecting an item also focuses it. 41 focused = waitForEvent(EVENT_FOCUS, radio1); 42 groupEl.value = "1"; 43 await focused; 44 testStates(radio1, STATE_FOCUSED | STATE_CHECKED); 45 46 // If an item is already selected but not focused, selecting it again 47 // focuses it. 48 focused = waitForEvent(EVENT_FOCUS, radio2); 49 radio2.takeFocus(); 50 await focused; 51 testStates(radio2, STATE_FOCUSED, 0, STATE_CHECKED); 52 // radio1 is selected but not focused. 53 // Select radio1 again, which should focus it. 54 focused = waitForEvent(EVENT_FOCUS, radio1); 55 groupEl.value = "1"; 56 await focused; 57 testStates(radio1, STATE_FOCUSED | STATE_CHECKED); 58 59 SimpleTest.finish(); 60 } 61 62 SimpleTest.waitForExplicitFinish(); 63 addA11yLoadEvent(doTests); 64 ]]> 65 </script> 66 67 <hbox flex="1" style="overflow: auto;"> 68 <body xmlns="http://www.w3.org/1999/xhtml"> 69 <p id="display"></p> 70 <div id="content" style="display: none"></div> 71 <pre id="test"> 72 </pre> 73 </body> 74 75 <vbox flex="1"> 76 <radiogroup id="radiogroup" value="2"> 77 <radio id="radio1" value="1"/> 78 <radio id="radio2" value="2"/> 79 </radiogroup> 80 81 <vbox id="eventdump"/> 82 </vbox> 83 </hbox> 84 </window>