Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7162)

Unified Diff: chrome/browser/ui/tabs/tab_strip_model_unittest.cc

Issue 836223004: Fix tab insertion position after moving tab or nesting openers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/tabs/tab_strip_model_unittest.cc
diff --git a/chrome/browser/ui/tabs/tab_strip_model_unittest.cc b/chrome/browser/ui/tabs/tab_strip_model_unittest.cc
index 5ae32f53348ef9c9c1a43f7a93949a7b9f387051..bd78d5da8f89ad6177664a3215cee0824f3eb0d9 100644
--- a/chrome/browser/ui/tabs/tab_strip_model_unittest.cc
+++ b/chrome/browser/ui/tabs/tab_strip_model_unittest.cc
@@ -863,6 +863,115 @@ TEST_F(TabStripModelTest, TestInsertionIndexDetermination) {
EXPECT_TRUE(tabstrip.empty());
}
+// Tests that non-adjacent tabs with an opener are ignored when deciding where
+// to position tabs.
+TEST_F(TabStripModelTest, TestInsertionIndexDeterminationAfterDragged) {
+ TabStripDummyDelegate delegate;
+ TabStripModel tabstrip(&delegate, profile());
+ EXPECT_TRUE(tabstrip.empty());
+
+ // Start with three tabs, of which the first is active.
+ WebContents* opener1 = CreateWebContentsWithID(1);
+ tabstrip.AppendWebContents(opener1, true /* foreground */);
+ tabstrip.AppendWebContents(CreateWebContentsWithID(2), false);
+ tabstrip.AppendWebContents(CreateWebContentsWithID(3), false);
+ EXPECT_EQ("1 2 3", GetTabStripStateString(tabstrip));
+ EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
+ EXPECT_EQ(-1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
+
+ // Open a link in a new background tab.
+ tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
+ CreateWebContentsWithID(11),
+ TabStripModel::ADD_INHERIT_GROUP);
+ EXPECT_EQ("1 11 2 3", GetTabStripStateString(tabstrip));
+ EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
+ EXPECT_EQ(1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
+
+ // Drag that tab (which activates it) one to the right.
+ tabstrip.MoveWebContentsAt(1, 2, true /* select_after_move */);
+ EXPECT_EQ("1 2 11 3", GetTabStripStateString(tabstrip));
+ EXPECT_EQ(11, GetID(tabstrip.GetActiveWebContents()));
+ // It should no longer be counted by GetIndexOfLastWebContentsOpenedBy,
+ // since there is a tab in between, even though its opener is unchanged.
+ // TODO(johnme): Maybe its opener should be reset when it's dragged away.
+ EXPECT_EQ(-1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
+ EXPECT_EQ(opener1, tabstrip.GetOpenerOfWebContentsAt(2));
+
+ // Activate the parent tab again.
+ tabstrip.ActivateTabAt(0, true /* user_gesture */);
+ EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
+
+ // Open another link in a new background tab.
+ tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
+ CreateWebContentsWithID(12),
+ TabStripModel::ADD_INHERIT_GROUP);
+ // Tab 12 should be next to 1, and considered opened by it.
+ EXPECT_EQ("1 12 2 11 3", GetTabStripStateString(tabstrip));
+ EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
+ EXPECT_EQ(1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
+
+ tabstrip.CloseAllTabs();
+ EXPECT_TRUE(tabstrip.empty());
+}
+
+// Tests that grandchild tabs are considered to be opened by their grandparent
+// tab when deciding where to position tabs.
+TEST_F(TabStripModelTest, TestInsertionIndexDeterminationNestedOpener) {
+ TabStripDummyDelegate delegate;
+ TabStripModel tabstrip(&delegate, profile());
+ EXPECT_TRUE(tabstrip.empty());
+
+ // Start with two tabs, of which the first is active:
+ WebContents* opener1 = CreateWebContentsWithID(1);
+ tabstrip.AppendWebContents(opener1, true /* foreground */);
+ tabstrip.AppendWebContents(CreateWebContentsWithID(2), false);
+ EXPECT_EQ("1 2", GetTabStripStateString(tabstrip));
+ EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
+ EXPECT_EQ(-1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
+
+ // Open a link in a new background child tab.
+ WebContents* child11 = CreateWebContentsWithID(11);
+ tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
+ child11,
+ TabStripModel::ADD_INHERIT_GROUP);
+ EXPECT_EQ("1 11 2", GetTabStripStateString(tabstrip));
+ EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
+ EXPECT_EQ(1, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
+
+ // Activate the child tab:
+ tabstrip.ActivateTabAt(1, true /* user_gesture */);
+ EXPECT_EQ(11, GetID(tabstrip.GetActiveWebContents()));
+
+ // Open a link in a new background grandchild tab.
+ tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
+ CreateWebContentsWithID(111),
+ TabStripModel::ADD_INHERIT_GROUP);
+ EXPECT_EQ("1 11 111 2", GetTabStripStateString(tabstrip));
+ EXPECT_EQ(11, GetID(tabstrip.GetActiveWebContents()));
+ // The grandchild tab should be counted by GetIndexOfLastWebContentsOpenedBy
+ // as opened by both its parent (child11) and grandparent (opener1).
+ EXPECT_EQ(2, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
+ EXPECT_EQ(2, tabstrip.GetIndexOfLastWebContentsOpenedBy(child11, 1));
+
+ // Activate the parent tab again:
+ tabstrip.ActivateTabAt(0, true /* user_gesture */);
+ EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
+
+ // Open another link in a new background child tab (a sibling of child11).
+ tabstrip.InsertWebContentsAt(GetInsertionIndex(&tabstrip),
+ CreateWebContentsWithID(12),
+ TabStripModel::ADD_INHERIT_GROUP);
+ EXPECT_EQ("1 11 111 12 2", GetTabStripStateString(tabstrip));
+ EXPECT_EQ(1, GetID(tabstrip.GetActiveWebContents()));
+ // opener1 has three adjacent descendants (11, 111, 12)
+ EXPECT_EQ(3, tabstrip.GetIndexOfLastWebContentsOpenedBy(opener1, 0));
+ // child11 has only one adjacent descendant (111)
+ EXPECT_EQ(2, tabstrip.GetIndexOfLastWebContentsOpenedBy(child11, 1));
+
+ tabstrip.CloseAllTabs();
+ EXPECT_TRUE(tabstrip.empty());
+}
+
// Tests that selection is shifted to the correct tab when a tab is closed.
// If a tab is in the background when it is closed, the selection does not
// change.
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698