1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "chrome/browser/ui/tabs/dock_info.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/point.h"
11 // Distance in pixels between the hotspot and when the hint should be shown.
12 const int kHotSpotDeltaX
= 120;
13 const int kHotSpotDeltaY
= 120;
14 // Size of the popup window.
15 const int kPopupWidth
= 70;
16 const int kPopupHeight
= 70;
19 TEST(DockInfoTest
, IsCloseToPoint
) {
21 gfx::Point screen_loc
[] = {
23 gfx::Point(kPopupWidth
/2 - 1, kPopupHeight
/2 - 1),
24 gfx::Point(kPopupWidth
/2, kPopupHeight
/2),
25 gfx::Point(kHotSpotDeltaX
- 1, kHotSpotDeltaY
- 1),
26 gfx::Point(kHotSpotDeltaX
, kHotSpotDeltaY
),
27 gfx::Point(-kHotSpotDeltaX
, -kHotSpotDeltaY
)
29 gfx::Point hotspot
[] = {
32 gfx::Point(kPopupWidth
, kPopupHeight
),
34 gfx::Point(2*kHotSpotDeltaX
, 2*kHotSpotDeltaY
),
37 bool expected_results
[] = {
38 true, true, true, true, false, false
40 bool expected_in_enable_area
[] = {
41 true, true, false, false, false, false
44 for (size_t i
= 0; i
< arraysize(expected_results
); ++i
) {
45 bool result
= DockInfo::IsCloseToPoint(
46 screen_loc
[i
], hotspot
[i
].x(), hotspot
[i
].y(), &in_enable_area
);
47 EXPECT_EQ(expected_results
[i
], result
);
48 EXPECT_EQ(expected_in_enable_area
[i
], in_enable_area
);
52 TEST(DockInfoTest
, IsCloseToMonitorPoint
) {
54 gfx::Point screen_loc
[] = {
56 gfx::Point(kPopupWidth
- 1, kPopupHeight
/2 -1),
57 gfx::Point(kPopupWidth
, kPopupHeight
/2 - 1),
58 gfx::Point(kPopupWidth
- 1, kPopupHeight
),
59 gfx::Point(2*kHotSpotDeltaX
, kHotSpotDeltaY
- 1),
60 gfx::Point(2*kHotSpotDeltaX
- 1, kHotSpotDeltaY
),
61 gfx::Point(2*kHotSpotDeltaX
- 1, kHotSpotDeltaY
),
63 gfx::Point(kPopupWidth
/2 - 1, kPopupHeight
- 1),
64 gfx::Point(kPopupWidth
/2 - 1, kPopupHeight
),
65 gfx::Point(kPopupWidth
/2, kPopupHeight
- 1),
66 gfx::Point(kHotSpotDeltaX
- 1, 2*kHotSpotDeltaY
),
67 gfx::Point(kHotSpotDeltaX
, 2*kHotSpotDeltaY
- 1),
69 gfx::Point hotspot
= gfx::Point(0, 0);
70 DockInfo::Type type
[] = {
78 DockInfo::BOTTOM_HALF
,
79 DockInfo::BOTTOM_HALF
,
80 DockInfo::BOTTOM_HALF
,
81 DockInfo::BOTTOM_HALF
,
82 DockInfo::BOTTOM_HALF
,
83 DockInfo::BOTTOM_HALF
,
85 bool expected_results
[] = {
86 true, true, true, true, false, false, false,
87 true, true, true, true, false, false
89 bool expected_in_enable_area
[] = {
90 true, true, false, false, false, false, false,
91 true, true, false, false, false, false
94 for (size_t i
= 0; i
< arraysize(expected_results
); ++i
) {
95 bool result
= DockInfo::IsCloseToMonitorPoint(
96 screen_loc
[i
], hotspot
.x(), hotspot
.y(), type
[i
], &in_enable_area
);
97 EXPECT_EQ(expected_results
[i
], result
);
98 EXPECT_EQ(expected_in_enable_area
[i
], in_enable_area
);
102 TEST(DockInfoTest
, IsValidForPoint
) {
104 EXPECT_FALSE(d
.IsValidForPoint(gfx::Point(0, 0)));
105 d
.set_monitor_bounds(gfx::Rect(0, 0, kPopupWidth
, kPopupHeight
));
106 d
.set_hot_spot(gfx::Point(0, 0));
107 d
.set_type(DockInfo::LEFT_HALF
);
109 gfx::Point screen_point
[] = {
111 gfx::Point(kPopupWidth
+ 1, kPopupHeight
+ 1),
112 gfx::Point(2 * kHotSpotDeltaX
, kHotSpotDeltaY
),
115 bool expected_result
[] = {
119 for (size_t i
= 0; i
< arraysize(expected_result
); ++i
) {
120 EXPECT_EQ(expected_result
[i
], d
.IsValidForPoint(screen_point
[i
]));
124 TEST(DockInfoTest
, equals
) {
127 EXPECT_TRUE(d
.equals(dd
));
128 d
.set_type(DockInfo::MAXIMIZE
);
129 EXPECT_FALSE(d
.equals(dd
));
132 TEST(DockInfoTest
, CheckMonitorPoint
) {
134 gfx::Point screen_loc
[] = {
136 gfx::Point(2 * kHotSpotDeltaX
, kHotSpotDeltaY
),
137 gfx::Point(2 * kHotSpotDeltaX
, kHotSpotDeltaY
),
140 DockInfo::Type type
[] = {
142 DockInfo::RIGHT_HALF
,
146 bool expected_result
[] = {
150 for (size_t i
= 0; i
< arraysize(expected_result
); ++i
) {
151 bool result
= d
.CheckMonitorPoint(screen_loc
[i
], 0, 0, type
[i
]);
152 EXPECT_EQ(result
, expected_result
[i
]);
153 if (result
== true) {
154 EXPECT_EQ(0, d
.hot_spot().x());
155 EXPECT_EQ(0, d
.hot_spot().y());
156 EXPECT_EQ(type
[i
], d
.type());
161 TEST(DockInfoTest
, GetPopupRect
) {
163 d
.set_hot_spot(gfx::Point(kPopupWidth
, kPopupHeight
));
164 DockInfo::Type type
[] = {
167 DockInfo::RIGHT_HALF
,
168 DockInfo::BOTTOM_HALF
,
183 for (size_t i
= 0; i
< arraysize(type
); ++i
) {
185 gfx::Rect result
= d
.GetPopupRect();
186 EXPECT_EQ(expected_x
[i
], result
.x());
187 EXPECT_EQ(expected_y
[i
], result
.y());
188 EXPECT_EQ(kPopupWidth
, result
.width());
189 EXPECT_EQ(kPopupHeight
, result
.height());