browser_shutdown_remote_own_reference.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 'use strict';
  5. add_task(function* () {
  6. // Making sure that the e10s is enabled on Windows for testing.
  7. yield setE10sPrefs();
  8. yield BrowserTestUtils.withNewTab({
  9. gBrowser,
  10. url: `data:text/html,
  11. <html>
  12. <head>
  13. <meta charset="utf-8"/>
  14. <title>Accessibility Test</title>
  15. </head>
  16. <body></body>
  17. </html>`
  18. }, function*(browser) {
  19. info('Creating a service in parent and waiting for service to be created ' +
  20. 'in content');
  21. // Create a11y service in the main process. This will trigger creating of
  22. // the a11y service in parent as well.
  23. let parentA11yInit = initPromise();
  24. let contentA11yInit = initPromise(browser);
  25. let accService = Cc['@mozilla.org/accessibilityService;1'].getService(
  26. Ci.nsIAccessibilityService);
  27. ok(accService, 'Service initialized in parent');
  28. yield Promise.all([parentA11yInit, contentA11yInit]);
  29. info('Adding additional reference to accessibility service in content ' +
  30. 'process');
  31. // Add a new reference to the a11y service inside the content process.
  32. loadFrameScripts(browser, `let accService = Components.classes[
  33. '@mozilla.org/accessibilityService;1'].getService(
  34. Components.interfaces.nsIAccessibilityService);`);
  35. info('Shutting down a service in parent and making sure the one in ' +
  36. 'content stays alive');
  37. let contentCanShutdown = false;
  38. let parentA11yShutdown = shutdownPromise();
  39. // This promise will resolve only if contentCanShutdown flag is set to true.
  40. // If 'a11y-init-or-shutdown' event with '0' flag (in content) comes before
  41. // it can be shut down, the promise will reject.
  42. let contentA11yShutdown = new Promise((resolve, reject) =>
  43. shutdownPromise(browser).then(flag => contentCanShutdown ?
  44. resolve() : reject('Accessible service was shut down incorrectly')));
  45. // Remove a11y service reference in the main process and force garbage
  46. // collection. This should not trigger shutdown in content since a11y
  47. // service is used by XPCOM.
  48. accService = null;
  49. ok(!accService, 'Service is removed in parent');
  50. // Force garbage collection that should not trigger shutdown because there
  51. // is a reference in a content process.
  52. forceGC();
  53. loadFrameScripts(browser, `Components.utils.forceGC();`);
  54. yield parentA11yShutdown;
  55. // Have some breathing room between a11y service shutdowns.
  56. yield new Promise(resolve => executeSoon(resolve));
  57. info('Removing a service in content');
  58. // Now allow a11y service to shutdown in content.
  59. contentCanShutdown = true;
  60. // Remove last reference to a11y service in content and force garbage
  61. // collection that should trigger shutdown.
  62. loadFrameScripts(browser, `accService = null; Components.utils.forceGC();`);
  63. yield contentA11yShutdown;
  64. // Unsetting e10s related preferences.
  65. yield unsetE10sPrefs();
  66. });
  67. });