Index: ash/system/toast/toast_manager_unittest.cc |
diff --git a/ash/system/toast/toast_manager_unittest.cc b/ash/system/toast/toast_manager_unittest.cc |
index fc6ec7f6941e209ee3e12b47cd72112ffa0a6f35..e89b347d942aa193b1f2abab5e62658292b76371 100644 |
--- a/ash/system/toast/toast_manager_unittest.cc |
+++ b/ash/system/toast/toast_manager_unittest.cc |
@@ -10,6 +10,7 @@ |
#include "ash/system/toast/toast_manager.h" |
#include "ash/test/ash_test_base.h" |
#include "base/run_loop.h" |
+#include "base/strings/string_number_conversions.h" |
#include "ui/compositor/scoped_animation_duration_scale_mode.h" |
namespace ash { |
@@ -34,14 +35,14 @@ class ToastManagerTest : public test::AshTestBase { |
manager_ = Shell::GetInstance()->toast_manager(); |
- manager_->ResetToastIdForTesting(); |
- EXPECT_EQ(0, GetToastId()); |
+ manager_->ResetSerialForTesting(); |
+ EXPECT_EQ(0, GetToastSerial()); |
} |
protected: |
ToastManager* manager() { return manager_; } |
- int GetToastId() { return manager_->toast_id_for_testing(); } |
+ int GetToastSerial() { return manager_->serial_for_testing(); } |
ToastOverlay* GetCurrentOverlay() { |
return manager_->GetCurrentOverlayForTesting(); |
@@ -76,25 +77,34 @@ class ToastManagerTest : public test::AshTestBase { |
behavior); |
} |
+ std::string ShowToast(const std::string& text, uint64_t duration) { |
+ std::string id = "TOAST_ID_" + base::UintToString(serial_++); |
+ manager()->Show(ToastData(id, text, duration)); |
+ return id; |
+ } |
+ |
+ void CancelToast(const std::string& id) { manager()->Cancel(id); } |
+ |
private: |
ToastManager* manager_ = nullptr; |
+ unsigned int serial_ = 0; |
DISALLOW_COPY_AND_ASSIGN(ToastManagerTest); |
}; |
TEST_F(ToastManagerTest, ShowAndCloseAutomatically) { |
- manager()->Show("DUMMY", 10); |
+ ShowToast("DUMMY", 10); |
- EXPECT_EQ(1, GetToastId()); |
+ EXPECT_EQ(1, GetToastSerial()); |
while (GetCurrentOverlay() != nullptr) |
base::RunLoop().RunUntilIdle(); |
} |
TEST_F(ToastManagerTest, ShowAndCloseManually) { |
- manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
+ ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
- EXPECT_EQ(1, GetToastId()); |
+ EXPECT_EQ(1, GetToastSerial()); |
EXPECT_FALSE(GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()); |
@@ -107,11 +117,11 @@ TEST_F(ToastManagerTest, ShowAndCloseManuallyDuringAnimation) { |
ui::ScopedAnimationDurationScaleMode slow_animation_duration( |
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); |
- manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
+ ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
EXPECT_TRUE(GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()); |
base::RunLoop().RunUntilIdle(); |
- EXPECT_EQ(1, GetToastId()); |
+ EXPECT_EQ(1, GetToastSerial()); |
EXPECT_TRUE(GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()); |
// Close it during animation. |
@@ -122,19 +132,19 @@ TEST_F(ToastManagerTest, ShowAndCloseManuallyDuringAnimation) { |
} |
TEST_F(ToastManagerTest, QueueMessage) { |
- manager()->Show("DUMMY1", 10); |
- manager()->Show("DUMMY2", 10); |
- manager()->Show("DUMMY3", 10); |
+ ShowToast("DUMMY1", 10); |
+ ShowToast("DUMMY2", 10); |
+ ShowToast("DUMMY3", 10); |
- EXPECT_EQ(1, GetToastId()); |
+ EXPECT_EQ(1, GetToastSerial()); |
EXPECT_EQ("DUMMY1", GetCurrentText()); |
- while (GetToastId() != 2) |
+ while (GetToastSerial() != 2) |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ("DUMMY2", GetCurrentText()); |
- while (GetToastId() != 3) |
+ while (GetToastSerial() != 3) |
base::RunLoop().RunUntilIdle(); |
EXPECT_EQ("DUMMY3", GetCurrentText()); |
@@ -146,8 +156,8 @@ TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { |
SetShelfState(ash::SHELF_VISIBLE); |
SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM); |
- manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
- EXPECT_EQ(1, GetToastId()); |
+ ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
+ EXPECT_EQ(1, GetToastSerial()); |
gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
gfx::Rect root_bounds = |
@@ -178,8 +188,8 @@ TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { |
shelf->LayoutShelf(); |
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
- manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
- EXPECT_EQ(1, GetToastId()); |
+ ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
+ EXPECT_EQ(1, GetToastSerial()); |
gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
gfx::Rect root_bounds = |
@@ -198,8 +208,8 @@ TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { |
SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM); |
SetShelfState(ash::SHELF_HIDDEN); |
- manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
- EXPECT_EQ(1, GetToastId()); |
+ ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
+ EXPECT_EQ(1, GetToastSerial()); |
gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
gfx::Rect root_bounds = |
@@ -216,8 +226,8 @@ TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { |
SetShelfState(ash::SHELF_VISIBLE); |
SetShelfAlignment(wm::SHELF_ALIGNMENT_LEFT); |
- manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
- EXPECT_EQ(1, GetToastId()); |
+ ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
+ EXPECT_EQ(1, GetToastSerial()); |
gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
gfx::Rect root_bounds = |
@@ -250,8 +260,8 @@ TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { |
SetShelfState(ash::SHELF_VISIBLE); |
SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM); |
- manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
- EXPECT_EQ(1, GetToastId()); |
+ ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
+ EXPECT_EQ(1, GetToastSerial()); |
gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
gfx::Rect root_bounds = |
@@ -272,4 +282,22 @@ TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { |
} |
} |
+TEST_F(ToastManagerTest, CancelToast) { |
+ std::string id1 = ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
+ std::string id2 = ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); |
+ |
+ // Confirm that the first toast is shown. |
+ EXPECT_TRUE(GetCurrentOverlay()); |
+ // Cancel the queued toast. |
+ CancelToast(id2); |
+ // Confirm that the shown toast is still visible. |
+ EXPECT_TRUE(GetCurrentOverlay()); |
+ // Cancel the shown toast. |
+ CancelToast(id1); |
+ // Confirm that the shown toast disappears. |
+ EXPECT_FALSE(GetCurrentOverlay()); |
+ // Confirm that only 1 toast is shown. |
+ EXPECT_EQ(1, GetToastSerial()); |
+} |
+ |
} // namespace ash |