Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI run for contributor PR #25160 #26018

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion browser/ui/views/tabs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ source_set("browser_tests") {
testonly = true
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]

sources = [ "//brave/browser/ui/views/tabs/brave_tab_hover_browsertest.cc" ]
sources = [
"//brave/browser/ui/views/tabs/brave_tab_hover_browsertest.cc",
"//brave/browser/ui/views/tabs/tab_drag_controller_browsertest.cc",
]

deps = [
"//base",
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/views/tabs/tab_drag_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ void TabDragController::DetachAndAttachToNewContext(
std::vector<tabs::TabHandle> tabs;
auto* tab_strip_model = browser->tab_strip_model();
DCHECK_EQ(tab_strip_model, attached_context_->GetTabStripModel());
for (const auto& tab_drag_data : drag_data_) {
for (size_t i = first_tab_index(); i < drag_data_.size(); ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This here should be something like:

auto drag_data = base::span(drag_data_).subspan(first_tab_index());
for (const auto& tab_drag_data : drag_data) {
  ...

This way we don't access the subscript directly.

tabs.push_back(tab_strip_model->GetTabHandleAt(
tab_strip_model->GetIndexOfWebContents(tab_drag_data.contents)));
tab_strip_model->GetIndexOfWebContents(drag_data_[i].contents)));
}
old_split_view_browser_data->TabsWillBeAttachedToNewBrowser(tabs);
}
Expand Down
82 changes: 82 additions & 0 deletions browser/ui/views/tabs/tab_drag_controller_browsertest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "chrome/browser/ui/views/tabs/tab_drag_controller.h"

#include "brave/browser/ui/tabs/features.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test.h"

class TabDragControllerTest : public InProcessBrowserTest {
public:
~TabDragControllerTest() override = default;

TabDragControllerTest() {
scoped_feature_list_.InitAndEnableFeature(tabs::features::kBraveSplitView);
}

protected:
void AppendTab(Browser* browser) {
chrome::AddTabAt(browser, GURL(), -1, true);
}

tab_groups::TabGroupId AddTabToNewGroup(Browser* browser, int tab_index) {
return browser->tab_strip_model()->AddToNewGroup({tab_index});
}

TabStrip* GetTabStripForBrowser(Browser* browser) {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
return browser_view->tabstrip();
}

private:
base::test::ScopedFeatureList scoped_feature_list_;
};

#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
// It's flaky. Upstream also runs group header detach test only on Windows.
// See
// DetachToBrowserTabDragControllerTest.MAYBE_DragGroupHeaderToSeparateWindow
#define MAYBE_DragGroupHeaderToSeparateWindow \
DISABLED_DragGroupHeaderToSeparateWindow
#else
#define MAYBE_DragGroupHeaderToSeparateWindow DragGroupHeaderToSeparateWindow
#endif

// Browser test for https://github.com/brave/brave-browser/issues/39486
IN_PROC_BROWSER_TEST_F(TabDragControllerTest,
MAYBE_DragGroupHeaderToSeparateWindow) {
ASSERT_TRUE(browser()->tab_strip_model()->SupportsTabGroups());
tab_groups::TabGroupId group = AddTabToNewGroup(browser(), 0);
AppendTab(browser());

TabStrip* tab_strip = GetTabStripForBrowser(browser());
EXPECT_EQ(tab_strip->tab_at(0)->group().value(), group);
EXPECT_EQ(tab_strip->tab_at(1)->group(), std::nullopt);

TabGroupHeader* tab_group_header = tab_strip->group_header(group);
gfx::Point tab_group_header_center(tab_group_header->width() / 2,
tab_group_header->height() / 2);
const ui::MouseEvent mouse_pressed_event(
ui::EventType::kMousePressed, tab_group_header_center,
tab_group_header_center, base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
tab_strip->StopAnimating(true);
tab_strip->MaybeStartDrag(tab_group_header, mouse_pressed_event,
tab_strip->GetSelectionModel());

static const int kDragDistance = 20;
gfx::Point tab_group_drag_point(tab_group_header->width() + kDragDistance,
tab_group_header->height() + kDragDistance);
ui::MouseEvent mouse_dragged_event(
ui::EventType::kMouseDragged, tab_group_drag_point, tab_group_drag_point,
base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, 0);
std::ignore = tab_strip->ContinueDrag(tab_group_header, mouse_dragged_event);
tab_strip->EndDrag(EndDragReason::END_DRAG_COMPLETE);
}