Bug 1274106 - Ensure opening tabs in background from about:debugging test. r=jdescottes

MozReview-Commit-ID: kSeAw9Xz1A

--HG--
extra : rebase_source : d9b4ca87a1e2023e96f6b056e3d4b1d3921337c6
This commit is contained in:
Alexandre Poirot 2016-09-14 07:41:08 -07:00
parent 4e18ab329e
commit 9cc1756d21
4 changed files with 18 additions and 48 deletions

View File

@ -55,6 +55,6 @@ add_task(function* () {
let img = document.querySelector(imgClass);
ok(img, "warning message is rendered");
yield closeAboutDebugging(tab, win);
yield closeAboutDebugging(tab);
win.close();
});

View File

@ -21,7 +21,7 @@ add_task(function* () {
// Open a new tab in background and wait for its addition in the UI
let onNewTab = waitForMutation(tabsElement, { childList: true });
let newTab = yield addTab(TAB_URL, null, true);
let newTab = yield addTab(TAB_URL, { background: true });
yield onNewTab;
// Check that the new tab appears in the UI, but with an empty name

View File

@ -31,7 +31,7 @@ function* openAboutDebugging(page, win) {
url += "#" + page;
}
let tab = yield addTab(url, win);
let tab = yield addTab(url, { window: win });
let browser = tab.linkedBrowser;
let document = browser.contentDocument;
@ -63,49 +63,9 @@ function openPanel(document, panelId) {
document.querySelector(".main-content"), {childList: true});
}
function closeAboutDebugging(tab, win) {
function closeAboutDebugging(tab) {
info("Closing about:debugging");
return removeTab(tab, win);
}
function addTab(url, win, backgroundTab = false) {
info("Adding tab: " + url);
return new Promise(done => {
let targetWindow = win || window;
let targetBrowser = targetWindow.gBrowser;
targetWindow.focus();
let tab = targetBrowser.addTab(url);
if (!backgroundTab) {
targetBrowser.selectedTab = tab;
}
let linkedBrowser = tab.linkedBrowser;
BrowserTestUtils.browserLoaded(linkedBrowser)
.then(function () {
info("Tab added and finished loading: " + url);
done(tab);
});
});
}
function removeTab(tab, win) {
info("Removing tab.");
return new Promise(done => {
let targetWindow = win || window;
let targetBrowser = targetWindow.gBrowser;
let tabContainer = targetBrowser.tabContainer;
tabContainer.addEventListener("TabClose", function onClose() {
tabContainer.removeEventListener("TabClose", onClose, false);
info("Tab removed and finished closing.");
done();
}, false);
targetBrowser.removeTab(tab);
});
return removeTab(tab);
}
function getSupportsFile(path) {

View File

@ -107,13 +107,22 @@ registerCleanupFunction(function* cleanup() {
/**
* Add a new test tab in the browser and load the given url.
* @param {String} url The url to be loaded in the new tab
* @param {Object} options Object with various optional fields:
* - {Boolean} background If true, open the tab in background
* - {ChromeWindow} window Firefox top level window we should use to open the tab
* @return a promise that resolves to the tab object when the url is loaded
*/
var addTab = Task.async(function* (url) {
var addTab = Task.async(function* (url, options = { background: false, window: window }) {
info("Adding a new tab with URL: " + url);
let tab = gBrowser.selectedTab = gBrowser.addTab(url);
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
let { background } = options;
let { gBrowser } = options.window ? options.window : window;
let tab = gBrowser.addTab(url);
if (!background) {
gBrowser.selectedTab = tab;
}
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
info("Tab added and finished loading");
@ -128,6 +137,7 @@ var addTab = Task.async(function* (url) {
var removeTab = Task.async(function* (tab) {
info("Removing tab.");
let { gBrowser } = tab.ownerDocument.defaultView;
let onClose = once(gBrowser.tabContainer, "TabClose");
gBrowser.removeTab(tab);
yield onClose;