browser_shutdown_doc_acc_reference.js (1837B)
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 add_task(async function () { 8 // Create a11y service. 9 const [a11yInitObserver, a11yInit] = initAccService(); 10 await a11yInitObserver; 11 12 let accService = Cc["@mozilla.org/accessibilityService;1"].getService( 13 Ci.nsIAccessibilityService 14 ); 15 16 await a11yInit; 17 ok(accService, "Service initialized"); 18 19 // Accessible document reference will live longer than the scope of this 20 // function. 21 let docAcc = accService.getAccessibleFor(document); 22 ok(docAcc, "Accessible document is created"); 23 24 let canShutdown = false; 25 // This promise will resolve only if canShutdown flag is set to true. If 26 // 'a11y-init-or-shutdown' event with '0' flag comes before it can be shut 27 // down, the promise will reject. 28 const [a11yShutdownObserver, a11yShutdownPromise] = shutdownAccService(); 29 await a11yShutdownObserver; 30 const a11yShutdown = new Promise((resolve, reject) => 31 a11yShutdownPromise.then(() => 32 canShutdown 33 ? resolve() 34 : reject("Accessible service was shut down incorrectly") 35 ) 36 ); 37 38 accService = null; 39 ok(!accService, "Service is removed"); 40 41 // Force garbage collection that should not trigger shutdown because there is 42 // a reference to an accessible document. 43 forceGC(); 44 // Have some breathing room when removing a11y service references. 45 await TestUtils.waitForTick(); 46 47 // Now allow a11y service to shutdown. 48 canShutdown = true; 49 // Remove a reference to an accessible document. 50 docAcc = null; 51 ok(!docAcc, "Accessible document is removed"); 52 53 // Force garbage collection that should now trigger shutdown. 54 forceGC(); 55 await a11yShutdown; 56 });