| 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/display/display_manager.h" | 5 #include "ash/display/display_manager.h" |
| 6 #include "ash/screen_util.h" | 6 #include "ash/screen_util.h" |
| 7 #include "ash/shelf/shelf.h" | 7 #include "ash/shelf/shelf.h" |
| 8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/system/toast/toast_manager.h" | 10 #include "ash/system/toast/toast_manager.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 13 | 14 |
| 14 namespace ash { | 15 namespace ash { |
| 15 | 16 |
| 16 // Long duration so the timeout doesn't occur. | 17 // Long duration so the timeout doesn't occur. |
| 17 const int64_t kLongLongDuration = INT64_MAX; | 18 const int64_t kLongLongDuration = INT64_MAX; |
| 18 | 19 |
| 19 class DummyEvent : public ui::Event { | 20 class DummyEvent : public ui::Event { |
| 20 public: | 21 public: |
| 21 DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {} | 22 DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {} |
| 22 ~DummyEvent() override {} | 23 ~DummyEvent() override {} |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 77 } |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 ToastManager* manager_ = nullptr; | 80 ToastManager* manager_ = nullptr; |
| 80 | 81 |
| 81 DISALLOW_COPY_AND_ASSIGN(ToastManagerTest); | 82 DISALLOW_COPY_AND_ASSIGN(ToastManagerTest); |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 TEST_F(ToastManagerTest, ShowAndCloseAutomatically) { | 85 TEST_F(ToastManagerTest, ShowAndCloseAutomatically) { |
| 85 manager()->Show("DUMMY", 10); | 86 manager()->Show("DUMMY", 10); |
| 86 base::RunLoop().RunUntilIdle(); | |
| 87 | 87 |
| 88 EXPECT_EQ(1, GetToastId()); | 88 EXPECT_EQ(1, GetToastId()); |
| 89 | 89 |
| 90 while (GetCurrentOverlay() != nullptr) | 90 while (GetCurrentOverlay() != nullptr) |
| 91 base::RunLoop().RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST_F(ToastManagerTest, ShowAndCloseManually) { | 94 TEST_F(ToastManagerTest, ShowAndCloseManually) { |
| 95 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); | 95 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 96 |
| 97 EXPECT_EQ(1, GetToastId()); |
| 98 |
| 99 EXPECT_FALSE(GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()); |
| 100 |
| 101 ClickDismissButton(); |
| 102 |
| 103 EXPECT_EQ(nullptr, GetCurrentOverlay()); |
| 104 } |
| 105 |
| 106 TEST_F(ToastManagerTest, ShowAndCloseManuallyDuringAnimation) { |
| 107 ui::ScopedAnimationDurationScaleMode slow_animation_duration( |
| 108 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 109 |
| 110 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 111 EXPECT_TRUE(GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()); |
| 96 base::RunLoop().RunUntilIdle(); | 112 base::RunLoop().RunUntilIdle(); |
| 97 | 113 |
| 98 EXPECT_EQ(1, GetToastId()); | 114 EXPECT_EQ(1, GetToastId()); |
| 115 EXPECT_TRUE(GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()); |
| 99 | 116 |
| 117 // Close it during animation. |
| 100 ClickDismissButton(); | 118 ClickDismissButton(); |
| 101 | 119 |
| 102 while (GetCurrentOverlay() != nullptr) | 120 while (GetCurrentOverlay() != nullptr) |
| 103 base::RunLoop().RunUntilIdle(); | 121 base::RunLoop().RunUntilIdle(); |
| 104 } | 122 } |
| 105 | 123 |
| 106 TEST_F(ToastManagerTest, QueueMessage) { | 124 TEST_F(ToastManagerTest, QueueMessage) { |
| 107 manager()->Show("DUMMY1", 10); | 125 manager()->Show("DUMMY1", 10); |
| 108 manager()->Show("DUMMY2", 10); | 126 manager()->Show("DUMMY2", 10); |
| 109 manager()->Show("DUMMY3", 10); | 127 manager()->Show("DUMMY3", 10); |
| 110 | 128 |
| 111 while (GetToastId() != 1) | 129 EXPECT_EQ(1, GetToastId()); |
| 112 base::RunLoop().RunUntilIdle(); | |
| 113 | |
| 114 EXPECT_EQ("DUMMY1", GetCurrentText()); | 130 EXPECT_EQ("DUMMY1", GetCurrentText()); |
| 115 | 131 |
| 116 while (GetToastId() != 2) | 132 while (GetToastId() != 2) |
| 117 base::RunLoop().RunUntilIdle(); | 133 base::RunLoop().RunUntilIdle(); |
| 118 | 134 |
| 119 EXPECT_EQ("DUMMY2", GetCurrentText()); | 135 EXPECT_EQ("DUMMY2", GetCurrentText()); |
| 120 | 136 |
| 121 while (GetToastId() != 3) | 137 while (GetToastId() != 3) |
| 122 base::RunLoop().RunUntilIdle(); | 138 base::RunLoop().RunUntilIdle(); |
| 123 | 139 |
| 124 EXPECT_EQ("DUMMY3", GetCurrentText()); | 140 EXPECT_EQ("DUMMY3", GetCurrentText()); |
| 125 } | 141 } |
| 126 | 142 |
| 127 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { | 143 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { |
| 128 ShelfLayoutManager* shelf = | 144 ShelfLayoutManager* shelf = |
| 129 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 145 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); |
| 130 SetShelfState(ash::SHELF_VISIBLE); | 146 SetShelfState(ash::SHELF_VISIBLE); |
| 131 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); | 147 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); |
| 132 | 148 |
| 133 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); | 149 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 134 base::RunLoop().RunUntilIdle(); | |
| 135 EXPECT_EQ(1, GetToastId()); | 150 EXPECT_EQ(1, GetToastId()); |
| 136 | 151 |
| 137 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 152 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 138 gfx::Rect root_bounds = | 153 gfx::Rect root_bounds = |
| 139 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 154 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 140 | 155 |
| 141 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 156 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); |
| 142 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 157 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 143 | 158 |
| 144 if (SupportsHostWindowResize()) { | 159 if (SupportsHostWindowResize()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 157 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 172 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
| 158 | 173 |
| 159 ShelfLayoutManager* shelf = | 174 ShelfLayoutManager* shelf = |
| 160 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 175 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); |
| 161 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); | 176 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); |
| 162 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 177 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 163 shelf->LayoutShelf(); | 178 shelf->LayoutShelf(); |
| 164 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 179 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 165 | 180 |
| 166 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); | 181 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 167 base::RunLoop().RunUntilIdle(); | |
| 168 EXPECT_EQ(1, GetToastId()); | 182 EXPECT_EQ(1, GetToastId()); |
| 169 | 183 |
| 170 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 184 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 171 gfx::Rect root_bounds = | 185 gfx::Rect root_bounds = |
| 172 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 186 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 173 | 187 |
| 174 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 188 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); |
| 175 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 189 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 176 EXPECT_EQ(root_bounds.bottom() - ShelfLayoutManager::kAutoHideSize - 5, | 190 EXPECT_EQ(root_bounds.bottom() - ShelfLayoutManager::kAutoHideSize - 5, |
| 177 toast_bounds.bottom()); | 191 toast_bounds.bottom()); |
| 178 } | 192 } |
| 179 | 193 |
| 180 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { | 194 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { |
| 181 ShelfLayoutManager* shelf = | 195 ShelfLayoutManager* shelf = |
| 182 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 196 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); |
| 183 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 197 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 184 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); | 198 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); |
| 185 SetShelfState(ash::SHELF_HIDDEN); | 199 SetShelfState(ash::SHELF_HIDDEN); |
| 186 | 200 |
| 187 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); | 201 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 188 base::RunLoop().RunUntilIdle(); | |
| 189 EXPECT_EQ(1, GetToastId()); | 202 EXPECT_EQ(1, GetToastId()); |
| 190 | 203 |
| 191 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 204 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 192 gfx::Rect root_bounds = | 205 gfx::Rect root_bounds = |
| 193 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 206 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 194 | 207 |
| 195 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 208 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); |
| 196 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 209 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 197 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 210 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
| 198 } | 211 } |
| 199 | 212 |
| 200 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { | 213 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { |
| 201 ShelfLayoutManager* shelf = | 214 ShelfLayoutManager* shelf = |
| 202 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 215 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); |
| 203 SetShelfState(ash::SHELF_VISIBLE); | 216 SetShelfState(ash::SHELF_VISIBLE); |
| 204 SetShelfAlignment(ash::SHELF_ALIGNMENT_LEFT); | 217 SetShelfAlignment(ash::SHELF_ALIGNMENT_LEFT); |
| 205 | 218 |
| 206 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); | 219 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 207 base::RunLoop().RunUntilIdle(); | |
| 208 EXPECT_EQ(1, GetToastId()); | 220 EXPECT_EQ(1, GetToastId()); |
| 209 | 221 |
| 210 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 222 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 211 gfx::Rect root_bounds = | 223 gfx::Rect root_bounds = |
| 212 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 224 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 213 | 225 |
| 214 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 226 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); |
| 215 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 227 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
| 216 | 228 |
| 217 if (SupportsHostWindowResize()) { | 229 if (SupportsHostWindowResize()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 232 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 244 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 233 display_manager->SetUnifiedDesktopEnabled(true); | 245 display_manager->SetUnifiedDesktopEnabled(true); |
| 234 UpdateDisplay("1000x500,0+600-100x500"); | 246 UpdateDisplay("1000x500,0+600-100x500"); |
| 235 | 247 |
| 236 ShelfLayoutManager* shelf = | 248 ShelfLayoutManager* shelf = |
| 237 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 249 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); |
| 238 SetShelfState(ash::SHELF_VISIBLE); | 250 SetShelfState(ash::SHELF_VISIBLE); |
| 239 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); | 251 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); |
| 240 | 252 |
| 241 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); | 253 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 242 base::RunLoop().RunUntilIdle(); | |
| 243 EXPECT_EQ(1, GetToastId()); | 254 EXPECT_EQ(1, GetToastId()); |
| 244 | 255 |
| 245 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 256 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 246 gfx::Rect root_bounds = | 257 gfx::Rect root_bounds = |
| 247 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | 258 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); |
| 248 | 259 |
| 249 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); | 260 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); |
| 250 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); | 261 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); |
| 251 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 262 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 252 | 263 |
| 253 if (SupportsHostWindowResize()) { | 264 if (SupportsHostWindowResize()) { |
| 254 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() | 265 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() |
| 255 // doesn't return correct value. | 266 // doesn't return correct value. |
| 256 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 267 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 257 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 268 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 258 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); | 269 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); |
| 259 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, | 270 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, |
| 260 toast_bounds.bottom()); | 271 toast_bounds.bottom()); |
| 261 } | 272 } |
| 262 } | 273 } |
| 263 | 274 |
| 264 } // namespace ash | 275 } // namespace ash |
| OLD | NEW |