Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/shelf/shelf_constants.h" | 5 #include "ash/common/shelf/shelf_constants.h" |
| 6 #include "ash/common/shelf/wm_shelf.h" | |
| 6 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 7 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
| 8 #include "ash/shelf/shelf.h" | |
| 9 #include "ash/shelf/shelf_layout_manager.h" | |
| 10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 11 #include "ash/system/toast/toast_manager.h" | 10 #include "ash/system/toast/toast_manager.h" |
| 12 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 15 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 15 #include "ui/views/widget/widget.h" | |
| 16 | 16 |
| 17 namespace ash { | 17 namespace ash { |
| 18 | 18 |
| 19 class DummyEvent : public ui::Event { | 19 class DummyEvent : public ui::Event { |
| 20 public: | 20 public: |
| 21 DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeTicks(), 0) {} | 21 DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeTicks(), 0) {} |
| 22 ~DummyEvent() override {} | 22 ~DummyEvent() override {} |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 class ToastManagerTest : public test::AshTestBase { | 25 class ToastManagerTest : public test::AshTestBase { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 ToastOverlay* overlay = GetCurrentOverlay(); | 60 ToastOverlay* overlay = GetCurrentOverlay(); |
| 61 return overlay ? overlay->dismiss_text_ : std::string(); | 61 return overlay ? overlay->dismiss_text_ : std::string(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ClickDismissButton() { | 64 void ClickDismissButton() { |
| 65 ToastOverlay* overlay = GetCurrentOverlay(); | 65 ToastOverlay* overlay = GetCurrentOverlay(); |
| 66 if (overlay) | 66 if (overlay) |
| 67 overlay->ClickDismissButtonForTesting(DummyEvent()); | 67 overlay->ClickDismissButtonForTesting(DummyEvent()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SetShelfAlignment(ShelfAlignment alignment) { | |
| 71 Shelf::ForPrimaryDisplay()->SetAlignment(alignment); | |
| 72 } | |
| 73 | |
| 74 void SetShelfState(ShelfVisibilityState state) { | |
| 75 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetState(state); | |
| 76 } | |
| 77 | |
| 78 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior) { | |
| 79 Shelf::ForPrimaryDisplay()->SetAutoHideBehavior(behavior); | |
| 80 } | |
| 81 | |
| 82 std::string ShowToast(const std::string& text, int32_t duration) { | 70 std::string ShowToast(const std::string& text, int32_t duration) { |
| 83 std::string id = "TOAST_ID_" + base::UintToString(serial_++); | 71 std::string id = "TOAST_ID_" + base::UintToString(serial_++); |
| 84 manager()->Show(ToastData(id, text, duration, "")); | 72 manager()->Show(ToastData(id, text, duration, "")); |
| 85 return id; | 73 return id; |
| 86 } | 74 } |
| 87 | 75 |
| 88 std::string ShowToastWithDismiss(const std::string& text, | 76 std::string ShowToastWithDismiss(const std::string& text, |
| 89 int32_t duration, | 77 int32_t duration, |
| 90 const std::string& dismiss_text) { | 78 const std::string& dismiss_text) { |
| 91 std::string id = "TOAST_ID_" + base::UintToString(serial_++); | 79 std::string id = "TOAST_ID_" + base::UintToString(serial_++); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 142 |
| 155 EXPECT_EQ("DUMMY2", GetCurrentText()); | 143 EXPECT_EQ("DUMMY2", GetCurrentText()); |
| 156 | 144 |
| 157 while (GetToastSerial() != 3) | 145 while (GetToastSerial() != 3) |
| 158 base::RunLoop().RunUntilIdle(); | 146 base::RunLoop().RunUntilIdle(); |
| 159 | 147 |
| 160 EXPECT_EQ("DUMMY3", GetCurrentText()); | 148 EXPECT_EQ("DUMMY3", GetCurrentText()); |
| 161 } | 149 } |
| 162 | 150 |
| 163 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { | 151 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { |
| 164 ShelfLayoutManager* shelf = | 152 WmShelf* shelf = WmShelf::ForPrimaryDisplay(); |
| 165 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 153 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
| 166 SetShelfState(ash::SHELF_VISIBLE); | 154 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 167 SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM); | |
| 168 | 155 |
| 169 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 156 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 170 EXPECT_EQ(1, GetToastSerial()); | 157 EXPECT_EQ(1, GetToastSerial()); |
| 171 | 158 |
| 172 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 159 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 173 gfx::Rect root_bounds = | 160 gfx::Rect root_bounds = |
| 174 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 161 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 175 | 162 |
| 176 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 163 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 177 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 164 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 178 | 165 |
| 179 if (SupportsHostWindowResize()) { | 166 if (SupportsHostWindowResize()) { |
| 180 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() | 167 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() |
| 181 // doesn't return correct value. | 168 // doesn't return correct value. |
| 182 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 169 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 183 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 170 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 184 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); | 171 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); |
| 185 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, | 172 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, |
| 186 toast_bounds.bottom()); | 173 toast_bounds.bottom()); |
| 187 } | 174 } |
| 188 } | 175 } |
| 189 | 176 |
| 190 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { | 177 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { |
| 191 std::unique_ptr<aura::Window> window( | 178 std::unique_ptr<aura::Window> window( |
| 192 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 179 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
| 193 | 180 |
| 194 ShelfLayoutManager* shelf = | 181 WmShelf* shelf = WmShelf::ForPrimaryDisplay(); |
| 195 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 182 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
| 196 SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM); | 183 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 197 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 184 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 198 shelf->LayoutShelf(); | |
| 199 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | |
| 200 | 185 |
| 201 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 186 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 202 EXPECT_EQ(1, GetToastSerial()); | 187 EXPECT_EQ(1, GetToastSerial()); |
| 203 | 188 |
| 204 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 189 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 205 gfx::Rect root_bounds = | 190 gfx::Rect root_bounds = |
| 206 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 191 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 207 | 192 |
| 208 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 193 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 209 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 194 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 210 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5, | 195 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5, |
| 211 toast_bounds.bottom()); | 196 toast_bounds.bottom()); |
| 212 } | 197 } |
| 213 | 198 |
| 214 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { | 199 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { |
| 215 ShelfLayoutManager* shelf = | 200 WmShelf* shelf = WmShelf::ForPrimaryDisplay(); |
| 216 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 201 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
| 217 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 202 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 218 SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM); | 203 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); |
| 219 SetShelfState(ash::SHELF_HIDDEN); | |
| 220 | 204 |
| 221 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 205 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 222 EXPECT_EQ(1, GetToastSerial()); | 206 EXPECT_EQ(1, GetToastSerial()); |
| 223 | 207 |
| 224 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 208 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 225 gfx::Rect root_bounds = | 209 gfx::Rect root_bounds = |
| 226 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 210 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 227 | 211 |
| 228 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 212 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 229 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 213 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 230 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 214 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
| 231 } | 215 } |
| 232 | 216 |
| 233 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { | 217 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { |
| 234 ShelfLayoutManager* shelf = | 218 WmShelf* shelf = WmShelf::ForPrimaryDisplay(); |
| 235 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 219 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 236 SetShelfState(ash::SHELF_VISIBLE); | 220 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 237 SetShelfAlignment(SHELF_ALIGNMENT_LEFT); | |
| 238 | 221 |
| 239 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 222 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 240 EXPECT_EQ(1, GetToastSerial()); | 223 EXPECT_EQ(1, GetToastSerial()); |
| 241 | 224 |
| 242 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 225 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 243 gfx::Rect root_bounds = | 226 gfx::Rect root_bounds = |
| 244 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 227 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 245 | 228 |
| 246 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 229 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 247 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 230 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
| 248 | 231 |
| 249 if (SupportsHostWindowResize()) { | 232 if (SupportsHostWindowResize()) { |
| 250 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() | 233 // If host resize is not supported then calling WmShelf::GetIdealBounds() |
|
James Cook
2016/06/24 23:20:08
The old code here is kind of bogus. There was a te
msw
2016/06/25 00:18:29
Acknowledged.
| |
| 251 // doesn't return correct value. | 234 // doesn't return correct value. |
| 252 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 235 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 253 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 236 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 254 EXPECT_EQ( | 237 EXPECT_EQ( |
| 255 shelf_bounds.right() + (root_bounds.width() - shelf_bounds.width()) / 2, | 238 shelf_bounds.right() + (root_bounds.width() - shelf_bounds.width()) / 2, |
| 256 toast_bounds.CenterPoint().x()); | 239 toast_bounds.CenterPoint().x()); |
| 257 } | 240 } |
| 258 } | 241 } |
| 259 | 242 |
| 260 TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { | 243 TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { |
| 261 if (!SupportsMultipleDisplays()) | 244 if (!SupportsMultipleDisplays()) |
| 262 return; | 245 return; |
| 263 | 246 |
| 264 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 247 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 265 display_manager->SetUnifiedDesktopEnabled(true); | 248 display_manager->SetUnifiedDesktopEnabled(true); |
| 266 UpdateDisplay("1000x500,0+600-100x500"); | 249 UpdateDisplay("1000x500,0+600-100x500"); |
| 267 | 250 |
| 268 ShelfLayoutManager* shelf = | 251 WmShelf* shelf = WmShelf::ForPrimaryDisplay(); |
| 269 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 252 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
| 270 SetShelfState(ash::SHELF_VISIBLE); | 253 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 271 SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM); | |
| 272 | 254 |
| 273 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 255 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 274 EXPECT_EQ(1, GetToastSerial()); | 256 EXPECT_EQ(1, GetToastSerial()); |
| 275 | 257 |
| 276 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 258 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 277 gfx::Rect root_bounds = | 259 gfx::Rect root_bounds = |
| 278 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 260 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 279 | 261 |
| 280 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 262 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 281 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); | 263 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); |
| 282 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 264 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 283 | 265 |
| 284 if (SupportsHostWindowResize()) { | 266 if (SupportsHostWindowResize()) { |
| 285 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() | 267 // If host resize is not supported then calling WmShelf::GetIdealBounds() |
| 286 // doesn't return correct value. | 268 // doesn't return correct value. |
| 287 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 269 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 288 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 270 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 289 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); | 271 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); |
| 290 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, | 272 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, |
| 291 toast_bounds.bottom()); | 273 toast_bounds.bottom()); |
| 292 } | 274 } |
| 293 } | 275 } |
| 294 | 276 |
| 295 TEST_F(ToastManagerTest, CancelToast) { | 277 TEST_F(ToastManagerTest, CancelToast) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 309 EXPECT_EQ("TEXT3", GetCurrentText()); | 291 EXPECT_EQ("TEXT3", GetCurrentText()); |
| 310 // Cancel the shown toast. | 292 // Cancel the shown toast. |
| 311 CancelToast(id3); | 293 CancelToast(id3); |
| 312 // Confirm that the shown toast disappears. | 294 // Confirm that the shown toast disappears. |
| 313 EXPECT_FALSE(GetCurrentOverlay()); | 295 EXPECT_FALSE(GetCurrentOverlay()); |
| 314 // Confirm that only 1 toast is shown. | 296 // Confirm that only 1 toast is shown. |
| 315 EXPECT_EQ(2, GetToastSerial()); | 297 EXPECT_EQ(2, GetToastSerial()); |
| 316 } | 298 } |
| 317 | 299 |
| 318 } // namespace ash | 300 } // namespace ash |
| OLD | NEW |