| 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" |
| 14 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 13 | 15 |
| 14 namespace ash { | 16 namespace ash { |
| 15 | 17 |
| 16 // Long duration so the timeout doesn't occur. | 18 // Long duration so the timeout doesn't occur. |
| 17 const int64_t kLongLongDuration = INT64_MAX; | 19 const int64_t kLongLongDuration = INT64_MAX; |
| 18 | 20 |
| 19 class DummyEvent : public ui::Event { | 21 class DummyEvent : public ui::Event { |
| 20 public: | 22 public: |
| 21 DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {} | 23 DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {} |
| 22 ~DummyEvent() override {} | 24 ~DummyEvent() override {} |
| 23 }; | 25 }; |
| 24 | 26 |
| 25 class ToastManagerTest : public test::AshTestBase { | 27 class ToastManagerTest : public test::AshTestBase { |
| 26 public: | 28 public: |
| 27 ToastManagerTest() {} | 29 ToastManagerTest() {} |
| 28 ~ToastManagerTest() override {} | 30 ~ToastManagerTest() override {} |
| 29 | 31 |
| 30 private: | 32 private: |
| 31 void SetUp() override { | 33 void SetUp() override { |
| 32 test::AshTestBase::SetUp(); | 34 test::AshTestBase::SetUp(); |
| 33 | 35 |
| 34 manager_ = Shell::GetInstance()->toast_manager(); | 36 manager_ = Shell::GetInstance()->toast_manager(); |
| 35 | 37 |
| 36 manager_->ResetToastIdForTesting(); | 38 manager_->ResetToastIdForTesting(); |
| 37 EXPECT_EQ(0, GetToastId()); | 39 EXPECT_EQ(0, GetToastId()); |
| 40 test_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( |
| 41 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION)); |
| 38 } | 42 } |
| 39 | 43 |
| 40 protected: | 44 protected: |
| 41 ToastManager* manager() { return manager_; } | 45 ToastManager* manager() { return manager_; } |
| 42 | 46 |
| 43 int GetToastId() { return manager_->toast_id_for_testing(); } | 47 int GetToastId() { return manager_->toast_id_for_testing(); } |
| 44 | 48 |
| 45 ToastOverlay* GetCurrentOverlay() { | 49 ToastOverlay* GetCurrentOverlay() { |
| 46 return manager_->GetCurrentOverlayForTesting(); | 50 return manager_->GetCurrentOverlayForTesting(); |
| 47 } | 51 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 71 } | 75 } |
| 72 | 76 |
| 73 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior) { | 77 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior) { |
| 74 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetAutoHideBehavior( | 78 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetAutoHideBehavior( |
| 75 behavior); | 79 behavior); |
| 76 } | 80 } |
| 77 | 81 |
| 78 private: | 82 private: |
| 79 ToastManager* manager_ = nullptr; | 83 ToastManager* manager_ = nullptr; |
| 80 | 84 |
| 85 scoped_ptr<ui::ScopedAnimationDurationScaleMode> test_duration_mode_; |
| 86 |
| 81 DISALLOW_COPY_AND_ASSIGN(ToastManagerTest); | 87 DISALLOW_COPY_AND_ASSIGN(ToastManagerTest); |
| 82 }; | 88 }; |
| 83 | 89 |
| 84 TEST_F(ToastManagerTest, ShowAndCloseAutomatically) { | 90 TEST_F(ToastManagerTest, ShowAndCloseAutomatically) { |
| 85 manager()->Show("DUMMY", 10); | 91 manager()->Show("DUMMY", 10); |
| 86 base::RunLoop().RunUntilIdle(); | 92 base::RunLoop().RunUntilIdle(); |
| 87 | 93 |
| 88 EXPECT_EQ(1, GetToastId()); | 94 EXPECT_EQ(1, GetToastId()); |
| 89 | 95 |
| 90 while (GetCurrentOverlay() != nullptr) | 96 while (GetCurrentOverlay() != nullptr) |
| 91 base::RunLoop().RunUntilIdle(); | 97 base::RunLoop().RunUntilIdle(); |
| 92 } | 98 } |
| 93 | 99 |
| 94 TEST_F(ToastManagerTest, ShowAndCloseManually) { | 100 TEST_F(ToastManagerTest, ShowAndCloseManually) { |
| 95 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); | 101 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 96 base::RunLoop().RunUntilIdle(); | 102 base::RunLoop().RunUntilIdle(); |
| 97 | 103 |
| 98 EXPECT_EQ(1, GetToastId()); | 104 EXPECT_EQ(1, GetToastId()); |
| 99 | 105 |
| 106 while (GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()) |
| 107 base::RunLoop().RunUntilIdle(); |
| 108 |
| 100 ClickDismissButton(); | 109 ClickDismissButton(); |
| 101 | 110 |
| 102 while (GetCurrentOverlay() != nullptr) | 111 while (GetCurrentOverlay() != nullptr) |
| 112 base::RunLoop().RunUntilIdle(); |
| 113 } |
| 114 |
| 115 TEST_F(ToastManagerTest, ShowAndCloseManuallyDuringAnimation) { |
| 116 ui::ScopedAnimationDurationScaleMode slow_animation_duration( |
| 117 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
| 118 |
| 119 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| 120 base::RunLoop().RunUntilIdle(); |
| 121 |
| 122 EXPECT_EQ(1, GetToastId()); |
| 123 EXPECT_TRUE(GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()); |
| 124 |
| 125 // Close it during animation. |
| 126 ClickDismissButton(); |
| 127 |
| 128 while (GetCurrentOverlay() != nullptr) |
| 103 base::RunLoop().RunUntilIdle(); | 129 base::RunLoop().RunUntilIdle(); |
| 104 } | 130 } |
| 105 | 131 |
| 106 TEST_F(ToastManagerTest, QueueMessage) { | 132 TEST_F(ToastManagerTest, QueueMessage) { |
| 107 manager()->Show("DUMMY1", 10); | 133 manager()->Show("DUMMY1", 10); |
| 108 manager()->Show("DUMMY2", 10); | 134 manager()->Show("DUMMY2", 10); |
| 109 manager()->Show("DUMMY3", 10); | 135 manager()->Show("DUMMY3", 10); |
| 110 | 136 |
| 111 while (GetToastId() != 1) | 137 while (GetToastId() != 1) |
| 112 base::RunLoop().RunUntilIdle(); | 138 base::RunLoop().RunUntilIdle(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // doesn't return correct value. | 281 // doesn't return correct value. |
| 256 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 282 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 257 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 283 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 258 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); | 284 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); |
| 259 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, | 285 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, |
| 260 toast_bounds.bottom()); | 286 toast_bounds.bottom()); |
| 261 } | 287 } |
| 262 } | 288 } |
| 263 | 289 |
| 264 } // namespace ash | 290 } // namespace ash |
| OLD | NEW |