head.js (1844B)
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 /* exported initAccessibilityService, openNewTab, shutdownAccessibilityService */ 8 9 // Load the shared-head file first. 10 Services.scriptloader.loadSubScript( 11 "chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js", 12 this 13 ); 14 15 const nsIAccessibleRole = Ci.nsIAccessibleRole; // eslint-disable-line no-unused-vars 16 17 /* import-globals-from ../../mochitest/role.js */ 18 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR }); 19 20 async function openNewTab(url) { 21 const forceNewProcess = true; 22 23 return BrowserTestUtils.openNewForegroundTab({ 24 gBrowser, 25 url, 26 forceNewProcess, 27 }); 28 } 29 30 async function initAccessibilityService() { 31 info("Create accessibility service."); 32 let accService = Cc["@mozilla.org/accessibilityService;1"].getService( 33 Ci.nsIAccessibilityService 34 ); 35 36 await new Promise(resolve => { 37 if (Services.appinfo.accessibilityEnabled) { 38 resolve(); 39 return; 40 } 41 42 let observe = (subject, topic, data) => { 43 if (data === "1") { 44 Services.obs.removeObserver(observe, "a11y-init-or-shutdown"); 45 resolve(); 46 } 47 }; 48 Services.obs.addObserver(observe, "a11y-init-or-shutdown"); 49 }); 50 51 return accService; 52 } 53 54 function shutdownAccessibilityService() { 55 forceGC(); 56 57 return new Promise(resolve => { 58 if (!Services.appinfo.accessibilityEnabled) { 59 resolve(); 60 return; 61 } 62 63 let observe = (subject, topic, data) => { 64 if (data === "0") { 65 Services.obs.removeObserver(observe, "a11y-init-or-shutdown"); 66 resolve(); 67 } 68 }; 69 Services.obs.addObserver(observe, "a11y-init-or-shutdown"); 70 }); 71 }