browser_shutdown_remote_no_reference.js (4149B)
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 await BrowserTestUtils.withNewTab( 9 { 10 gBrowser, 11 url: `data:text/html, 12 <html> 13 <head> 14 <meta charset="utf-8"/> 15 <title>Accessibility Test</title> 16 </head> 17 <body></body> 18 </html>`, 19 }, 20 async function (browser) { 21 info( 22 "Creating a service in parent and waiting for service to be created " + 23 "in content" 24 ); 25 await loadContentScripts(browser, { 26 script: "Common.sys.mjs", 27 symbol: "CommonUtils", 28 }); 29 // Create a11y service in the main process. This will trigger creating of 30 // the a11y service in parent as well. 31 const [parentA11yInitObserver, parentA11yInit] = initAccService(); 32 const [contentA11yInitObserver, contentA11yInit] = 33 initAccService(browser); 34 let [parentConsumersChangedObserver, parentConsumersChanged] = 35 accConsumersChanged(); 36 let [contentConsumersChangedObserver, contentConsumersChanged] = 37 accConsumersChanged(browser); 38 39 await Promise.all([ 40 parentA11yInitObserver, 41 contentA11yInitObserver, 42 parentConsumersChangedObserver, 43 contentConsumersChangedObserver, 44 ]); 45 46 let accService = Cc["@mozilla.org/accessibilityService;1"].getService( 47 Ci.nsIAccessibilityService 48 ); 49 ok(accService, "Service initialized in parent"); 50 await Promise.all([parentA11yInit, contentA11yInit]); 51 await parentConsumersChanged.then(data => 52 Assert.deepEqual( 53 data, 54 { 55 XPCOM: true, 56 MainProcess: false, 57 PlatformAPI: false, 58 }, 59 "Accessibility service consumers in parent are correct." 60 ) 61 ); 62 await contentConsumersChanged.then(data => 63 Assert.deepEqual( 64 data, 65 { 66 XPCOM: false, 67 MainProcess: true, 68 PlatformAPI: false, 69 }, 70 "Accessibility service consumers in content are correct." 71 ) 72 ); 73 74 Assert.deepEqual( 75 JSON.parse(accService.getConsumers()), 76 { 77 XPCOM: true, 78 MainProcess: false, 79 PlatformAPI: false, 80 }, 81 "Accessibility service consumers in parent are correct." 82 ); 83 84 info( 85 "Removing a service in parent and waiting for service to be shut " + 86 "down in content" 87 ); 88 // Remove a11y service reference in the main process. 89 const [parentA11yShutdownObserver, parentA11yShutdown] = 90 shutdownAccService(); 91 const [contentA11yShutdownObserver, contentA11yShutdown] = 92 shutdownAccService(browser); 93 [parentConsumersChangedObserver, parentConsumersChanged] = 94 accConsumersChanged(); 95 [contentConsumersChangedObserver, contentConsumersChanged] = 96 accConsumersChanged(browser); 97 98 await Promise.all([ 99 parentA11yShutdownObserver, 100 contentA11yShutdownObserver, 101 parentConsumersChangedObserver, 102 contentConsumersChangedObserver, 103 ]); 104 105 accService = null; 106 ok(!accService, "Service is removed in parent"); 107 // Force garbage collection that should trigger shutdown in both main and 108 // content process. 109 forceGC(); 110 await Promise.all([parentA11yShutdown, contentA11yShutdown]); 111 await parentConsumersChanged.then(data => 112 Assert.deepEqual( 113 data, 114 { 115 XPCOM: false, 116 MainProcess: false, 117 PlatformAPI: false, 118 }, 119 "Accessibility service consumers are correct." 120 ) 121 ); 122 await contentConsumersChanged.then(data => 123 Assert.deepEqual( 124 data, 125 { 126 XPCOM: false, 127 MainProcess: false, 128 PlatformAPI: false, 129 }, 130 "Accessibility service consumers are correct." 131 ) 132 ); 133 } 134 ); 135 });