Commit dad62746 authored by Charlene Yan's avatar Charlene Yan Committed by Commit Bot

[Tab Groups] Update tab groups when inserting tab into new window.

Bug: 915956
Change-Id: I46d68323a447a972006f165d20d84c73d9ed31e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846097
Commit-Queue: Charlene Yan <cyan@chromium.org>
Reviewed-by: default avatarTaylor Bergquist <tbergquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704379}
parent 900c4c5e
...@@ -1249,6 +1249,8 @@ void TabDragController::Attach(TabDragContext* attached_context, ...@@ -1249,6 +1249,8 @@ void TabDragController::Attach(TabDragContext* attached_context,
attached_context_tabs_closed_tracker_ = attached_context_tabs_closed_tracker_ =
std::make_unique<DraggedTabsClosedTracker>( std::make_unique<DraggedTabsClosedTracker>(
attached_context_->GetTabStripModel(), this); attached_context_->GetTabStripModel(), this);
if (attach_index_ != -1)
UpdateGroupForDraggedTabs();
} }
void TabDragController::Detach(ReleaseCapture release_capture) { void TabDragController::Detach(ReleaseCapture release_capture) {
...@@ -2138,7 +2140,7 @@ base::Optional<TabGroupId> TabDragController::GetTabGroupForTargetIndex( ...@@ -2138,7 +2140,7 @@ base::Optional<TabGroupId> TabDragController::GetTabGroupForTargetIndex(
// ungrouped. // ungrouped.
const Tab* left_most_selected_tab = const Tab* left_most_selected_tab =
source_context_->GetTabAt(selected.front()); attached_context_->GetTabAt(selected.front());
const int buffer = left_most_selected_tab->width() / 4; const int buffer = left_most_selected_tab->width() / 4;
...@@ -2152,7 +2154,7 @@ base::Optional<TabGroupId> TabDragController::GetTabGroupForTargetIndex( ...@@ -2152,7 +2154,7 @@ base::Optional<TabGroupId> TabDragController::GetTabGroupForTargetIndex(
// tab or there is a group header to the immediate left. // tab or there is a group header to the immediate left.
int left_edge = int left_edge =
attached_model->ContainsIndex(left_tab_index) attached_model->ContainsIndex(left_tab_index)
? source_context_->GetTabAt(left_tab_index)->bounds().right() - ? attached_context_->GetTabAt(left_tab_index)->bounds().right() -
tab_left_inset tab_left_inset
: tab_left_inset; : tab_left_inset;
......
...@@ -1843,6 +1843,50 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, ...@@ -1843,6 +1843,50 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
EXPECT_FALSE(browser2->window()->IsMaximized()); EXPECT_FALSE(browser2->window()->IsMaximized());
} }
// Creates two browser with two tabs each. The first browser has one tab in a
// group and the second tab not in a group. The second browser {browser2} has
// two tabs in another group {group1}. Dragging the two tabs in the first
// browser into the middle of the second browser will insert the two dragged
// tabs into the {group1}} after the first tab.
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
DragWindowIntoGroup) {
scoped_feature_list_.InitAndEnableFeature(features::kTabGroups);
TabStrip* tab_strip = GetTabStripForBrowser(browser());
TabStripModel* model = browser()->tab_strip_model();
AddTabsAndResetBrowser(browser(), 1);
model->AddToNewGroup({0});
StopAnimating(tab_strip);
// Set up the second browser with two tabs in a group with distinct IDs.
Browser* browser2 = CreateAnotherBrowserAndResize();
TabStrip* tab_strip2 = GetTabStripForBrowser(browser2);
TabStripModel* model2 = browser2->tab_strip_model();
AddTabsAndResetBrowser(browser2, 1);
ResetIDs(model2, 100);
TabGroupId group1 = model2->AddToNewGroup({0, 1});
StopAnimating(tab_strip2);
// Click the first tab and select the second tab so they are the only ones
// selected.
ASSERT_TRUE(PressInput(GetCenterInScreenCoordinates(tab_strip->tab_at(0))));
ASSERT_TRUE(ReleaseInput());
browser()->tab_strip_model()->ToggleSelectionAt(1);
// Move to the first tab and drag it enough so that it detaches, but not
// enough that it attaches to browser2.
DragTabAndNotify(tab_strip, base::BindOnce(&DragAllToSeparateWindowStep2,
this, tab_strip, tab_strip2));
// Release the mouse, stopping the drag session.
ASSERT_TRUE(ReleaseInput());
EXPECT_EQ("100 0 1 101", IDString(model2));
EXPECT_THAT(model2->ListTabsInGroup(group1),
testing::ElementsAre(0, 1, 2, 3));
}
namespace { namespace {
// Invoked from the nested run loop. // Invoked from the nested run loop.
......
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