1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
ash / quick_insert / views / quick_insert_positioning_unittest.cc [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/quick_insert/views/quick_insert_positioning.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/outsets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
namespace ash {
namespace {
constexpr gfx::Outsets kPaddingAroundCaret(4);
constexpr gfx::Point kDefaultCursorPoint(42, 42);
TEST(QuickInsertPositioningTest,
UsesCaretBoundsWhenCaretBoundsIsWithinWindowBounds) {
gfx::Rect caret_bounds(100, 200, 5, 5);
const gfx::Rect anchor_bounds = GetQuickInsertAnchorBounds(
/*caret_bounds=*/caret_bounds, kDefaultCursorPoint,
/*focused_window_bounds=*/gfx::Rect(0, 0, 500, 500));
caret_bounds.Outset(kPaddingAroundCaret);
EXPECT_EQ(anchor_bounds, caret_bounds);
}
TEST(QuickInsertPositioningTest,
UsesCursorPointWhenCaretBoundsIsOutsideWindowBounds) {
const gfx::Rect anchor_bounds = GetQuickInsertAnchorBounds(
/*caret_bounds=*/gfx::Rect(600, 200, 5, 5), kDefaultCursorPoint,
/*focused_window_bounds=*/gfx::Rect(0, 0, 500, 500));
EXPECT_EQ(anchor_bounds.origin(), kDefaultCursorPoint);
EXPECT_EQ(anchor_bounds.width(), 0);
EXPECT_EQ(anchor_bounds.height(), 0);
}
TEST(QuickInsertPositioningTest, UsesCursorPointWhenCaretBoundsIsEmpty) {
const gfx::Rect anchor_bounds = GetQuickInsertAnchorBounds(
/*caret_bounds=*/gfx::Rect(), kDefaultCursorPoint,
/*focused_window_bounds=*/gfx::Rect(0, 0, 500, 500));
EXPECT_EQ(anchor_bounds.origin(), kDefaultCursorPoint);
EXPECT_EQ(anchor_bounds.width(), 0);
EXPECT_EQ(anchor_bounds.height(), 0);
}
} // namespace
} // namespace ash