Bug 685692 - "Move to Group" should always insert the moved tab into the same place r=dietrich
authorRaymond Lee <raymond@raysquare.com>
Tue, 20 Sep 2011 18:00:02 +0800
changeset 77673 a9edf67c89547f37836e69ea744e87ab6708c3e2
parent 77672 ee20c375e6e63e7467f54c4fa766b47437b8b294
child 77674 12daae1947d755f438a9ea060832fe888a907005
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersdietrich
bugs685692
milestone9.0a1
Bug 685692 - "Move to Group" should always insert the moved tab into the same place r=dietrich
browser/base/content/tabview/groupitems.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug685692.js
--- a/browser/base/content/tabview/groupitems.js
+++ b/browser/base/content/tabview/groupitems.js
@@ -2599,17 +2599,17 @@ let GroupItems = {
     // remove tab item from a groupItem
     if (tab._tabViewTabItem.parent)
       tab._tabViewTabItem.parent.remove(tab._tabViewTabItem);
 
     // add tab item to a groupItem
     if (groupItemId) {
       groupItem = GroupItems.groupItem(groupItemId);
       groupItem.add(tab._tabViewTabItem);
-      UI.setReorderTabItemsOnShow(groupItem);
+      groupItem.reorderTabsBasedOnTabItemOrder()
     } else {
       let pageBounds = Items.getPageBounds();
       pageBounds.inset(20, 20);
 
       let box = new Rect(pageBounds);
       box.width = 250;
       box.height = 200;
 
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -153,16 +153,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug663421.js \
                  browser_tabview_bug665502.js \
                  browser_tabview_bug669694.js \
                  browser_tabview_bug673196.js \
                  browser_tabview_bug673729.js \
                  browser_tabview_bug677310.js \
                  browser_tabview_bug679853.js \
                  browser_tabview_bug681599.js \
+                 browser_tabview_bug685692.js \
                  browser_tabview_bug686654.js \
                  browser_tabview_click_group.js \
                  browser_tabview_dragdrop.js \
                  browser_tabview_exit_button.js \
                  browser_tabview_expander.js \
                  browser_tabview_firstrun_pref.js \
                  browser_tabview_group.js \
                  browser_tabview_launch.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug685692.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  waitForExplicitFinish();
+
+  gBrowser.addTab("http://example.com/");
+  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();
+
+      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);
+      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() {
+          cw.UI.setActive(groupItemOne);
+          hideTabView(finish);
+        });
+      });
+    });
+  });
+}
+
+function moveTabToAnotherGroup(targetTab, groupItemOne, groupItemTwo, callback) {
+  hideTabView(function() {
+    let tabCountInGroupItemOne = groupItemOne.getChildren().length;
+    let tabCountInGroupItemTwo = groupItemTwo.getChildren().length;
+
+    TabView.moveTabTo(targetTab, groupItemTwo.id);
+
+    showTabView(function() {
+      is(groupItemOne.getChildren().length, --tabCountInGroupItemOne, "The number of tab items in group one is decreased");
+      is(groupItemTwo.getChildren().length, ++tabCountInGroupItemTwo, "The number of tab items in group two is increased");
+      is(groupItemTwo.getChild(tabCountInGroupItemTwo-1).tab, targetTab, "The last tab is the moved tab");
+
+      callback();
+    });
+  });
+}