forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer_floating_behavior_unittest.cc
154 lines (127 loc) · 6.85 KB
/
container_floating_behavior_unittest.cc
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/keyboard/ui/container_floating_behavior.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/vector2d.h"
namespace keyboard {
TEST(ContainerFloatingBehaviorTest, AdjustSetBoundsRequest) {
ContainerFloatingBehavior floating_behavior(nullptr);
const int keyboard_width = 600;
const int keyboard_height = 70;
gfx::Rect workspace(0, 0, 1000, 600);
gfx::Rect center(100, 100, keyboard_width, keyboard_height);
gfx::Rect top_left_overlap(-30, -30, keyboard_width, keyboard_height);
gfx::Rect bottom_right_overlap(workspace.width() - 30,
workspace.height() - 30, keyboard_width,
keyboard_height);
// Save an arbitrary position so that default location will not be used.
floating_behavior.SavePosition(
gfx::Rect(0, 0, keyboard_width, keyboard_height), workspace.size());
gfx::Rect result =
floating_behavior.AdjustSetBoundsRequest(workspace, center);
ASSERT_EQ(center, result);
result =
floating_behavior.AdjustSetBoundsRequest(workspace, top_left_overlap);
ASSERT_EQ(gfx::Rect(0, 0, keyboard_width, keyboard_height), result);
result =
floating_behavior.AdjustSetBoundsRequest(workspace, bottom_right_overlap);
ASSERT_EQ(gfx::Rect(workspace.width() - keyboard_width,
workspace.height() - keyboard_height, keyboard_width,
keyboard_height),
result);
// Try to move the keyboard to the center of the primary display while it's
// in a secondary display.
gfx::Rect secondary_display(1000, -200, 1200, 800);
result = floating_behavior.AdjustSetBoundsRequest(secondary_display, center);
// It gets clipped to the far left of this display
ASSERT_EQ(gfx::Rect(1000, 100, keyboard_width, keyboard_height), result);
}
TEST(ContainerFloatingBehaviorTest, AdjustSetBoundsRequestVariousSides) {
ContainerFloatingBehavior floating_behavior(nullptr);
const int keyboard_width = 100;
const int keyboard_height = 100;
gfx::Size keyboard_size = gfx::Size(keyboard_width, keyboard_height);
gfx::Rect workspace_wide(0, 0, 1000, 500);
gfx::Rect workspace_tall(0, 0, 500, 1000);
gfx::Rect top_left(0, 0, keyboard_width, keyboard_height);
gfx::Rect top_right(900, 0, keyboard_width, keyboard_height);
gfx::Rect bottom_left(0, 400, keyboard_width, keyboard_height);
gfx::Rect bottom_right(900, 400, keyboard_width, keyboard_height);
gfx::Rect bottomish_center(450, 390, keyboard_width, keyboard_height);
// Save an arbitrary position so that default location will not be used.
floating_behavior.SavePosition(
gfx::Rect(0, 0, keyboard_width, keyboard_height), workspace_wide.size());
floating_behavior.AdjustSetBoundsRequest(workspace_wide, top_left);
gfx::Point result = floating_behavior.GetPositionForShowingKeyboard(
keyboard_size, workspace_wide);
ASSERT_EQ(gfx::Point(0, 0), result);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_tall);
ASSERT_EQ(gfx::Point(0, 0), result);
floating_behavior.AdjustSetBoundsRequest(workspace_wide, top_right);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_wide);
ASSERT_EQ(gfx::Point(900, 0), result);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_tall);
ASSERT_EQ(gfx::Point(400, 0), result);
floating_behavior.AdjustSetBoundsRequest(workspace_wide, bottom_left);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_wide);
ASSERT_EQ(gfx::Point(0, 400), result);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_tall);
ASSERT_EQ(gfx::Point(0, 900), result);
floating_behavior.AdjustSetBoundsRequest(workspace_wide, bottom_right);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_wide);
ASSERT_EQ(gfx::Point(900, 400), result);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_tall);
ASSERT_EQ(gfx::Point(400, 900), result);
floating_behavior.AdjustSetBoundsRequest(workspace_wide, bottomish_center);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_wide);
ASSERT_EQ(gfx::Point(450, 390), result);
result = floating_behavior.GetPositionForShowingKeyboard(keyboard_size,
workspace_tall);
// rather than 400:0 for the vertical padding, use 390:10
// with 900 pixels available this ratio results in 877.5, which is truncated.
// 390 / 400 * 900 = 877.5
ASSERT_EQ(gfx::Point(200, 877), result);
}
TEST(ContainerFloatingBehaviorTest, DontSaveCoordinatesUntilKeyboardMoved) {
ContainerFloatingBehavior floating_behavior(nullptr);
const int keyboard_width = 600;
const int keyboard_height = 70;
gfx::Rect workspace(0, 0, 1000, 600);
gfx::Rect top_left(0, 0, keyboard_width, keyboard_height);
gfx::Rect center(100, 100, keyboard_width, keyboard_height);
gfx::Rect initial_default(
workspace.width() - keyboard_width - kDefaultDistanceFromScreenRight,
workspace.height() - keyboard_height - kDefaultDistanceFromScreenBottom,
keyboard_width, keyboard_height);
// Adjust bounds to the arbitrary load location. Floating Behavior should use
// the UX-chosen default location instead.
gfx::Rect result =
floating_behavior.AdjustSetBoundsRequest(workspace, top_left);
ASSERT_EQ(initial_default, result);
// Doing the same thing again should result in the same behavior, since the
// values should not have been preserved.
result = floating_behavior.AdjustSetBoundsRequest(workspace, top_left);
ASSERT_EQ(initial_default, result);
// Simulate the user clicking and moving the keyboard to some arbitrary
// location (it doesn't matter where). Now that the coordinate is known to be
// user-determined.
floating_behavior.SavePosition(
gfx::Rect(10, 10, keyboard_width, keyboard_height), workspace.size());
// Move the keyboard somewhere else. The coordinates should be taken as-is
// without being adjusted.
result = floating_behavior.AdjustSetBoundsRequest(workspace, center);
ASSERT_EQ(center, result);
}
} // namespace keyboard