#include "ui/views/animation/ink_drop_host.h"
#include <memory>
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/test/mock_callback.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/compositor/layer.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_handler.h"
#include "ui/events/event_utils.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/animation/animation_test_api.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/test/ink_drop_host_test_api.h"
#include "ui/views/animation/test/ink_drop_impl_test_api.h"
#include "ui/views/animation/test/test_ink_drop.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/test/views_test_base.h"
namespace views::test {
InkDropMode;
class TestViewWithInkDrop : public View { … };
class InkDropHostTest : public testing::Test { … };
InkDropHostTest::InkDropHostTest()
: … { … }
InkDropHostTest::~InkDropHostTest() = default;
void InkDropHostTest::MouseEventTriggersInkDropHelper(
InkDropMode ink_drop_mode) { … }
TEST_F(InkDropHostTest, GetInkDropCenterBasedOnLastEventForNullEvent) { … }
TEST_F(InkDropHostTest, GetInkDropCenterBasedOnLastEventForLocatedEvent) { … }
TEST_F(InkDropHostTest, HasInkDrop) { … }
TEST_F(InkDropHostTest, MouseEventsTriggerInkDropsWhenInkDropIsOn) { … }
TEST_F(InkDropHostTest,
MouseEventsTriggerInkDropsWhenInkDropIsOnNoGestureHandler) { … }
TEST_F(InkDropHostTest, MouseEventsDontTriggerInkDropsWhenInkDropIsOff) { … }
TEST_F(InkDropHostTest, GestureEventsDontTriggerInkDropsWhenHostIsDisabled) { … }
TEST_F(InkDropHostTest,
GestureEventsDontTriggerInkDropsWhenInkDropModeIsNotOn) { … }
#if BUILDFLAG(IS_WIN)
TEST_F(InkDropHostTest, NoInkDropOnTouchOrGestureEvents) {
host_view_.SetSize(gfx::Size(20, 20));
test_api_.SetInkDropMode(
views::InkDropHost::InkDropMode::ON_NO_GESTURE_HANDLER);
EXPECT_EQ(test_api_.GetInkDrop()->GetTargetInkDropState(),
InkDropState::HIDDEN);
ui::TouchEvent touch_event(
ui::EventType::kTouchPressed, gfx::Point(5, 6), ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::kTouch, 1));
test_api_.AnimateToState(InkDropState::ACTION_PENDING, &touch_event);
EXPECT_EQ(test_api_.GetInkDrop()->GetTargetInkDropState(),
InkDropState::HIDDEN);
test_api_.AnimateToState(InkDropState::ALTERNATE_ACTION_PENDING,
&touch_event);
EXPECT_EQ(test_api_.GetInkDrop()->GetTargetInkDropState(),
InkDropState::HIDDEN);
ui::GestureEvent gesture_event(
5.0f, 6.0f, 0, ui::EventTimeForNow(),
ui::GestureEventDetails(ui::EventType::kGestureTap));
test_api_.AnimateToState(InkDropState::ACTION_PENDING, &gesture_event);
EXPECT_EQ(test_api_.GetInkDrop()->GetTargetInkDropState(),
InkDropState::HIDDEN);
test_api_.AnimateToState(InkDropState::ALTERNATE_ACTION_PENDING,
&gesture_event);
EXPECT_EQ(test_api_.GetInkDrop()->GetTargetInkDropState(),
InkDropState::HIDDEN);
}
TEST_F(InkDropHostTest, DismissInkDropOnTouchOrGestureEvents) {
if (!gfx::Animation::ShouldRenderRichAnimation()) {
return;
}
host_view_.SetSize(gfx::Size(20, 20));
test_api_.SetInkDropMode(
views::InkDropHost::InkDropMode::ON_NO_GESTURE_HANDLER);
EXPECT_EQ(test_api_.GetInkDrop()->GetTargetInkDropState(),
InkDropState::HIDDEN);
ui::MouseEvent mouse_event(ui::EventType::kMousePressed, gfx::Point(5, 6),
gfx::Point(5, 6), ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, 0);
test_api_.AnimateToState(InkDropState::ACTION_PENDING, &mouse_event);
EXPECT_EQ(test_api_.GetInkDrop()->GetTargetInkDropState(),
InkDropState::ACTION_PENDING);
ui::TouchEvent touch_event(
ui::EventType::kTouchPressed, gfx::Point(5, 6), ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::kTouch, 1));
test_api_.AnimateToState(InkDropState::ACTION_TRIGGERED, &touch_event);
EXPECT_EQ(test_api_.GetInkDrop()->GetTargetInkDropState(),
InkDropState::ACTION_TRIGGERED);
}
#endif
TEST_F(InkDropHostTest, HighlightedChangedFired) { … }
class BasicTestViewWithInkDrop : public View { … };
class InkDropHostClippingTest : public testing::Test { … };
TEST_F(InkDropHostClippingTest, DefaultInkDropMasksRootLayer) { … }
TEST_F(InkDropHostClippingTest,
HighlightPathGeneratorClipsRootLayerWithoutMask) { … }
TEST_F(InkDropHostClippingTest,
EmptyHighlightPathGeneratorUsesNeitherMaskNorClipsRootLayer) { … }
class InkDropInWidgetTest : public ViewsTestBase { … };
TEST_F(InkDropInWidgetTest, SetBaseColor) { … }
TEST_F(InkDropInWidgetTest, SetBaseColorId) { … }
TEST_F(InkDropInWidgetTest, SetBaseColorCallback) { … }
class InkDropHostAttentionTest : public ViewsTestBase { … };
TEST_F(InkDropHostAttentionTest, ToggleAttentionColor) { … }
TEST_F(InkDropHostAttentionTest, ToggleAttentionMask) { … }
TEST_F(InkDropHostAttentionTest, AttentionMaskCoexistWithClipping) { … }
}