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