chromium/chrome/browser/ui/views/toolbar/toolbar_controller_interactive_uitest.cc

// 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 <optional>
#include <sstream>

#include "base/functional/overloaded.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/user_action_tester.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/toolbar/pinned_toolbar/pinned_toolbar_actions_model.h"
#include "chrome/browser/ui/toolbar_controller_util.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/side_panel/side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_util.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs/chrome_labs_button.h"
#include "chrome/browser/ui/views/toolbar/pinned_toolbar_actions_container.h"
#include "chrome/browser/ui/views/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/interaction/feature_engagement_initialized_observer.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "chrome/test/user_education/interactive_feature_promo_test.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/test/scoped_iph_feature_list.h"
#include "components/user_education/common/feature_promo_result.h"
#include "components/user_education/views/help_bubble_view.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/test/test_extension_dir.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/layout/animating_layout_manager_test_util.h"
#include "ui/views/test/views_test_utils.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"

namespace {
constexpr int kBrowserContentAllowedMinimumWidth =;
}  // namespace

class ToolbarControllerUiTest : public InteractiveFeaturePromoTest {};

// TODO(crbug.com/41495158): Flaky on Windows.
#if BUILDFLAG(IS_WIN)
#define MAYBE_StartBrowserWithThresholdWidth
#else
#define MAYBE_StartBrowserWithThresholdWidth
#endif
IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       MAYBE_StartBrowserWithThresholdWidth) {}
// TODO(crbug.com/41495158): Flaky on Windows.
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_StartBrowserWithWidthSmallerThanThreshold
#else
#define MAYBE_StartBrowserWithWidthSmallerThanThreshold
#endif
IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       MAYBE_StartBrowserWithWidthSmallerThanThreshold) {}

IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       StartBrowserWithWidthLargerThanThreshold) {}

IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest, MenuMatchesOverflowedElements) {}

IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest, ActivateActionElementFromMenu) {}

// TODO(crbug.com/360465388): Lacros failures are because resize doesn't
// actually stick.
// TODO(crbug/361296257): ActionItemsOverflowAndReappear is flaky on
// linux64-rel-ready.
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_LINUX)
#define MAYBE_ActionItemsOverflowAndReappear
#else
#define MAYBE_ActionItemsOverflowAndReappear
#endif
IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       MAYBE_ActionItemsOverflowAndReappear) {}

// TODO(crbug.com/360465388): Lacros failures are because resize doesn't
// actually stick.
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_ActionItemsShowInMenuAndActivateFromMenu
#else
#define MAYBE_ActionItemsShowInMenuAndActivateFromMenu
#endif
IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       MAYBE_ActionItemsShowInMenuAndActivateFromMenu) {}

IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       ActivatedActionItemsDoNotOverflow) {}

// TODO(crbug.com/41495158): Flaky on multiple platforms.
IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       DISABLED_DeactivatedActionItemsOverflow) {}

IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       EveryElementHasActionMetricName) {}

// Verify fixing animation loop bug (crbug.com/).
// Steps to reproduce:
// 1  Set browser with to a big value that nothing should overflow.
// 2. Have 1 pinned extension button in extensions container.
// 3. Have 2 pinned buttons in pinned toolbar container.
// 4. Set browser width to when PinnedToolbarContainer starts to overflow. In
// this case both pinned buttons in PinnedToolbarContainer should overflow,
// overflow button should show. Verify: The pinned extension button should still
// be visible because there's enough space for it. Extensions container should
// not have animation because its visibility didn't change.
// TODO(crbug.com/41495158): Flaky on Windows and Mac.
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#define MAYBE_ExtensionHasNoAnimationLoop
#else
#define MAYBE_ExtensionHasNoAnimationLoop
#endif
IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       MAYBE_ExtensionHasNoAnimationLoop) {}

// TODO(crbug.com/41495158): Flaky on Windows and fails on Lacros.
// TODO(crbug.com/360465388): Lacros failures are because resize doesn't
// actually stick.
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS_LACROS)
#define MAYBE_DoNotShowIphWhenOverflowed
#else
#define MAYBE_DoNotShowIphWhenOverflowed
#endif
IN_PROC_BROWSER_TEST_F(ToolbarControllerUiTest,
                       MAYBE_DoNotShowIphWhenOverflowed) {}