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