Bug 1322383 - getCurrentWindow() has to only return the currently selected window. r=ato,maja_zf

Given that this method will be used in each command for checks of a valid window, we have to return
the currently active window. It means the window mediator should only be used during setting up the
session to find the first browser window.

At the same time the code in this method is getting split-up for chrome and content scopes.

MozReview-Commit-ID: KyzxYk63RgA

--HG--
extra : rebase_source : 0ff9ab53babcf60e9120d435ea6abb82d70aebec
This commit is contained in:
Henrik Skupin 2017-02-08 12:58:45 +01:00
Родитель f681f14f4f
Коммит 14cf73d88f
1 изменённых файлов: 30 добавлений и 23 удалений

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

@ -309,33 +309,41 @@ GeckoDriver.prototype.sendTargettedAsyncMessage_ = function (name, payload) {
};
/**
* Gets the current active window.
* Get the session's current top-level browsing context.
*
* It will return the outer {@ChromeWindow} previously selected by window handle
* through {@code #switchToWindow}, or the first window that was registered.
*
* @param {Context=} forcedContext
* Optional name of the context to use for the checks.
* Defaults to the current context.
* Optional name of the context to use for finding the window. It will be required
* if a command always needs a specific context, whether which context is
* currently set. Defaults to the current context.
*
* @return {nsIDOMWindow}
* @return {ChromeWindow}
* The current top-level browsing context.
*/
GeckoDriver.prototype.getCurrentWindow = function (forcedContext = undefined) {
let context = typeof forcedContext == "undefined" ? this.context : forcedContext;
let win = null;
if (this.curFrame === null) {
if (this.curBrowser === null) {
let typ = (context === Context.CONTENT) ? "navigator:browser" : null;
win = Services.wm.getMostRecentWindow(typ);
} else {
if (context === Context.CHROME) {
win = this.curBrowser.window;
} else {
if (this.curBrowser.tab && browser.getBrowserForTab(this.curBrowser.tab)) {
win = this.curBrowser.window;
}
}
}
} else {
switch (context) {
case Context.CHROME:
if (this.curFrame !== null) {
win = this.curFrame;
} else {
win = this.curBrowser.window;
}
break;
case Context.CONTENT:
if (this.curFrame !== null) {
win = this.curFrame;
} else if (this.curBrowser.tab && browser.getBrowserForTab(this.curBrowser.tab)) {
win = this.curBrowser.window;
}
break;
}
return win;
@ -604,7 +612,8 @@ GeckoDriver.prototype.newSession = function* (cmd, resp) {
let browserListening = this.listeningPromise();
let waitForWindow = function () {
let win = this.getCurrentWindow();
let win = Services.wm.getMostRecentWindow("navigator:browser");
if (!win) {
// if the window isn't even created, just poll wait for it
let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
@ -624,10 +633,8 @@ GeckoDriver.prototype.newSession = function* (cmd, resp) {
win.addEventListener("load", listener, true);
} else {
let clickToStart = Preferences.get(CLICK_TO_START_PREF);
if (clickToStart && (this.appName != "B2G")) {
let pService = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
pService.alert(win, "", "Click to start execution of marionette tests");
if (clickToStart) {
Services.prompt.alert(win, "", "Click to start execution of marionette tests");
}
this.startBrowser(win, true);
}