browser_shutdown_multi_acc_reference_obj.js (2480B)
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 let docAcc = accService.getAccessibleFor(document); 20 ok(docAcc, "Accessible document is created"); 21 22 // Accessible object reference will live longer than the scope of this 23 // function. 24 let acc = await new Promise(resolve => { 25 let intervalId = setInterval(() => { 26 let tabAcc = accService.getAccessibleFor(gBrowser.selectedTab); 27 if (tabAcc) { 28 clearInterval(intervalId); 29 resolve(tabAcc); 30 } 31 }, 10); 32 }); 33 ok(acc, "Accessible object is created"); 34 35 let canShutdown = false; 36 // This promise will resolve only if canShutdown flag is set to true. If 37 // 'a11y-init-or-shutdown' event with '0' flag comes before it can be shut 38 // down, the promise will reject. 39 const [a11yShutdownObserver, a11yShutdownPromise] = shutdownAccService(); 40 await a11yShutdownObserver; 41 const a11yShutdown = new Promise((resolve, reject) => 42 a11yShutdownPromise.then(() => 43 canShutdown 44 ? resolve() 45 : reject("Accessible service was shut down incorrectly") 46 ) 47 ); 48 49 accService = null; 50 ok(!accService, "Service is removed"); 51 52 // Force garbage collection that should not trigger shutdown because there are 53 // references to accessible objects. 54 forceGC(); 55 // Have some breathing room when removing a11y service references. 56 await TestUtils.waitForTick(); 57 58 // Remove a reference to an accessible document. 59 docAcc = null; 60 ok(!docAcc, "Accessible document is removed"); 61 // Force garbage collection that should not trigger shutdown because there is 62 // a reference to an accessible object. 63 forceGC(); 64 // Have some breathing room when removing a11y service references. 65 await TestUtils.waitForTick(); 66 67 // Now allow a11y service to shutdown. 68 canShutdown = true; 69 // Remove a reference to an accessible object. 70 acc = null; 71 ok(!acc, "Accessible object is removed"); 72 73 // Force garbage collection that should now trigger shutdown. 74 forceGC(); 75 await a11yShutdown; 76 });