Bug 1001521 - Fix tabview tests that remove the original tab r=smacleod

This commit is contained in:
Tim Taubert 2014-04-25 18:01:04 +02:00
parent 5b00b9e16e
commit 35e71b64ec
9 changed files with 103 additions and 114 deletions

View File

@ -37,6 +37,7 @@ function test() {
Services.prefs.clearUserPref("browser.sessionstore.restore_hidden_tabs");
gBrowser.selectedTab = gBrowser.tabs[0];
ss.setBrowserState(stateBackup);
});

View File

@ -9,6 +9,10 @@ function test() {
registerCleanupFunction(function() {
gBrowser.unpinTab(pinnedTab);
// Don't remove the initial tab.
gBrowser.moveTabTo(gBrowser.tabs[1], 0);
while (gBrowser.tabs[1])
gBrowser.removeTab(gBrowser.tabs[1]);
hideTabView();

View File

@ -3,34 +3,26 @@
function test() {
waitForExplicitFinish();
window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
TabView.toggle();
newWindowWithTabView(onTabViewWindowLoaded);
}
function onTabViewWindowLoaded() {
window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
let contentWindow = document.getElementById("tab-view").contentWindow;
function onTabViewWindowLoaded(win) {
let contentWindow = win.TabView.getContentWindow();
is(contentWindow.GroupItems.groupItems.length, 1,
"There is one group item on startup");
is(gBrowser.tabs.length, 1, "There is one tab on startup");
is(win.gBrowser.tabs.length, 1, "There is one tab on startup");
let groupItem = contentWindow.GroupItems.groupItems[0];
hideGroupItem(groupItem, function () {
let onTabViewHidden = function() {
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
hideTabView(() => {
is(contentWindow.GroupItems.groupItems.length, 1,
"There is still one group item");
isnot(groupItem, contentWindow.GroupItems.groupItems[0],
"The initial group item is not the same as the final group item");
is(gBrowser.tabs.length, 1, "There is only one tab");
ok(!TabView.isVisible(), "Tab View is hidden");
finish();
};
window.addEventListener("tabviewhidden", onTabViewHidden, false);
TabView.hide();
is(win.gBrowser.tabs.length, 1, "There is only one tab");
ok(!win.TabView.isVisible(), "Tab View is hidden");
promiseWindowClosed(win).then(finish);
}, win);
});
}

View File

@ -40,7 +40,7 @@ function test() {
is(targetGroup.getChildren().length, 2, 'target group has now two children');
// cleanup and finish
tabItem.close();
targetGroup.getChild(0).close();
hideTabView(finishTest);
});
}

View File

@ -3,6 +3,7 @@
function test() {
let cw;
let win;
let currentTest;
let getGroupItem = function (index) {
@ -15,7 +16,7 @@ function test() {
cw.UI.setActive(groupItem);
for (let i=0; i<numTabs || 0; i++)
gBrowser.loadOneTab('about:blank', {inBackground: true});
win.gBrowser.loadOneTab('about:blank', {inBackground: true});
return groupItem;
}
@ -35,13 +36,13 @@ function test() {
}
currentTest = test.name;
showTabView(test.func);
showTabView(test.func, win);
} else
hideTabView(finish);
promiseWindowClosed(win).then(finish);
}
let assertTabViewIsHidden = function () {
ok(!TabView.isVisible(), currentTest + ': tabview is hidden');
ok(!win.TabView.isVisible(), currentTest + ': tabview is hidden');
}
let assertNumberOfGroupItems = function (num) {
@ -49,7 +50,7 @@ function test() {
}
let assertNumberOfTabs = function (num) {
is(gBrowser.tabs.length, num, currentTest + ': number of tabs is equal to ' + num);
is(win.gBrowser.tabs.length, num, currentTest + ': number of tabs is equal to ' + num);
}
let assertGroupItemRemoved = function (groupItem) {
@ -68,7 +69,7 @@ function test() {
closeGroupItem(groupItem, function () {
assertNumberOfGroupItems(1);
assertGroupItemRemoved(groupItem);
whenTabViewIsHidden(next);
whenTabViewIsHidden(next, win);
});
}
@ -82,7 +83,7 @@ function test() {
assertNumberOfGroupItems(1);
assertGroupItemRemoved(groupItem);
next();
});
}, win);
});
}
@ -97,7 +98,7 @@ function test() {
closeGroupItem(groupItem, function () {
assertNumberOfGroupItems(1);
assertGroupItemExists(newGroupItem);
hideTabView(next);
hideTabView(next, win);
});
}
@ -115,7 +116,7 @@ function test() {
assertGroupItemRemoved(groupItem);
assertGroupItemExists(newGroupItem);
next();
});
}, win);
});
}
@ -123,37 +124,37 @@ function test() {
// action: exit panorama
// expected: nothing should happen
let testPinnedTab1 = function () {
gBrowser.pinTab(gBrowser.selectedTab);
win.gBrowser.pinTab(win.gBrowser.selectedTab);
let groupItem = getGroupItem(0);
hideTabView(function () {
assertNumberOfGroupItems(1);
assertGroupItemExists(groupItem);
gBrowser.unpinTab(gBrowser.selectedTab);
win.gBrowser.unpinTab(win.gBrowser.selectedTab);
next();
});
}, win);
}
// setup: 1 pinned tab
// action: exit panorama
// expected: new blank group is created
let testPinnedTab2 = function () {
gBrowser.pinTab(gBrowser.selectedTab);
win.gBrowser.pinTab(win.gBrowser.selectedTab);
getGroupItem(0).close();
hideTabView(function () {
assertNumberOfTabs(1);
assertNumberOfGroupItems(1);
gBrowser.unpinTab(gBrowser.selectedTab);
win.gBrowser.unpinTab(win.gBrowser.selectedTab);
next();
});
}, win);
}
// setup: 1 pinned tab, 1 empty group, 1 non-empty group
// action: close non-empty group
// expected: nothing should happen
let testPinnedTab3 = function () {
gBrowser.pinTab(gBrowser.selectedTab);
win.gBrowser.pinTab(win.gBrowser.selectedTab);
let groupItem = getGroupItem(0);
let newGroupItem = createGroupItem(1);
@ -163,8 +164,8 @@ function test() {
assertNumberOfGroupItems(1);
assertGroupItemExists(groupItem);
gBrowser.unpinTab(gBrowser.selectedTab);
hideTabView(next);
win.gBrowser.unpinTab(win.gBrowser.selectedTab);
hideTabView(next, win);
});
}
@ -172,7 +173,7 @@ function test() {
// action: hide non-empty group, exit panorama
// expected: nothing should happen
let testPinnedTab4 = function () {
gBrowser.pinTab(gBrowser.selectedTab);
win.gBrowser.pinTab(win.gBrowser.selectedTab);
let groupItem = getGroupItem(0);
let newGroupItem = createGroupItem(1);
@ -183,9 +184,9 @@ function test() {
assertNumberOfGroupItems(1);
assertGroupItemExists(groupItem);
assertGroupItemRemoved(newGroupItem);
gBrowser.unpinTab(gBrowser.selectedTab);
win.gBrowser.unpinTab(win.gBrowser.selectedTab);
next();
});
}, win);
});
}
@ -200,7 +201,7 @@ function test() {
closeGroupItem(groupItem, function () {
assertNumberOfGroupItems(1);
assertGroupItemExists(newGroupItem);
whenTabViewIsHidden(next);
whenTabViewIsHidden(next, win);
});
}
@ -218,7 +219,7 @@ function test() {
assertGroupItemRemoved(groupItem);
assertGroupItemExists(newGroupItem);
next();
});
}, win);
});
}
@ -235,7 +236,7 @@ function test() {
assertNumberOfGroupItems(1);
assertGroupItemRemoved(groupItem);
assertGroupItemExists(hiddenGroupItem);
hideTabView(next);
hideTabView(next, win);
});
});
}
@ -255,7 +256,7 @@ function test() {
assertGroupItemRemoved(groupItem);
assertGroupItemRemoved(hiddenGroupItem);
next();
});
}, win);
});
});
}
@ -279,8 +280,9 @@ function test() {
waitForExplicitFinish();
showTabView(function () {
cw = TabView.getContentWindow();
newWindowWithTabView(window => {
win = window;
cw = win.TabView.getContentWindow();
next();
});
}

View File

@ -3,11 +3,12 @@
function test() {
let cw;
let win;
let groupItemId;
let prefix = 'start';
let assertTabViewIsHidden = function () {
ok(!TabView.isVisible(), prefix + ': tabview is hidden');
ok(!win.TabView.isVisible(), prefix + ': tabview is hidden');
}
let assertNumberOfGroups = function (num) {
@ -15,11 +16,11 @@ function test() {
}
let assertNumberOfTabs = function (num) {
is(gBrowser.visibleTabs.length, num, prefix + ': there should be ' + num + ' tabs');
is(win.gBrowser.visibleTabs.length, num, prefix + ': there should be ' + num + ' tabs');
}
let assertNumberOfPinnedTabs = function (num) {
is(gBrowser._numPinnedTabs, num, prefix + ': there should be ' + num + ' pinned tabs');
is(win.gBrowser._numPinnedTabs, num, prefix + ': there should be ' + num + ' pinned tabs');
}
let assertGroupItemPreserved = function () {
@ -34,7 +35,7 @@ function test() {
}
let createTab = function (url) {
return gBrowser.loadOneTab(url || 'http://mochi.test:8888/', {inBackground: true});
return win.gBrowser.loadOneTab(url || 'http://mochi.test:8888/', {inBackground: true});
}
let createBlankTab = function () {
@ -44,7 +45,7 @@ function test() {
let finishTest = function () {
prefix = 'finish';
assertValidPrerequisites();
finish();
promiseWindowClosed(win).then(finish);
}
let testUndoCloseWithSelectedBlankTab = function () {
@ -53,7 +54,7 @@ function test() {
assertNumberOfTabs(2);
afterAllTabsLoaded(function () {
gBrowser.removeTab(tab);
win.gBrowser.removeTab(tab);
assertNumberOfTabs(1);
assertNumberOfPinnedTabs(0);
@ -63,9 +64,9 @@ function test() {
assertGroupItemPreserved();
createBlankTab();
afterAllTabsLoaded(testUndoCloseWithSelectedBlankPinnedTab);
});
});
afterAllTabsLoaded(testUndoCloseWithSelectedBlankPinnedTab, win);
}, 0, win);
}, win);
}
let testUndoCloseWithSelectedBlankPinnedTab = function () {
@ -73,14 +74,8 @@ function test() {
assertNumberOfTabs(2);
afterAllTabsLoaded(function () {
gBrowser.removeTab(gBrowser.tabs[0]);
gBrowser.pinTab(gBrowser.tabs[0]);
registerCleanupFunction(function () {
let tab = gBrowser.tabs[0];
if (tab.pinned)
gBrowser.unpinTab(tab);
});
win.gBrowser.removeTab(win.gBrowser.tabs[0]);
win.gBrowser.pinTab(win.gBrowser.tabs[0]);
assertNumberOfTabs(1);
assertNumberOfPinnedTabs(1);
@ -91,23 +86,24 @@ function test() {
assertGroupItemPreserved();
createBlankTab();
gBrowser.removeTab(gBrowser.tabs[0]);
win.gBrowser.removeTab(win.gBrowser.tabs[0]);
afterAllTabsLoaded(finishTest);
});
});
afterAllTabsLoaded(finishTest, win);
}, 0, win);
}, win);
}
waitForExplicitFinish();
registerCleanupFunction(function () TabView.hide());
showTabView(function () {
newWindowWithTabView(window => {
win = window;
hideTabView(function () {
cw = TabView.getContentWindow();
cw = win.TabView.getContentWindow();
groupItemId = cw.GroupItems.groupItems[0].id;
assertValidPrerequisites();
testUndoCloseWithSelectedBlankTab();
});
}, win);
});
}

View File

@ -18,18 +18,18 @@ let activeGroup;
function test() {
waitForExplicitFinish();
showTabView(function () {
contentWindow = TabView.getContentWindow();
newWindowWithTabView(win => {
contentWindow = win.TabView.getContentWindow();
activeGroup = contentWindow.GroupItems.getActiveGroupItem();
gBrowser.browsers[0].loadURI("data:text/html,<p>test for bug 626455, tab1");
win.gBrowser.browsers[0].loadURI("data:text/html,<p>test for bug 626455, tab1");
let tab = gBrowser.addTab(TEST_URL);
afterAllTabsLoaded(() => testStayOnPage(tab));
let tab = win.gBrowser.addTab(TEST_URL);
afterAllTabsLoaded(() => testStayOnPage(win, tab));
});
}
function testStayOnPage(blockingTab) {
function testStayOnPage(win, blockingTab) {
let browser = blockingTab.linkedBrowser;
waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) {
// stay on page
@ -37,12 +37,12 @@ function testStayOnPage(blockingTab) {
executeSoon(function () {
showTabView(function () {
is(gBrowser.tabs.length, 1,
is(win.gBrowser.tabs.length, 1,
"The total number of tab is 1 when staying on the page");
// The other initial tab has been closed when trying to close the tab
// group. The only tab left is the one with the onbeforeunload dialog.
let url = gBrowser.browsers[0].currentURI.spec;
let url = win.gBrowser.browsers[0].currentURI.spec;
ok(url.contains("onbeforeunload"), "The open tab is the expected one");
is(contentWindow.GroupItems.getActiveGroupItem(), activeGroup,
@ -52,32 +52,32 @@ function testStayOnPage(blockingTab) {
"Only one group is open");
// start the next test
testLeavePage(gBrowser.tabs[0]);
});
testLeavePage(win, win.gBrowser.tabs[0]);
}, win);
});
});
closeGroupItem(activeGroup);
}
function testLeavePage(blockingTab) {
function testLeavePage(win, blockingTab) {
let browser = blockingTab.linkedBrowser;
waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) {
// Leave page
btnLeave.click();
});
whenGroupClosed(activeGroup, finishTest);
whenGroupClosed(activeGroup, () => finishTest(win));
closeGroupItem(activeGroup);
}
function finishTest() {
is(gBrowser.tabs.length, 1,
function finishTest(win) {
is(win.gBrowser.tabs.length, 1,
"The total number of tab is 1 after leaving the page");
is(contentWindow.TabItems.getItems().length, 1,
"The total number of tab items is 1 after leaving the page");
let location = gBrowser.browsers[0].currentURI.spec;
let location = win.gBrowser.browsers[0].currentURI.spec;
is(location, BROWSER_NEW_TAB_URL, "The open tab is the expected one");
isnot(contentWindow.GroupItems.getActiveGroupItem(), activeGroup,
@ -88,7 +88,7 @@ function finishTest() {
contentWindow = null;
activeGroup = null;
finish();
promiseWindowClosed(win).then(finish);
}
// ----------

View File

@ -4,10 +4,10 @@
function test() {
waitForExplicitFinish();
showTabView(function () {
is(gBrowser.tabs.length, 1, "There is only one tab");
newWindowWithTabView(win => {
is(win.gBrowser.tabs.length, 1, "There is only one tab");
let tab = gBrowser.tabs[0];
let tab = win.gBrowser.tabs[0];
let tabItem = tab._tabViewTabItem;
ok(tabItem.parent, "The tab item belongs to a group");
let groupId = tabItem.parent.id;
@ -16,16 +16,16 @@ function test() {
whenTabViewIsHidden(function() {
// a new tab with group should be opened
is(gBrowser.tabs.length, 1, "There is still one tab");
isnot(gBrowser.selectedTab, tab, "The tab is different");
is(win.gBrowser.tabs.length, 1, "There is still one tab");
isnot(win.gBrowser.selectedTab, tab, "The tab is different");
tab = gBrowser.tabs[0];
tab = win.gBrowser.tabs[0];
tabItem = tab._tabViewTabItem;
ok(tabItem.parent, "This new tab item belongs to a group");
is(tabItem.parent.id, groupId, "The group is different");
finish();
});
promiseWindowClosed(win).then(finish);
}, win);
});
}

View File

@ -4,44 +4,38 @@
function test() {
waitForExplicitFinish();
gBrowser.addTab("http://example.com/");
gBrowser.addTab("http://example.com/");
newWindowWithTabView(win => {
win.gBrowser.addTab("http://example.com/");
win.gBrowser.addTab("http://example.com/");
registerCleanupFunction(function () {
while (gBrowser.tabs.length > 1)
gBrowser.removeTab(gBrowser.tabs[1]);
hideTabView();
})
afterAllTabsLoaded(function() {
showTabView(function() {
let cw = TabView.getContentWindow();
afterAllTabsLoaded(function() {
let cw = win.TabView.getContentWindow();
let groupItemOne = cw.GroupItems.groupItems[0];
is(groupItemOne.getChildren().length, 3, "The number of tabs in group one is 3");
// create a group with a blank tab
let groupItemTwo = createGroupItemWithBlankTabs(window, 400, 400, 40, 1);
let groupItemTwo = createGroupItemWithBlankTabs(win, 400, 400, 40, 1);
is(groupItemTwo.getChildren().length, 1, "The number of tabs in group two is 1");
cw.UI.setActive(groupItemOne);
moveTabToAnotherGroup(groupItemOne.getChild(2).tab, groupItemOne, groupItemTwo, function() {
moveTabToAnotherGroup(groupItemOne.getChild(1).tab, groupItemOne, groupItemTwo, function() {
moveTabToAnotherGroup(win, groupItemOne.getChild(2).tab, groupItemOne, groupItemTwo, function() {
moveTabToAnotherGroup(win, groupItemOne.getChild(1).tab, groupItemOne, groupItemTwo, function() {
groupItemOne.close();
hideTabView(finish);
promiseWindowClosed(win).then(finish);
});
});
});
});
}
function moveTabToAnotherGroup(targetTab, groupItemOne, groupItemTwo, callback) {
function moveTabToAnotherGroup(win, targetTab, groupItemOne, groupItemTwo, callback) {
hideTabView(function() {
let tabCountInGroupItemOne = groupItemOne.getChildren().length;
let tabCountInGroupItemTwo = groupItemTwo.getChildren().length;
TabView.moveTabTo(targetTab, groupItemTwo.id);
win.TabView.moveTabTo(targetTab, groupItemTwo.id);
showTabView(function() {
is(groupItemOne.getChildren().length, --tabCountInGroupItemOne, "The number of tab items in group one is decreased");
@ -49,6 +43,6 @@ function moveTabToAnotherGroup(targetTab, groupItemOne, groupItemTwo, callback)
is(groupItemTwo.getChild(tabCountInGroupItemTwo-1).tab, targetTab, "The last tab is the moved tab");
callback();
});
});
}, win);
}, win);
}