browser_events_statechange.js (2221B)
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 /* import-globals-from ../../mochitest/role.js */ 8 /* import-globals-from ../../mochitest/states.js */ 9 loadScripts( 10 { name: "role.js", dir: MOCHITESTS_DIR }, 11 { name: "states.js", dir: MOCHITESTS_DIR } 12 ); 13 14 function checkStateChangeEvent(event, state, isExtraState, isEnabled) { 15 let scEvent = event.QueryInterface(nsIAccessibleStateChangeEvent); 16 is(scEvent.state, state, "Correct state of the statechange event."); 17 is( 18 scEvent.isExtraState, 19 isExtraState, 20 "Correct extra state bit of the statechange event." 21 ); 22 is(scEvent.isEnabled, isEnabled, "Correct state of statechange event state"); 23 } 24 25 // Insert mock source into the iframe to be able to verify the right document 26 // body id. 27 let iframeSrc = `data:text/html, 28 <html> 29 <head> 30 <meta charset='utf-8'/> 31 <title>Inner Iframe</title> 32 </head> 33 <body id='iframe'></body> 34 </html>`; 35 36 /** 37 * Test state change event and its interface: 38 * - state 39 * - isExtraState 40 * - isEnabled 41 */ 42 addAccessibleTask( 43 ` 44 <iframe id="iframe" src="${iframeSrc}"></iframe> 45 <input id="checkbox" type="checkbox" />`, 46 async function (browser) { 47 // Test state change 48 let onStateChange = waitForEvent(EVENT_STATE_CHANGE, "checkbox"); 49 // Set checked for a checkbox. 50 await invokeContentTask(browser, [], () => { 51 content.document.getElementById("checkbox").checked = true; 52 }); 53 let event = await onStateChange; 54 55 checkStateChangeEvent(event, STATE_CHECKED, false, true); 56 testStates(event.accessible, STATE_CHECKED, 0); 57 58 // Test extra state 59 onStateChange = waitForEvent(EVENT_STATE_CHANGE, "iframe"); 60 // Set design mode on. 61 await invokeContentTask(browser, [], () => { 62 content.document.getElementById("iframe").contentDocument.designMode = 63 "on"; 64 }); 65 event = await onStateChange; 66 67 checkStateChangeEvent(event, EXT_STATE_EDITABLE, true, true); 68 testStates(event.accessible, 0, EXT_STATE_EDITABLE); 69 }, 70 { iframe: true, remoteIframe: true } 71 );