browser_shutdown_proxy_acc_reference.js (2376B)
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_setup(async function () { 8 await SpecialPowers.pushPrefEnv({ 9 set: [["test.wait300msAfterTabSwitch", true]], 10 }); 11 }); 12 13 add_task(async function () { 14 const [a11yInitObserver, a11yInit] = initAccService(); 15 await a11yInitObserver; 16 17 let accService = Cc["@mozilla.org/accessibilityService;1"].getService( 18 Ci.nsIAccessibilityService 19 ); 20 ok(accService, "Service initialized"); 21 await a11yInit; 22 23 await BrowserTestUtils.withNewTab( 24 { 25 gBrowser, 26 url: `data:text/html, 27 <html> 28 <head> 29 <meta charset="utf-8"/> 30 <title>Accessibility Test</title> 31 </head> 32 <body><div id="div" style="visibility: hidden;"></div></body> 33 </html>`, 34 }, 35 async function (browser) { 36 let onShow = waitForEvent(Ci.nsIAccessibleEvent.EVENT_SHOW, "div"); 37 await invokeSetStyle(browser, "div", "visibility", "visible"); 38 let showEvent = await onShow; 39 let divAcc = showEvent.accessible; 40 ok(divAcc, "Accessible proxy is created"); 41 // Remove unnecessary dangling references 42 onShow = null; 43 showEvent = null; 44 forceGC(); 45 46 let canShutdown = false; 47 const [a11yShutdownObserver, a11yShutdownPromise] = shutdownAccService(); 48 await a11yShutdownObserver; 49 const a11yShutdown = new Promise((resolve, reject) => 50 a11yShutdownPromise.then(() => 51 canShutdown 52 ? resolve() 53 : reject("Accessible service was shut down incorrectly") 54 ) 55 ); 56 57 accService = null; 58 ok(!accService, "Service is removed"); 59 // Force garbage collection that should not trigger shutdown because there 60 // is a reference to an accessible proxy. 61 forceGC(); 62 // Have some breathing room when removing a11y service references. 63 await TestUtils.waitForTick(); 64 65 // Now allow a11y service to shutdown. 66 canShutdown = true; 67 // Remove a last reference to an accessible proxy. 68 divAcc = null; 69 ok(!divAcc, "Accessible proxy is removed"); 70 71 // Force garbage collection that should now trigger shutdown. 72 forceGC(); 73 await a11yShutdown; 74 } 75 ); 76 });