Bug 1665437 - [marionette] Fix race between "WebDriver:CloseChromeWindow" and next browsing context check. r=marionette-reviewers,maja_zf

Similar to closing a tab the internal browsing contexts
need to be nullified. This is necessary because browsing
contexts are asynchronously discarded and garbage collected.

Also the "unload" event as currently used to wait for the
chrome window to be closed fires too early. Instead the
"xul-window-destroyed" observer notification needs to be used.

Differential Revision: https://phabricator.services.mozilla.com/D91296
This commit is contained in:
Henrik Skupin 2020-09-24 19:02:26 +00:00
parent 13dc789969
commit 08d5370559
3 changed files with 10 additions and 7 deletions

View file

@ -275,15 +275,14 @@ browser.Context = class {
* @return {Promise} * @return {Promise}
* A promise which is resolved when the current window has been closed. * A promise which is resolved when the current window has been closed.
*/ */
closeWindow() { async closeWindow() {
let destroyed = new MessageManagerDestroyedPromise( const destroyed = waitForObserverTopic("xul-window-destroyed", {
this.window.messageManager checkFn: () => this.window && this.window.closed,
); });
let unloaded = waitForEvent(this.window, "unload");
this.window.close(); this.window.close();
return Promise.all([destroyed, unloaded]); return destroyed;
} }
/** /**

View file

@ -2936,6 +2936,9 @@ GeckoDriver.prototype.closeChromeWindow = async function() {
} }
await this.curBrowser.closeWindow(); await this.curBrowser.closeWindow();
this.chromeBrowsingContext = null;
this.contentBrowsingContext = null;
return this.chromeWindowHandles.map(String); return this.chromeWindowHandles.map(String);
}; };

View file

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import from __future__ import absolute_import, print_function
from marionette_driver import By from marionette_driver import By
from marionette_driver.errors import NoSuchWindowException from marionette_driver.errors import NoSuchWindowException
@ -27,6 +27,7 @@ class TestNoSuchWindowContent(WindowManagerMixin, MarionetteTestCase):
# When closing a browser window both handles are not available # When closing a browser window both handles are not available
for context in ("chrome", "content"): for context in ("chrome", "content"):
print("Testing handles with context {}".format(context))
with self.marionette.using_context(context): with self.marionette.using_context(context):
with self.assertRaises(NoSuchWindowException): with self.assertRaises(NoSuchWindowException):
self.marionette.current_chrome_window_handle self.marionette.current_chrome_window_handle