| 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/system/toast/toast_manager.h" | 5 #include "ash/system/toast/toast_manager.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/config.h" | 7 #include "ash/public/cpp/config.h" |
| 8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
| 9 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_constants.h" | 10 #include "ash/shelf/shelf_constants.h" |
| 10 #include "ash/shelf/wm_shelf.h" | |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/wm_window.h" | 13 #include "ash/wm_window.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 19 #include "ui/display/manager/display_manager.h" | 19 #include "ui/display/manager/display_manager.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 EXPECT_EQ(base::ASCIIToUTF16("DUMMY2"), GetCurrentText()); | 174 EXPECT_EQ(base::ASCIIToUTF16("DUMMY2"), GetCurrentText()); |
| 175 | 175 |
| 176 while (GetToastSerial() != 3) | 176 while (GetToastSerial() != 3) |
| 177 base::RunLoop().RunUntilIdle(); | 177 base::RunLoop().RunUntilIdle(); |
| 178 | 178 |
| 179 EXPECT_EQ(base::ASCIIToUTF16("DUMMY3"), GetCurrentText()); | 179 EXPECT_EQ(base::ASCIIToUTF16("DUMMY3"), GetCurrentText()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { | 182 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { |
| 183 WmShelf* shelf = GetPrimaryShelf(); | 183 Shelf* shelf = GetPrimaryShelf(); |
| 184 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 184 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->alignment()); |
| 185 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); | 185 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 186 | 186 |
| 187 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 187 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 188 EXPECT_EQ(1, GetToastSerial()); | 188 EXPECT_EQ(1, GetToastSerial()); |
| 189 | 189 |
| 190 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 190 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 191 gfx::Rect root_bounds = | 191 gfx::Rect root_bounds = |
| 192 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); | 192 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); |
| 193 | 193 |
| 194 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 194 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 195 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 195 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 196 | 196 |
| 197 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 197 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 198 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 198 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 199 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); | 199 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); |
| 200 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, | 200 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, |
| 201 toast_bounds.bottom()); | 201 toast_bounds.bottom()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { | 204 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { |
| 205 std::unique_ptr<aura::Window> window( | 205 std::unique_ptr<aura::Window> window( |
| 206 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 206 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
| 207 | 207 |
| 208 WmShelf* shelf = GetPrimaryShelf(); | 208 Shelf* shelf = GetPrimaryShelf(); |
| 209 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 209 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->alignment()); |
| 210 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 210 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 211 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 211 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 212 | 212 |
| 213 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 213 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 214 EXPECT_EQ(1, GetToastSerial()); | 214 EXPECT_EQ(1, GetToastSerial()); |
| 215 | 215 |
| 216 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 216 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 217 gfx::Rect root_bounds = | 217 gfx::Rect root_bounds = |
| 218 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); | 218 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); |
| 219 | 219 |
| 220 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 220 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 221 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 221 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 222 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5, | 222 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5, |
| 223 toast_bounds.bottom()); | 223 toast_bounds.bottom()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { | 226 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { |
| 227 WmShelf* shelf = GetPrimaryShelf(); | 227 Shelf* shelf = GetPrimaryShelf(); |
| 228 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 228 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->alignment()); |
| 229 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 229 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 230 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); | 230 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); |
| 231 | 231 |
| 232 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 232 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 233 EXPECT_EQ(1, GetToastSerial()); | 233 EXPECT_EQ(1, GetToastSerial()); |
| 234 | 234 |
| 235 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 235 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 236 gfx::Rect root_bounds = | 236 gfx::Rect root_bounds = |
| 237 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); | 237 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); |
| 238 | 238 |
| 239 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 239 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 240 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 240 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 241 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 241 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
| 242 } | 242 } |
| 243 | 243 |
| 244 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { | 244 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { |
| 245 WmShelf* shelf = GetPrimaryShelf(); | 245 Shelf* shelf = GetPrimaryShelf(); |
| 246 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); | 246 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 247 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | 247 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 248 | 248 |
| 249 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 249 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 250 EXPECT_EQ(1, GetToastSerial()); | 250 EXPECT_EQ(1, GetToastSerial()); |
| 251 | 251 |
| 252 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 252 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 253 gfx::RectF precise_toast_bounds(toast_bounds); | 253 gfx::RectF precise_toast_bounds(toast_bounds); |
| 254 gfx::Rect root_bounds = | 254 gfx::Rect root_bounds = |
| 255 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); | 255 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); |
| 256 | 256 |
| 257 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 257 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 258 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 258 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
| 259 | 259 |
| 260 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 260 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 261 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 261 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 262 EXPECT_NEAR( | 262 EXPECT_NEAR( |
| 263 shelf_bounds.right() + (root_bounds.width() - shelf_bounds.width()) / 2.0, | 263 shelf_bounds.right() + (root_bounds.width() - shelf_bounds.width()) / 2.0, |
| 264 precise_toast_bounds.CenterPoint().x(), 1.f /* accepted error */); | 264 precise_toast_bounds.CenterPoint().x(), 1.f /* accepted error */); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { | 267 TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { |
| 268 // TODO: needs unified mode. http://crbug.com/698024. | 268 // TODO: needs unified mode. http://crbug.com/698024. |
| 269 if (Shell::GetAshConfig() == Config::MASH) | 269 if (Shell::GetAshConfig() == Config::MASH) |
| 270 return; | 270 return; |
| 271 | 271 |
| 272 display_manager()->SetUnifiedDesktopEnabled(true); | 272 display_manager()->SetUnifiedDesktopEnabled(true); |
| 273 UpdateDisplay("1000x500,0+600-100x500"); | 273 UpdateDisplay("1000x500,0+600-100x500"); |
| 274 | 274 |
| 275 WmShelf* shelf = GetPrimaryShelf(); | 275 Shelf* shelf = GetPrimaryShelf(); |
| 276 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 276 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->alignment()); |
| 277 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); | 277 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 278 | 278 |
| 279 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 279 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 280 EXPECT_EQ(1, GetToastSerial()); | 280 EXPECT_EQ(1, GetToastSerial()); |
| 281 | 281 |
| 282 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 282 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 283 gfx::Rect root_bounds = | 283 gfx::Rect root_bounds = |
| 284 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); | 284 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window()); |
| 285 | 285 |
| 286 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 286 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 311 EXPECT_EQ(base::ASCIIToUTF16("TEXT3"), GetCurrentText()); | 311 EXPECT_EQ(base::ASCIIToUTF16("TEXT3"), GetCurrentText()); |
| 312 // Cancel the shown toast. | 312 // Cancel the shown toast. |
| 313 CancelToast(id3); | 313 CancelToast(id3); |
| 314 // Confirm that the shown toast disappears. | 314 // Confirm that the shown toast disappears. |
| 315 EXPECT_FALSE(GetCurrentOverlay()); | 315 EXPECT_FALSE(GetCurrentOverlay()); |
| 316 // Confirm that only 1 toast is shown. | 316 // Confirm that only 1 toast is shown. |
| 317 EXPECT_EQ(2, GetToastSerial()); | 317 EXPECT_EQ(2, GetToastSerial()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace ash | 320 } // namespace ash |
| OLD | NEW |