Skip to content

Commit

Permalink
[responsive toolbar] force all buttons not overflow in browser tests
Browse files Browse the repository at this point in the history
Add a flag to make sure responsive toolbar would not overflow
buttons and turn it it on browser tests by default. This prevents
responsive toolbar from accidentally breaking browser tests.

For responsive toolbar specific tests we need to revert the flag to
test responsive toolbar specific logic.

Bug: 1463774
Change-Id: Ief7f968de29adddbe1dd7d8ef1859d263f6676c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4937130
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Dana Fried <dfried@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Yuheng Huang <yuhengh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1213091}
  • Loading branch information
Yuheng Huang authored and Chromium LUCI CQ committed Oct 21, 2023
1 parent 932998e commit 1188e6b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4699,6 +4699,8 @@ static_library("ui") {
"side_panel/side_panel_prefs.h",
"side_panel/side_panel_ui.cc",
"side_panel/side_panel_ui.h",
"toolbar_controller_util.cc",
"toolbar_controller_util.h",
"views/send_tab_to_self/send_tab_to_self_bubble.cc",
"views/send_tab_to_self/send_tab_to_self_bubble_controller.cc",
"views/send_tab_to_self/send_tab_to_self_bubble_controller.h",
Expand Down
18 changes: 18 additions & 0 deletions chrome/browser/ui/toolbar_controller_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/toolbar_controller_util.h"

bool ToolbarControllerUtil::prevent_overflow_for_testing_ = false;

// static
void ToolbarControllerUtil::SetPreventOverflowForTesting(
bool prevent_overflow) {
prevent_overflow_for_testing_ = prevent_overflow;
}

// static
bool ToolbarControllerUtil::PreventOverflow() {
return prevent_overflow_for_testing_;
}
19 changes: 19 additions & 0 deletions chrome/browser/ui/toolbar_controller_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_TOOLBAR_CONTROLLER_UTIL_H_
#define CHROME_BROWSER_UI_TOOLBAR_CONTROLLER_UTIL_H_
class ToolbarControllerUtil {
public:
// Set whether prevent toolbar buttons from overflow. Should only call by
// tests.
static void SetPreventOverflowForTesting(bool prevent_overflow);

// Return whether should prevent toolbar buttons from overflow.
static bool PreventOverflow();

private:
static bool prevent_overflow_for_testing_;
};
#endif // CHROME_BROWSER_UI_TOOLBAR_CONTROLLER_UTIL_H_
8 changes: 8 additions & 0 deletions chrome/browser/ui/views/toolbar/toolbar_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "chrome/browser/ui/views/toolbar/toolbar_controller.h"

#include "chrome/browser/ui/toolbar_controller_util.h"
#include "chrome/browser/ui/views/toolbar/overflow_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "chrome/grit/generated_resources.h"
Expand Down Expand Up @@ -61,6 +62,10 @@ ToolbarController::ToolbarController(
element_flex_order_start_(element_flex_order_start),
toolbar_container_view_(toolbar_container_view),
overflow_button_(overflow_button) {
if (ToolbarControllerUtil::PreventOverflow()) {
return;
}

for (ui::ElementIdentifier id : element_ids) {
auto* const toolbar_element =
FindToolbarElementWithId(toolbar_container_view_, id);
Expand Down Expand Up @@ -222,6 +227,9 @@ views::View* ToolbarController::FindToolbarElementWithId(

std::vector<ui::ElementIdentifier> ToolbarController::GetOverflowedElements() {
std::vector<ui::ElementIdentifier> overflowed_buttons;
if (ToolbarControllerUtil::PreventOverflow()) {
return overflowed_buttons;
}
for (ui::ElementIdentifier id : element_ids_) {
if (IsOverflowed(id)) {
overflowed_buttons.push_back(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "base/feature_list.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ui/toolbar_controller_util.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs_button.h"
Expand All @@ -24,6 +25,7 @@ constexpr int kBrowserContentAllowedMinimumWidth =
class ToolbarControllerInteractiveTest : public InteractiveBrowserTest {
public:
ToolbarControllerInteractiveTest() {
ToolbarControllerUtil::SetPreventOverflowForTesting(false);
scoped_feature_list_.InitWithFeatures({features::kResponsiveToolbar}, {});
}

Expand Down
4 changes: 4 additions & 0 deletions chrome/test/base/in_process_browser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar_controller_util.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
Expand Down Expand Up @@ -404,6 +405,9 @@ void InProcessBrowserTest::Initialize() {
bundle_swizzler_ = std::make_unique<ScopedBundleSwizzlerMac>();
#endif

// Force all buttons not overflow to prevent test flakiness.
ToolbarControllerUtil::SetPreventOverflowForTesting(true);

std::vector<base::test::FeatureRef> disabled_features;

// Preconnecting can cause non-deterministic test behavior especially with
Expand Down

0 comments on commit 1188e6b

Please sign in to comment.