[email protected] | 3b4bac6 | 2010-06-30 18:49:30 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "base/basictypes.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 6 | #include "chrome/browser/ui/tabs/dock_info.h" |
[email protected] | 3b4bac6 | 2010-06-30 18:49:30 | [diff] [blame] | 7 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 8 | #include "ui/gfx/point.h" |
[email protected] | 3b4bac6 | 2010-06-30 18:49:30 | [diff] [blame] | 9 | |
| 10 | namespace { |
| 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; |
| 17 | } // namespace |
| 18 | |
| 19 | TEST(DockInfoTest, IsCloseToPoint) { |
| 20 | bool in_enable_area; |
| 21 | gfx::Point screen_loc[] = { |
| 22 | gfx::Point(0, 0), |
| 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) |
| 28 | }; |
| 29 | gfx::Point hotspot[] = { |
| 30 | gfx::Point(0, 0), |
| 31 | gfx::Point(0, 0), |
| 32 | gfx::Point(kPopupWidth, kPopupHeight), |
| 33 | gfx::Point(0, 0), |
| 34 | gfx::Point(2*kHotSpotDeltaX, 2*kHotSpotDeltaY), |
| 35 | gfx::Point(0, 0) |
| 36 | }; |
| 37 | bool expected_results[] = { |
| 38 | true, true, true, true, false, false |
| 39 | }; |
| 40 | bool expected_in_enable_area[] = { |
| 41 | true, true, false, false, false, false |
| 42 | }; |
| 43 | |
| 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); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | TEST(DockInfoTest, IsCloseToMonitorPoint) { |
| 53 | bool in_enable_area; |
| 54 | gfx::Point screen_loc[] = { |
| 55 | gfx::Point(0, 0), |
| 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), |
| 62 | gfx::Point(0, 0), |
| 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), |
| 68 | }; |
| 69 | gfx::Point hotspot = gfx::Point(0, 0); |
| 70 | DockInfo::Type type[] = { |
| 71 | DockInfo::LEFT_HALF, |
| 72 | DockInfo::LEFT_HALF, |
| 73 | DockInfo::LEFT_HALF, |
| 74 | DockInfo::LEFT_HALF, |
| 75 | DockInfo::LEFT_HALF, |
| 76 | DockInfo::LEFT_HALF, |
| 77 | DockInfo::RIGHT_HALF, |
| 78 | DockInfo::BOTTOM_HALF, |
| 79 | DockInfo::BOTTOM_HALF, |
| 80 | DockInfo::BOTTOM_HALF, |
| 81 | DockInfo::BOTTOM_HALF, |
| 82 | DockInfo::BOTTOM_HALF, |
| 83 | DockInfo::BOTTOM_HALF, |
| 84 | }; |
| 85 | bool expected_results[] = { |
| 86 | true, true, true, true, false, false, false, |
| 87 | true, true, true, true, false, false |
| 88 | }; |
| 89 | bool expected_in_enable_area[] = { |
| 90 | true, true, false, false, false, false, false, |
| 91 | true, true, false, false, false, false |
| 92 | }; |
| 93 | |
| 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); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | TEST(DockInfoTest, IsValidForPoint) { |
| 103 | DockInfo d; |
[email protected] | 8b8fab97 | 2011-01-13 16:27:18 | [diff] [blame] | 104 | EXPECT_FALSE(d.IsValidForPoint(gfx::Point(0, 0))); |
[email protected] | 3b4bac6 | 2010-06-30 18:49:30 | [diff] [blame] | 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); |
| 108 | |
| 109 | gfx::Point screen_point[] = { |
| 110 | gfx::Point(0, 0), |
| 111 | gfx::Point(kPopupWidth + 1, kPopupHeight + 1), |
| 112 | gfx::Point(2 * kHotSpotDeltaX, kHotSpotDeltaY), |
| 113 | }; |
| 114 | |
| 115 | bool expected_result[] = { |
| 116 | true, false, false |
| 117 | }; |
| 118 | |
| 119 | for (size_t i = 0; i < arraysize(expected_result); ++i) { |
| 120 | EXPECT_EQ(expected_result[i], d.IsValidForPoint(screen_point[i])); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | TEST(DockInfoTest, equals) { |
| 125 | DockInfo d; |
| 126 | DockInfo dd; |
[email protected] | 515f249 | 2011-01-14 10:36:28 | [diff] [blame] | 127 | EXPECT_TRUE(d.equals(dd)); |
[email protected] | 3b4bac6 | 2010-06-30 18:49:30 | [diff] [blame] | 128 | d.set_type(DockInfo::MAXIMIZE); |
[email protected] | 8b8fab97 | 2011-01-13 16:27:18 | [diff] [blame] | 129 | EXPECT_FALSE(d.equals(dd)); |
[email protected] | 3b4bac6 | 2010-06-30 18:49:30 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | TEST(DockInfoTest, CheckMonitorPoint) { |
| 133 | DockInfo d; |
| 134 | gfx::Point screen_loc[] = { |
| 135 | gfx::Point(0, 0), |
| 136 | gfx::Point(2 * kHotSpotDeltaX, kHotSpotDeltaY), |
| 137 | gfx::Point(2 * kHotSpotDeltaX, kHotSpotDeltaY), |
| 138 | }; |
| 139 | |
| 140 | DockInfo::Type type[] = { |
| 141 | DockInfo::LEFT_HALF, |
| 142 | DockInfo::RIGHT_HALF, |
| 143 | DockInfo::MAXIMIZE |
| 144 | }; |
| 145 | |
| 146 | bool expected_result[] = { |
| 147 | true, false, false |
| 148 | }; |
| 149 | |
| 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()); |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | TEST(DockInfoTest, GetPopupRect) { |
| 162 | DockInfo d; |
| 163 | d.set_hot_spot(gfx::Point(kPopupWidth, kPopupHeight)); |
| 164 | DockInfo::Type type[] = { |
| 165 | DockInfo::MAXIMIZE, |
| 166 | DockInfo::LEFT_HALF, |
| 167 | DockInfo::RIGHT_HALF, |
| 168 | DockInfo::BOTTOM_HALF, |
| 169 | }; |
| 170 | int expected_x[] = { |
| 171 | kPopupWidth/2, |
| 172 | kPopupWidth, |
| 173 | 0, |
| 174 | kPopupWidth/2 |
| 175 | }; |
| 176 | int expected_y[] = { |
| 177 | kPopupHeight, |
| 178 | kPopupHeight/2, |
| 179 | kPopupHeight/2, |
| 180 | 0 |
| 181 | }; |
| 182 | |
| 183 | for (size_t i = 0; i < arraysize(type); ++i) { |
| 184 | d.set_type(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()); |
| 190 | } |
| 191 | } |