Bug 608405 - GroupItem.add should auto remove from previous group [r=ian, a=sdwilsh]
authorTim Taubert <tim.taubert@gmx.de>
Thu, 03 Feb 2011 02:16:21 +0100
changeset 61859 fd7962a458688e92cc5edd857d30da928438ad03
parent 61858 54da8f75df7f9d2a91d9a16019c850f25994c6a3
child 61860 be4f8b47377e4c75398fdf56507469a9c163f967
push idunknown
push userunknown
push dateunknown
reviewersian, sdwilsh
bugs608405
milestone2.0b12pre
Bug 608405 - GroupItem.add should auto remove from previous group [r=ian, a=sdwilsh]
browser/base/content/tabview/groupitems.js
browser/base/content/test/tabview/Makefile.in
browser/base/content/test/tabview/browser_tabview_bug608405.js
--- a/browser/base/content/tabview/groupitems.js
+++ b/browser/base/content/tabview/groupitems.js
@@ -853,18 +853,20 @@ GroupItem.prototype = Utils.extend(new I
       var $el;
       if (a.isAnItem) {
         item = a;
         $el = iQ(a.container);
       } else {
         $el = iQ(a);
         item = Items.item($el);
       }
-      Utils.assertThrow(!item.parent || item.parent == this,
-          "shouldn't already be in another groupItem");
+
+      // safeguard to remove the item from its previous group
+      if (item.parent && item.parent !== this)
+        item.parent.remove(item);
 
       item.removeTrenches();
 
       if (!options)
         options = {};
 
       var self = this;
 
@@ -1536,22 +1538,16 @@ GroupItem.prototype = Utils.extend(new I
         // If we drop this item before the timed rearrange was executed,
         // we won't have an accurate dropIndex value. Get that now.
         let dropPos = drag.info.item.getBounds().center();
         dropIndex = self.arrange({dropPos: dropPos,
                                   addTab: drag.info.item.parent != self,
                                   animate: true});
       }
 
-      // remove the item from its parent if that's not the current groupItem.
-      // this may occur when dragging too quickly so the out event is not fired.
-      var groupItem = drag.info.item.parent;
-      if (groupItem && self !== groupItem)
-        groupItem.remove(drag.info.$el, {dontClose: true});
-
       if (dropIndex !== false)
         options = {index: dropIndex};
       this.add(drag.info.$el, options);
       GroupItems.setActiveGroupItem(this);
       dropIndex = false;
     };
     this.dropOptions.out = function GroupItem_dropOptions_out(event) {
       dropIndex = false;
--- a/browser/base/content/test/tabview/Makefile.in
+++ b/browser/base/content/test/tabview/Makefile.in
@@ -75,16 +75,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_tabview_bug600645.js \
                  browser_tabview_bug600812.js \
                  browser_tabview_bug604098.js \
                  browser_tabview_bug606657.js \
                  browser_tabview_bug606905.js \
                  browser_tabview_bug608037.js \
                  browser_tabview_bug608184.js \
                  browser_tabview_bug608158.js \
+                 browser_tabview_bug608405.js \
                  browser_tabview_bug610242.js \
                  browser_tabview_bug612470.js \
                  browser_tabview_bug613541.js \
                  browser_tabview_bug616729.js \
                  browser_tabview_bug616967.js \
                  browser_tabview_bug618828.js \
                  browser_tabview_bug619937.js \
                  browser_tabview_bug622835.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabview/browser_tabview_bug608405.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  let cw;
+
+  let createGroupItem = function () {
+    let bounds = new cw.Rect(20, 20, 200, 200);
+    let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true});
+
+    cw.GroupItems.setActiveGroupItem(groupItem);
+    gBrowser.loadOneTab('about:blank', {inBackground: true});
+
+    return groupItem;
+  }
+
+  let finishTest = function () {
+    ok(!TabView.isVisible(), 'cleanup: tabview is hidden');
+    is(gBrowser.tabs.length, 1, 'cleanup: there is one tab, only');
+    is(cw.GroupItems.groupItems.length, 1, 'cleanup: there is one group, only');
+
+    finish();
+  }
+
+  let testAddChildFromAnotherGroup = function () {
+    let sourceGroup = cw.GroupItems.groupItems[0];
+    let targetGroup = createGroupItem();
+
+    afterAllTabsLoaded(function () {
+      // check setup
+      is(sourceGroup.getChildren().length, 1, 'setup: source group has one child');
+      is(targetGroup.getChildren().length, 1, 'setup: target group has one child');
+
+      let tabItem = sourceGroup.getChild(0);
+      targetGroup.add(tabItem);
+
+      // 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(targetGroup.getChildren().length, 2, 'target group has now two children');
+
+      // cleanup and finish
+      tabItem.close();
+      hideTabView(finishTest);
+    });
+  }
+
+  waitForExplicitFinish();
+
+  showTabView(function () {
+    cw = TabView.getContentWindow();
+    testAddChildFromAnotherGroup();
+  });
+}