Commit 3f161ac2 authored by Charlene Yan's avatar Charlene Yan Committed by Commit Bot

[Tab Groups] Check tab group of opener when adding a new tab.

When adding a new tab, look at the current active tab to
determine the group the new tab should belong in.

Bug: 1061004
Change-Id: I45905ccb9d57c5293059c9dc10ae7ad539c9fcb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2107421
Commit-Queue: Charlene Yan <cyan@chromium.org>
Reviewed-by: default avatarConnie Wan <connily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751216}
parent 2a343d6b
...@@ -935,6 +935,11 @@ void TabStripModel::AddWebContents( ...@@ -935,6 +935,11 @@ void TabStripModel::AddWebContents(
index = order_controller_->DetermineInsertionIndex(transition, index = order_controller_->DetermineInsertionIndex(transition,
add_types & ADD_ACTIVE); add_types & ADD_ACTIVE);
inherit_opener = true; inherit_opener = true;
// The current active index is our opener. If the tab we are adding is not
// in a group, set the group of the tab to that of its opener.
if (!group.has_value())
group = GetTabGroupForTab(active_index());
} else { } else {
// For all other types, respect what was passed to us, normalizing -1s and // For all other types, respect what was passed to us, normalizing -1s and
// values that are too large. // values that are too large.
......
...@@ -1712,6 +1712,33 @@ TEST_F(TabStripModelTest, AddWebContents_ForgetOpeners) { ...@@ -1712,6 +1712,33 @@ TEST_F(TabStripModelTest, AddWebContents_ForgetOpeners) {
EXPECT_TRUE(tabstrip.empty()); EXPECT_TRUE(tabstrip.empty());
} }
// Tests whether or not a WebContents in a new tab belongs in the same tab
// group as its opener.
TEST_F(TabStripModelTest, AddWebContents_LinkOpensInSameGroupAsOpener) {
TestTabStripModelDelegate delegate;
TabStripModel tabstrip(&delegate, profile());
ASSERT_TRUE(tabstrip.empty());
// Open the home page and add the tab to a group.
std::unique_ptr<WebContents> homepage_contents = CreateWebContents();
tabstrip.AddWebContents(std::move(homepage_contents), -1,
ui::PAGE_TRANSITION_AUTO_BOOKMARK,
TabStripModel::ADD_ACTIVE);
ASSERT_EQ(1, tabstrip.count());
tab_groups::TabGroupId group_id = tabstrip.AddToNewGroup({0});
ASSERT_EQ(tabstrip.GetTabGroupForTab(0), group_id);
// Open a tab by simulating a link that opens in a new tab.
std::unique_ptr<WebContents> contents = CreateWebContents();
tabstrip.AddWebContents(std::move(contents), -1, ui::PAGE_TRANSITION_LINK,
TabStripModel::ADD_ACTIVE);
EXPECT_EQ(2, tabstrip.count());
EXPECT_EQ(tabstrip.GetTabGroupForTab(1), group_id);
tabstrip.CloseAllTabs();
ASSERT_TRUE(tabstrip.empty());
}
// Added for http://b/issue?id=958960 // Added for http://b/issue?id=958960
TEST_F(TabStripModelTest, AppendContentsReselectionTest) { TEST_F(TabStripModelTest, AppendContentsReselectionTest) {
TestTabStripModelDelegate delegate; TestTabStripModelDelegate delegate;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment