Bug 1726465 - [marionette] Don't wait for initial window when new "moz:windowless" capability is set. r=webdriver-reviewers,jdescottes

Depends on D134276

Differential Revision: https://phabricator.services.mozilla.com/D134277
This commit is contained in:
Henrik Skupin 2022-05-10 09:04:05 +00:00
Родитель 25618e908d
Коммит 09b795477f
4 изменённых файлов: 75 добавлений и 55 удалений

Просмотреть файл

@ -423,64 +423,67 @@ GeckoDriver.prototype.newSession = async function(cmd) {
this._currentSession.capabilities.delete("webSocketUrl");
}
// Creating a WebDriver session too early can cause issues with
// clients in not being able to find any available window handle.
// Also when closing the application while it's still starting up can
// cause shutdown hangs. As such Marionette will return a new session
// once the initial application window has finished initializing.
logger.debug(`Waiting for initial application window`);
await Marionette.browserStartupFinished;
const win = await windowManager.waitForInitialApplicationWindowLoaded();
if (MarionettePrefs.clickToStart) {
Services.prompt.alert(
win,
"",
"Click to start execution of marionette tests"
);
}
this.addBrowser(win);
this.mainFrame = win;
registerCommandsActor();
enableEventsActor();
// Setup observer for modal dialogs
this.dialogObserver = new modal.DialogObserver(() => this.curBrowser);
this.dialogObserver.add(this.handleModalDialog.bind(this));
// Don't wait for the initial window when Marionette is in windowless mode
if (!this.currentSession.capabilities.get("moz:windowless")) {
// Creating a WebDriver session too early can cause issues with
// clients in not being able to find any available window handle.
// Also when closing the application while it's still starting up can
// cause shutdown hangs. As such Marionette will return a new session
// once the initial application window has finished initializing.
logger.debug(`Waiting for initial application window`);
await Marionette.browserStartupFinished;
for (let win of windowManager.windows) {
const tabBrowser = TabManager.getTabBrowser(win);
const appWin = await windowManager.waitForInitialApplicationWindowLoaded();
if (tabBrowser) {
for (const tab of tabBrowser.tabs) {
const contentBrowser = TabManager.getBrowserForTab(tab);
this.registerBrowser(contentBrowser);
}
if (MarionettePrefs.clickToStart) {
Services.prompt.alert(
appWin,
"",
"Click to start execution of marionette tests"
);
}
this.registerListenersForWindow(win);
this.addBrowser(appWin);
this.mainFrame = appWin;
// Setup observer for modal dialogs
this.dialogObserver = new modal.DialogObserver(() => this.curBrowser);
this.dialogObserver.add(this.handleModalDialog.bind(this));
for (let win of windowManager.windows) {
const tabBrowser = TabManager.getTabBrowser(win);
if (tabBrowser) {
for (const tab of tabBrowser.tabs) {
const contentBrowser = TabManager.getBrowserForTab(tab);
this.registerBrowser(contentBrowser);
}
}
this.registerListenersForWindow(win);
}
if (this.mainFrame) {
this.currentSession.chromeBrowsingContext = this.mainFrame.browsingContext;
this.mainFrame.focus();
}
if (this.curBrowser.tab) {
const browsingContext = this.curBrowser.contentBrowser.browsingContext;
this.currentSession.contentBrowsingContext = browsingContext;
await waitForInitialNavigationCompleted(browsingContext.webProgress);
this.curBrowser.contentBrowser.focus();
}
// Check if there is already an open dialog for the selected browser window.
this.dialog = modal.findModalDialogs(this.curBrowser);
}
if (this.mainFrame) {
this.currentSession.chromeBrowsingContext = this.mainFrame.browsingContext;
this.mainFrame.focus();
}
if (this.curBrowser.tab) {
const browsingContext = this.curBrowser.contentBrowser.browsingContext;
this.currentSession.contentBrowsingContext = browsingContext;
await waitForInitialNavigationCompleted(browsingContext.webProgress);
this.curBrowser.contentBrowser.focus();
}
// Check if there is already an open dialog for the selected browser window.
this.dialog = modal.findModalDialogs(this.curBrowser);
Services.obs.addObserver(this, "browser-delayed-startup-finished");
} catch (e) {
throw new error.SessionNotCreatedError(e);

Просмотреть файл

@ -270,7 +270,7 @@ class WindowManager {
resolve(subject);
},
{
errorMessage: "No applicable application windows found",
errorMessage: "No applicable application window found",
}
);
}

Просмотреть файл

@ -457,6 +457,7 @@ class Capabilities extends Map {
],
["moz:useNonSpecCompliantPointerOrigin", false],
["moz:webdriverClick", true],
["moz:windowless", false],
]);
}
@ -586,6 +587,11 @@ class Capabilities extends Map {
assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
break;
// Don't set the value because it's only used to return the address
// of the Remote Agent's debugger (HTTP server).
case "moz:debuggerAddress":
continue;
case "moz:useNonSpecCompliantPointerOrigin":
assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
break;
@ -594,10 +600,9 @@ class Capabilities extends Map {
assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
break;
// Don't set the value because it's only used to return the address
// of the Remote Agent's debugger (HTTP server).
case "moz:debuggerAddress":
continue;
case "moz:windowless":
assert.boolean(v, pprint`Expected ${k} to be boolean, got ${v}`);
break;
}
matched.set(k, v);

Просмотреть файл

@ -5,6 +5,8 @@
from __future__ import absolute_import, print_function
import os
import sys
import unittest
from marionette_driver.errors import SessionNotCreatedException
from marionette_harness import MarionetteTestCase
@ -103,6 +105,9 @@ class TestCapabilities(MarionetteTestCase):
self.assertIn("moz:webdriverClick", self.caps)
self.assertTrue(self.caps["moz:webdriverClick"])
self.assertIn("moz:windowless", self.caps)
self.assertFalse(self.caps["moz:windowless"])
def test_disable_webdriver_click(self):
self.marionette.delete_session()
self.marionette.start_session({"moz:webdriverClick": False})
@ -115,13 +120,20 @@ class TestCapabilities(MarionetteTestCase):
caps = self.marionette.session_capabilities
self.assertTrue(caps["moz:useNonSpecCompliantPointerOrigin"])
def test_we_get_valid_uuid4_when_creating_a_session(self):
def test_valid_uuid4_when_creating_a_session(self):
self.assertNotIn(
"{",
self.marionette.session_id,
"Session ID has {{}} in it: {}".format(self.marionette.session_id),
)
@unittest.skipUnless(sys.platform.startswith("darwin"), "Only supported on MacOS")
def test_windowless(self):
self.marionette.delete_session()
self.marionette.start_session({"moz:windowless": True})
caps = self.marionette.session_capabilities
self.assertTrue(caps["moz:windowless"])
class TestCapabilityMatching(MarionetteTestCase):
def setUp(self):