Skip to content

Commit

Permalink
Backed out 3 changesets (bug 1323185) for Mn bustage a=backout CLOSED…
Browse files Browse the repository at this point in the history
… TREE

Backed out changeset 2aa7604fbaaf (bug 1323185)
Backed out changeset 5b6ffae33504 (bug 1323185)
Backed out changeset ae6657776fe0 (bug 1323185)

MozReview-Commit-ID: 44EXnjm4RPt

--HG--
rename : testing/marionette/harness/marionette_harness/tests/unit/test_window_handles_content.py => testing/marionette/harness/marionette_harness/tests/unit/test_window_handles.py
  • Loading branch information
KWierso committed Jan 24, 2017
1 parent 12d87c0 commit f4f0210
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 444 deletions.
2 changes: 1 addition & 1 deletion testing/firefox-ui/tests/puppeteer/test_tabbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_close_not_selected_tab(self):
tabbar = self.browser.tabbar

new_tab = tabbar.open_tab()
tabbar.close_tab(tabbar.tabs[0], trigger="button")
tabbar.close_tab(tabbar.tabs[0])

self.assertEqual(len(tabbar.tabs), 1)
self.assertEqual(new_tab, tabbar.tabs[0])
Expand Down
167 changes: 59 additions & 108 deletions testing/marionette/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,6 @@ this.browser = {};

const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";


/**
* Get the <xul:browser> for the specified tab.
*
* @param {<xul:tab>} tab
* The tab whose browser needs to be returned.
*
* @return {<xul:browser>}
* The linked browser for the tab.
*
* @throws UnsupportedOperationError
* If tab handling for the current application isn't supported.
*/
browser.getBrowserForTab = function (tab) {
if (tab.hasOwnProperty("browser")) {
// Fennec
return tab.browser;

} else if (tab.hasOwnProperty("linkedBrowser")) {
// Firefox
return tab.linkedBrowser;

} else {
new UnsupportedOperationError("getBrowserForTab() not supported.");
}
};

/**
* Return the tab browser for the specified chrome window.
*
* @param {nsIDOMWindow} win
* The window whose tabbrowser needs to be accessed.
*
* @return {<xul:tabbrowser>}
* Tab browser or null if it's not a browser window.
*
* @throws UnsupportedOperationError
* If tab handling for the current application isn't supported.
*/
browser.getTabBrowser = function (win) {
if (win.hasOwnProperty("BrowserApp")) {
// Fennec
return win.BrowserApp;

} else if (win.hasOwnProperty("gBrowser")) {
// Firefox
return win.gBrowser;

} else {
new UnsupportedOperationError("getBrowserForTab() not supported.");
}
};

/**
* Creates a browsing context wrapper.
*
Expand All @@ -94,7 +41,8 @@ browser.Context = class {

// In Firefox this is <xul:tabbrowser> (not <xul:browser>!)
// and BrowserApp in Fennec
this.tabBrowser = browser.getTabBrowser(win);
this.browser = undefined;
this.setBrowser(win);

this.knownFrames = [];

Expand Down Expand Up @@ -130,6 +78,21 @@ browser.Context = class {
this._hasRemotenessChange = false;
}

/**
* Get the <xul:browser> for the current tab in this tab browser.
*
* @return {<xul:browser>}
* Browser linked to |this.tab| or the tab browser's
* |selectedBrowser|.
*/
get browserForTab() {
if (this.browser.getBrowserForTab) {
return this.browser.getBrowserForTab(this.tab);
} else {
return this.browser.selectedBrowser;
}
}

/**
* The current frame ID is managed per browser element on desktop in
* case the ID needs to be refreshed. The currently selected window is
Expand All @@ -140,7 +103,7 @@ browser.Context = class {
if (this.driver.appName == "B2G") {
rv = this._curFrameId;
} else if (this.tab) {
rv = this.getIdForBrowser(browser.getBrowserForTab(this.tab));
rv = this.getIdForBrowser(this.browserForTab);
}
return rv;
}
Expand All @@ -156,7 +119,7 @@ browser.Context = class {
* associated with the currently selected tab.
*/
getTabModalUI() {
let br = browser.getBrowserForTab(this.tab);
let br = this.browserForTab;
if (!br.hasAttribute("tabmodalPromptShowing")) {
return null;
}
Expand All @@ -168,6 +131,24 @@ browser.Context = class {
return modals[0].ui;
}

/**
* Set the browser if the application is not B2G.
*
* @param {nsIDOMWindow} win
* Current window reference.
*/
setBrowser(win) {
switch (this.driver.appName) {
case "Firefox":
this.browser = win.gBrowser;
break;

case "Fennec":
this.browser = win.BrowserApp;
break;
}
}

/**
* Close the current window.
*
Expand All @@ -193,32 +174,20 @@ browser.Context = class {
*
* @return {Promise}
* A promise which is resolved when the current tab has been closed.
*
* @throws UnsupportedOperationError
* If tab handling for the current application isn't supported.
*/
closeTab() {
// If the current window is not a browser then close it directly. Do the
// same if only one remaining tab is open, or no tab selected at all.
if (!this.tabBrowser || this.tabBrowser.tabs.length === 1 || !this.tab) {
if (!this.browser || !this.tab || this.browser.browsers.length == 1) {
return this.closeWindow();
}

return new Promise((resolve, reject) => {
if (this.tabBrowser.closeTab) {
// Fennec
this.tabBrowser.deck.addEventListener("TabClose", ev => {
resolve();
}, {once: true});
this.tabBrowser.closeTab(this.tab);

} else if (this.tabBrowser.removeTab) {
// Firefox
if (this.browser.removeTab) {
this.tab.addEventListener("TabClose", ev => {
resolve();
}, {once: true});
this.tabBrowser.removeTab(this.tab);

this.browser.removeTab(this.tab);
} else {
reject(new UnsupportedOperationError(
`closeTab() not supported in ${this.driver.appName}`));
Expand All @@ -233,47 +202,29 @@ browser.Context = class {
* URI to open.
*/
addTab(uri) {
return this.tabBrowser.addTab(uri, true);
return this.browser.addTab(uri, true);
}

/**
* Set the current tab and update remoteness tracking if a tabbrowser is available.
* Re-sets current tab and updates remoteness tracking.
*
* @param {number=} index
* Tab index to switch to. If the parameter is undefined,
* the currently selected tab will be used.
* @param {nsIDOMWindow=} win
* Switch to this window before selecting the tab.
* If a window is provided, the internal reference is updated before
* proceeding.
*/
switchToTab(index, win) {
switchToTab(ind, win) {
if (win) {
this.window = win;
this.tabBrowser = browser.getTabBrowser(win);
}

if (!this.tabBrowser) {
return;
this.setBrowser(win);
}

if (typeof index == "undefined") {
this.tab = this.tabBrowser.selectedTab;
} else {
this.tab = this.tabBrowser.tabs[index];

if (this.tabBrowser.selectTab) {
// Fennec
this.tabBrowser.selectTab(this.tab);

} else {
// Firefox
this.tabBrowser.selectedTab = this.tab;
}
if (this.browser.selectTabAtIndex) {
this.browser.selectTabAtIndex(ind);
this.tab = this.browser.selectedTab;
this._browserWasRemote = this.browserForTab.isRemoteBrowser;
}

if (this.driver.appName == "Firefox") {
this._browserWasRemote = browser.getBrowserForTab(this.tab).isRemoteBrowser;
this._hasRemotenessChange = false;
else {
this.tab = this.browser.selectedTab;
}
this._hasRemotenessChange = false;
}

/**
Expand All @@ -288,15 +239,15 @@ browser.Context = class {
register(uid, target) {
let remotenessChange = this.hasRemotenessChange();
if (this.curFrameId === null || remotenessChange) {
if (this.tabBrowser) {
if (this.browser) {
// If we're setting up a new session on Firefox, we only process the
// registration for this frame if it belongs to the current tab.
if (!this.tab) {
this.switchToTab();
this.switchToTab(this.browser.selectedIndex);
}

if (target == browser.getBrowserForTab(this.tab)) {
this.updateIdForBrowser(browser.getBrowserForTab(this.tab), uid);
if (target == this.browserForTab) {
this.updateIdForBrowser(this.browserForTab, uid);
this.mainContentId = uid;
}
} else {
Expand All @@ -320,15 +271,15 @@ browser.Context = class {
// and may not apply on Fennec.
if (this.driver.appName != "Firefox" ||
this.tab === null ||
browser.getBrowserForTab(this.tab) === null) {
this.browserForTab === null) {
return false;
}

if (this._hasRemotenessChange) {
return true;
}

let currentIsRemote = browser.getBrowserForTab(this.tab).isRemoteBrowser;
let currentIsRemote = this.browserForTab.isRemoteBrowser;
this._hasRemotenessChange = this._browserWasRemote !== currentIsRemote;
this._browserWasRemote = currentIsRemote;
return this._hasRemotenessChange;
Expand Down
36 changes: 16 additions & 20 deletions testing/marionette/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,14 @@ Object.defineProperty(GeckoDriver.prototype, "windowHandles", {

while (winEn.hasMoreElements()) {
let win = winEn.getNext();
let tabBrowser = browser.getTabBrowser(win);

if (tabBrowser) {
tabBrowser.tabs.forEach(tab => {
let winId = this.getIdForBrowser(browser.getBrowserForTab(tab));
if (win.gBrowser) {
let tabbrowser = win.gBrowser;
for (let i = 0; i < tabbrowser.browsers.length; ++i) {
let winId = this.getIdForBrowser(tabbrowser.getBrowserAtIndex(i));
if (winId !== null) {
hs.push(winId);
}
});
}
} else {
// For other chrome windows beside the browser window, only count the window itself.
let winId = win.QueryInterface(Ci.nsIInterfaceRequestor)
Expand Down Expand Up @@ -656,9 +655,7 @@ GeckoDriver.prototype.newSession = function*(cmd, resp) {
yield registerBrowsers;
yield browserListening;

if (this.curBrowser.tab) {
browser.getBrowserForTab(this.curBrowser.tab).focus();
}
this.curBrowser.browserForTab.focus();

return {
sessionId: this.sessionId,
Expand Down Expand Up @@ -817,7 +814,7 @@ GeckoDriver.prototype.executeScript = function*(cmd, resp) {
* @param {string=} sandbox
* Name of the sandbox to evaluate the script in. The sandbox is
* cached for later re-use on the same Window object if
* {@code newSandbox} is false. If the parameter is undefined,
* {@code newSandbox} is false. If he parameter is undefined,
* the script is evaluated in a mutable sandbox. If the parameter
* is "system", it will be evaluted in a sandbox with elevated system
* privileges, equivalent to chrome space.
Expand Down Expand Up @@ -975,7 +972,7 @@ GeckoDriver.prototype.get = function*(cmd, resp) {
});

yield get;
browser.getBrowserForTab(this.curBrowser.tab).focus();
this.curBrowser.browserForTab.focus();
};

/**
Expand Down Expand Up @@ -1202,6 +1199,7 @@ GeckoDriver.prototype.setWindowPosition = function (cmd, resp) {
*/
GeckoDriver.prototype.switchToWindow = function* (cmd, resp) {
let switchTo = cmd.parameters.name;
let isMobile = this.appName == "Fennec";
let found;

let getOuterWindowId = function (win) {
Expand All @@ -1221,13 +1219,12 @@ GeckoDriver.prototype.switchToWindow = function* (cmd, resp) {
while (winEn.hasMoreElements()) {
let win = winEn.getNext();
let outerId = getOuterWindowId(win);
let tabbrowser = browser.getTabBrowser(win);

if (tabbrowser) {
for (let i = 0; i < tabbrowser.tabs.length; ++i) {
let contentBrowser = browser.getBrowserForTab(tabbrowser.tabs[i]);
let contentWindowId = this.getIdForBrowser(contentBrowser);

if (win.gBrowser && !isMobile) {
let tabbrowser = win.gBrowser;
for (let i = 0; i < tabbrowser.browsers.length; ++i) {
let browser = tabbrowser.getBrowserAtIndex(i);
let contentWindowId = this.getIdForBrowser(browser);
if (byNameOrId(win.name, contentWindowId, outerId)) {
found = {
win: win,
Expand Down Expand Up @@ -2117,9 +2114,8 @@ GeckoDriver.prototype.close = function (cmd, resp) {
let win = winEn.getNext();

// For browser windows count the tabs. Otherwise take the window itself.
let tabbrowser = browser.getTabBrowser(win);
if (tabbrowser) {
nwins += tabbrowser.tabs.length;
if (win.gBrowser) {
nwins += win.gBrowser.browsers.length;
} else {
nwins++;
}
Expand Down
Loading

0 comments on commit f4f0210

Please sign in to comment.