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

// Copyright 2018 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/views/toolbar/toolbar_button.h"

#include <memory>
#include <utility>

#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/actions/actions.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/models/image_model.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/pointer/touch_ui_controller.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/interaction/element_tracker_views.h"

namespace test {

// Friend of ToolbarButton to access private members.
class ToolbarButtonTestApi {};

}  // namespace test

namespace {

class CheckActiveWebContentsMenuModel : public ui::SimpleMenuModel {};

class TestToolbarButton : public ToolbarButton {};

}  // namespace

ToolbarButtonViewsTest;

TEST_F(ToolbarButtonViewsTest, NoDefaultLayoutInsets) {}

TEST_F(ToolbarButtonViewsTest, SetLayoutInsets) {}

TEST_F(ToolbarButtonViewsTest, MenuDoesNotShowWhenTabStripIsEmpty) {}

class ToolbarButtonUITest : public ChromeViewsTestBase {};

// Test showing and dismissing a menu to verify menu delegate lifetime.
TEST_F(ToolbarButtonUITest, ShowMenu) {}

// Widget activation on Mac in unit tests is not reliable, so this will also be
// covered by e.g. `ToolbarViewTest.BackButtonMenu`.
#if !BUILDFLAG(IS_MAC)
TEST_F(ToolbarButtonUITest, ShowMenuWithIdentifier) {}
#endif  // !BUILDFLAG(IS_MAC)

// Test deleting a ToolbarButton while its menu is showing.
TEST_F(ToolbarButtonUITest, DeleteWithMenu) {}

// Tests to make sure the button's border color is updated as its animation
// color changes.
TEST_F(ToolbarButtonUITest, TestBorderUpdateColorChange) {}

// Ensures ToolbarButton updates its border on touch mode changes to
// match layout constants.
//
// Regression test for crbug.com/1163451: ToolbarButton updates its
// border on bounds change, which usually happens during layout.
// Updating the border itself invalidates layout if the border change
// results in a new preferred size. But View::SetBoundsRect() sets
// needs_layout_ = false right after the OnBoundsChanged() call.
//
// On touch mode changes the border change only happened after several
// layouts. When the bug occurred, the border was eventually set
// correctly but too late: its final size did not reflect the preferred
// size after the border update.
//
// This test ensures ToolbarButtons update their border promptly after
// the touch mode change, just after the icon update.
TEST_F(ToolbarButtonUITest, BorderUpdatedOnTouchModeSwitch) {}

ToolbarButtonActionViewInterfaceTest;

TEST_F(ToolbarButtonActionViewInterfaceTest, TestActionChanged) {}