Bug 663421 - Don't close empty groups automatically; f=raymond, r=dietrich

This commit is contained in:
Tim Taubert
2011-06-17 14:07:59 +02:00
parent 70a2c50a2c
commit 409142d6c7
25 changed files with 117 additions and 214 deletions

View File

@@ -130,4 +130,7 @@ function test() {
is(gBrowser.tabs.length, 1, "sanity check that it matches");
is(gBrowser.selectedTab, origTab, "got the orig tab");
is(origTab.hidden, false, "and it's not hidden -- visible!");
if (tabViewWindow)
tabViewWindow.GroupItems.groupItems[0].close();
}

View File

@@ -72,8 +72,6 @@ function testGroupSwitch(contentWindow, groupItemOne, groupItemTwo) {
"The currently selected tab should be the second tab in the groupItemOne");
// cleanup.
gBrowser.removeTab(groupItemTwo.getChild(0).tab);
gBrowser.removeTab(newTabOne);
finish();
closeGroupItem(groupItemTwo, finish);
}

View File

@@ -58,15 +58,17 @@ function onTabViewWindowLoaded() {
gBrowser.unpinTab(appXulTab);
gBrowser.removeTab(appXulTab);
ok(groupItem.closeIfEmpty(), "the second group was empty");
ok(!groupItem.getChildren().length, "the second group is empty");
// Verify ending state
is(gBrowser.tabs.length, 1, "we finish with one tab");
is(contentWindow.GroupItems.groupItems.length, 1,
"we finish with one group");
ok(!TabView.isVisible(), "we finish with Tab View hidden");
finish();
closeGroupItem(groupItem, function () {
// Verify ending state
is(gBrowser.tabs.length, 1, "we finish with one tab");
is(contentWindow.GroupItems.groupItems.length, 1,
"we finish with one group");
ok(!TabView.isVisible(), "we finish with Tab View hidden");
finish();
});
}
window.addEventListener("tabviewhidden", onTabViewHidden, false);

View File

@@ -28,12 +28,15 @@ function test() {
EventUtils.synthesizeMouseAtCenter(targetTab, {type: 'mousemove'}, cw);
EventUtils.synthesizeMouseAtCenter(targetTab, {type: 'mouseup'}, cw);
is(cw.GroupItems.groupItems.length, 2, 'there are two groupItems');
is(sourceGroup.getChildren().length, 0, 'source group has no tabs');
is(targetGroup.getChildren().length, 2, 'target group has two tabs');
is(cw.GroupItems.groupItems.length, 1, 'sourceGroup was closed');
isnot(cw.GroupItems.groupItems[0], sourceGroup, 'sourceGroup was closed');
targetGroup.getChild(0).close();
hideTabView(finish);
closeGroupItem(sourceGroup, function () {
hideTabView(finish);
});
}
waitForExplicitFinish();

View File

@@ -22,11 +22,13 @@ function test() {
"Tab width is bigger than tab clip width");
is(gBrowser.tabContainer.getAttribute("closebuttons"), "alltabs", "Show button on all tabs.")
let cw = TabView.getContentWindow();
let groupItems = cw.GroupItems.groupItems;
is(groupItems.length, 2, "there are two groupItems");
// clean up and finish
newTabs.forEach(function(tab) {
gBrowser.removeTab(tab);
});
finish();
newTabs.forEach(function (tab) gBrowser.removeTab(tab));
closeGroupItem(groupItems[1], finish);
});
});
}

View File

@@ -14,11 +14,11 @@ function test() {
// make sure the tab one is selected because undoCloseTab() would remove
// the selected tab if it's a blank tab.
gBrowser.selectedTab = tabOne;
showTabView(onTabViewWindowLoaded);
showTabView(onTabViewShown);
});
}
function onTabViewWindowLoaded() {
function onTabViewShown() {
let contentWindow = TabView.getContentWindow();
let groupItems = contentWindow.GroupItems.groupItems;
is(groupItems.length, 1, "There is only one group");
@@ -28,8 +28,7 @@ function onTabViewWindowLoaded() {
ok(TabView.isVisible(), "Tab View is still visible after removing a tab");
is(groupItems[0].getChildren().length, 2, "The group has two tab items");
tabTwo = undoCloseTab(0);
whenTabIsReconnected(tabTwo, function() {
restoreTab(function (tabTwo) {
ok(TabView.isVisible(), "Tab View is still visible after restoring a tab");
is(groupItems[0].getChildren().length, 3, "The group still has three tab items");
@@ -41,18 +40,3 @@ function onTabViewWindowLoaded() {
});
});
}
// ----------
function whenTabIsReconnected(tab, callback) {
let tabItem = tab._tabViewTabItem;
if (tabItem._reconnected) {
callback();
return;
}
tabItem.addSubscriber(tabItem, "reconnected", function () {
tabItem.removeSubscriber(tabItem, "reconnected");
callback();
});
}

View File

@@ -25,12 +25,11 @@ function test() {
is(gBrowser.visibleTabs.length, 1, "The number of visible tabs is 1");
is(gBrowser.visibleTabs[0], origTab,
"The original tab is the only visible tab");
isnot(newTab._tabViewTabItem.parent.id, newTabGroupItemId,
let groupItem = newTab._tabViewTabItem.parent;
isnot(groupItem.id, newTabGroupItemId,
"The moved tab item has a new group id");
// clean up
gBrowser.removeTab(newTab);
finish();
closeGroupItem(groupItem, finish);
});
}

View File

@@ -36,12 +36,14 @@ function test() {
// check state after adding tabItem to targetGroup
is(tabItem.parent, targetGroup, 'tabItem changed groups');
is(cw.GroupItems.groupItems.length, 1, 'source group was closed automatically');
is(sourceGroup.getChildren().length, 0, 'source group has no children');
is(targetGroup.getChildren().length, 2, 'target group has now two children');
// cleanup and finish
tabItem.close();
hideTabView(finishTest);
closeGroupItem(sourceGroup, function () {
tabItem.close();
hideTabView(finishTest);
});
});
}

View File

@@ -35,10 +35,7 @@ function test() {
is(win.gBrowser.visibleTabs.length, 1, "There is one tab displayed");
is(cw.GroupItems.groupItems.length, 2, "There are two groups still");
showTabView(function () {
is(cw.GroupItems.groupItems.length, 1, "There is now only one group");
waitForFocus(finish);
}, win);
waitForFocus(finish);
});
};

View File

@@ -20,23 +20,6 @@ function test() {
return groupItem;
}
let hideGroupItem = function (groupItem, callback) {
groupItem.addSubscriber(groupItem, 'groupHidden', function () {
groupItem.removeSubscriber(groupItem, 'groupHidden');
callback();
});
groupItem.closeAll();
}
let closeGroupItem = function (groupItem, callback) {
afterAllTabsLoaded(function () {
hideGroupItem(groupItem, function () {
groupItem.closeHidden();
callback();
});
});
}
let tests = [];
let next = function () {
@@ -214,10 +197,13 @@ function test() {
let tabItem = groupItem.getChild(0);
groupItem.remove(tabItem);
hideTabView(function () {
closeGroupItem(groupItem, function () {
assertNumberOfGroupItems(0);
createGroupItem().add(tabItem);
next();
hideTabView(function () {
createGroupItem().add(tabItem);
next();
});
});
}
@@ -229,14 +215,17 @@ function test() {
let tabItem = groupItem.getChild(0);
groupItem.remove(tabItem);
assertNumberOfGroupItems(0);
let newGroupItem = createGroupItem(1);
assertNumberOfGroupItems(1);
closeGroupItem(newGroupItem, function () {
closeGroupItem(groupItem, function () {
assertNumberOfGroupItems(0);
createGroupItem().add(tabItem);
hideTabView(next);
let newGroupItem = createGroupItem(1);
assertNumberOfGroupItems(1);
closeGroupItem(newGroupItem, function () {
assertNumberOfGroupItems(0);
createGroupItem().add(tabItem);
hideTabView(next);
});
});
}
@@ -248,15 +237,18 @@ function test() {
let tabItem = groupItem.getChild(0);
groupItem.remove(tabItem);
assertNumberOfGroupItems(0);
let newGroupItem = createGroupItem(1);
assertNumberOfGroupItems(1);
closeGroupItem(groupItem, function () {
assertNumberOfGroupItems(0);
hideGroupItem(newGroupItem, function () {
hideTabView(function () {
assertNumberOfGroupItems(0);
createGroupItem().add(tabItem);
next();
let newGroupItem = createGroupItem(1);
assertNumberOfGroupItems(1);
hideGroupItem(newGroupItem, function () {
hideTabView(function () {
assertNumberOfGroupItems(0);
createGroupItem().add(tabItem);
next();
});
});
});
}

View File

@@ -39,10 +39,6 @@ function test() {
tests.push([tab2, tab1]);
tests.push([tab1]);
// test reordering of empty groups - removes the last tab and causes
// the groupItem to close
tests.push([]);
while (tests.length) {
let test = tests.shift();
@@ -63,7 +59,7 @@ function test() {
groupItem.reorderTabsBasedOnTabItemOrder();
}
testMoveBetweenGroups();
closeGroupItem(groupItem, testMoveBetweenGroups);
}
let testMoveBetweenGroups = function () {

View File

@@ -119,7 +119,8 @@ function test() {
enterAndLeavePrivateBrowsing(function () {
assertNumberOfVisibleTabs(2);
next();
gBrowser.selectedTab = gBrowser.tabs[0];
closeGroupItem(cw.GroupItems.groupItems[1], next);
});
});
}

View File

@@ -41,20 +41,6 @@ function test() {
return createTab('about:blank');
}
let restoreTab = function (callback) {
let tab = undoCloseTab(0);
if (tab._tabViewTabItem._reconnected) {
afterAllTabsLoaded(callback);
return;
}
tab._tabViewTabItem.addSubscriber(tab, 'reconnected', function () {
tab._tabViewTabItem.removeSubscriber(tab, 'reconnected');
afterAllTabsLoaded(callback);
});
}
let finishTest = function () {
prefix = 'finish';
assertValidPrerequisites();

View File

@@ -33,13 +33,10 @@ function test() {
ok(!document.getElementById("context_closeTab").disabled, "The 'Close tab' menu item is enabled");
ok(!document.getElementById("context_openTabInWindow").disabled, "The 'Move to New Window' menu item is enabled");
let newTabTwo = gBrowser.selectedTab;
gBrowser.selected = originalTab;
gBrowser.removeTab(newTabOne);
gBrowser.removeTab(newTabTwo);
finish();
closeGroupItem(newGroup, finish);
});
let newGroup = contentWindow.GroupItems.newGroup();
newGroup.newTab();

View File

@@ -39,7 +39,9 @@ function test() {
synthesizeMiddleMouseDrag(tabContainer, 10);
ok(!groupItem.getChild(0), 'tabItem was closed');
hideTabView(finish);
closeGroupItem(groupItem, function () {
hideTabView(finish);
});
}
waitForExplicitFinish();

View File

@@ -25,21 +25,26 @@ function onTabViewWindowLoaded(win) {
is(group.getChildren().length, 1, "The group has one child now.");
let tab = group.getChild(0);
function check() {
if (groupOrTab == 'group') {
group.removeSubscriber(group, "groupHidden", check);
group.closeHidden();
} else
tab.removeSubscriber(tab, "tabRemoved", check);
function finalize() {
is(contentWindow.GroupItems.getActiveGroupItem(), originalGroup,
"The original group is active.");
is(contentWindow.UI.getActiveTab(), originalTab._tabViewTabItem,
"The original tab is active");
callback();
}
function check() {
if (groupOrTab == 'group') {
group.removeSubscriber(group, "groupHidden", check);
group.closeHidden();
finalize();
} else {
tab.removeSubscriber(tab, "tabRemoved", check);
closeGroupItem(group, finalize);
}
}
if (groupOrTab == 'group') {
group.addSubscriber(group, "groupHidden", check);
@@ -58,4 +63,4 @@ function onTabViewWindowLoaded(win) {
finish();
});
});
}
}

View File

@@ -25,20 +25,6 @@ function test() {
return cw.GroupItems.groupItems[index];
}
let restoreTab = function (callback) {
let tab = undoCloseTab(0);
if (tab._tabViewTabItem._reconnected) {
callback();
return;
}
tab._tabViewTabItem.addSubscriber(tab, 'reconnected', function () {
tab._tabViewTabItem.removeSubscriber(tab, 'reconnected');
afterAllTabsLoaded(callback);
});
}
let activateFirstGroupItem = function () {
let activeTabItem = getGroupItem(0).getChild(0);
cw.GroupItems.updateActiveGroupItemAndTabBar(activeTabItem);
@@ -91,9 +77,7 @@ function test() {
assertNumberOfTabsInGroup(groupItem, 2);
activateFirstGroupItem();
gBrowser.removeTab(gBrowser.tabs[1]);
gBrowser.removeTab(gBrowser.tabs[1]);
finishTest();
closeGroupItem(groupItem, finishTest);
});
}

View File

@@ -85,7 +85,7 @@ function addTest(contentWindow, groupOneId, groupTwoId, originalTab) {
};
groupTwo.addSubscriber(groupTwo, "close", function() {
groupTwo.removeSubscriber(groupTwo, "close");
finish();
closeGroupItem(groupOne, finish);
});
window.addEventListener("tabviewhidden", onTabViewHidden, false);
gBrowser.selectedTab = originalTab;

View File

@@ -95,7 +95,7 @@ function testGroupItemWithTabItem(contentWindow) {
let endGame = function() {
window.removeEventListener("tabviewhidden", endGame, false);
ok(!TabView.isVisible(), "Tab View is hidden");
finish();
closeGroupItem(groupItem, finish);
};
window.addEventListener("tabviewhidden", endGame, false);

View File

@@ -45,14 +45,19 @@ function createGroupItemWithBlankTabs(win, width, height, padding, numNewTabs, a
// ----------
function closeGroupItem(groupItem, callback) {
groupItem.addSubscriber(groupItem, "groupHidden", function() {
groupItem.removeSubscriber(groupItem, "groupHidden");
groupItem.addSubscriber(groupItem, "close", function() {
groupItem.removeSubscriber(groupItem, "close");
callback();
});
groupItem.closeHidden();
groupItem.addSubscriber(groupItem, "close", function () {
groupItem.removeSubscriber(groupItem, "close");
if ("function" == typeof callback)
executeSoon(callback);
});
if (groupItem.getChildren().length) {
groupItem.addSubscriber(groupItem, "groupHidden", function () {
groupItem.removeSubscriber(groupItem, "groupHidden");
groupItem.closeHidden();
});
}
groupItem.closeAll();
}
@@ -312,13 +317,17 @@ function restoreTab(callback, index, win) {
let tab = win.undoCloseTab(index || 0);
let tabItem = tab._tabViewTabItem;
let finalize = function () {
afterAllTabsLoaded(function () callback(tab), win);
};
if (tabItem._reconnected) {
afterAllTabsLoaded(callback, win);
finalize();
return;
}
tab._tabViewTabItem.addSubscriber(tab, "reconnected", function onReconnected() {
tab._tabViewTabItem.removeSubscriber(tab, "reconnected");
afterAllTabsLoaded(callback, win);
finalize();
});
}