browser_shutdown_parent_own_reference.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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('Trying to shut down a service in content and making sure it stays ' +
  36. 'alive as it was started by parent');
  37. let contentCanShutdown = false;
  38. // This promise will resolve only if contentCanShutdown flag is set to true.
  39. // If 'a11y-init-or-shutdown' event with '0' flag (in content) comes before
  40. // it can be shut down, the promise will reject.
  41. let contentA11yShutdown = new Promise((resolve, reject) =>
  42. shutdownPromise(browser).then(flag => contentCanShutdown ?
  43. resolve() : reject('Accessible service was shut down incorrectly')));
  44. // Remove a11y service reference in content and force garbage collection.
  45. // This should not trigger shutdown since a11y was originally initialized by
  46. // the main process.
  47. loadFrameScripts(browser, `accService = null; Components.utils.forceGC();`);
  48. // Have some breathing room between a11y service shutdowns.
  49. yield new Promise(resolve => executeSoon(resolve));
  50. info('Removing a service in parent');
  51. // Now allow a11y service to shutdown in content.
  52. contentCanShutdown = true;
  53. // Remove the a11y service reference in the main process.
  54. let parentA11yShutdown = shutdownPromise();
  55. accService = null;
  56. ok(!accService, 'Service is removed in parent');
  57. // Force garbage collection that should trigger shutdown in both parent and
  58. // content.
  59. forceGC();
  60. yield Promise.all([parentA11yShutdown, contentA11yShutdown]);
  61. // Unsetting e10s related preferences.
  62. yield unsetE10sPrefs();
  63. });
  64. });