Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e73305ddd904bcd1b139ac902d81ccad7d133c04 |
| --- /dev/null |
| +++ b/ash/system/toast/toast_manager_unittest.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/shell.h" |
| +#include "ash/system/toast/toast_manager.h" |
| +#include "ash/test/ash_test_base.h" |
| +#include "base/run_loop.h" |
| + |
| +namespace ash { |
| + |
| +// Long duration so the timeout doesn't occur. |
| +const int64_t kLongLongDuration = INT64_MAX; |
| + |
| +class DummyEvent : public ui::Event { |
| + public: |
| + DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {} |
| + ~DummyEvent() override {} |
| +}; |
| + |
| +class ToastManagerTest : public test::AshTestBase { |
| + public: |
| + ToastManagerTest() {} |
| + ~ToastManagerTest() override {} |
| + |
| + private: |
| + void SetUp() override { |
| + test::AshTestBase::SetUp(); |
| + |
| + manager_ = Shell::GetInstance()->toast_manager(); |
| + |
| + manager_->ResetToastIdForTesting(); |
| + EXPECT_EQ(0, GetToastId()); |
| + } |
| + |
| + protected: |
| + ToastManager* manager() const { return manager_; } |
| + |
| + int GetToastId() const { return manager_->toast_id_for_testing(); } |
| + |
| + ToastOverlay* GetCurrentOverlay() const { |
|
oshima
2016/03/15 09:07:33
ditto
yoshiki
2016/03/15 15:04:22
Done.
|
| + return manager_->GetCurrentOverlayForTesting(); |
| + } |
| + |
| + void ClickDismissButton() { |
| + GetCurrentOverlay()->ClickDismissButtonForTesting(DummyEvent()); |
| + } |
| + |
| + private: |
| + ToastManager* manager_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ToastManagerTest); |
| +}; |
| + |
| +TEST_F(ToastManagerTest, ShowAndCloseAutomatically) { |
| + manager()->Show("DUMMY", 10); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(1, GetToastId()); |
| + |
| + while (GetCurrentOverlay() != nullptr) |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| + |
| +TEST_F(ToastManagerTest, ShowAndCloseManually) { |
| + manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + EXPECT_EQ(1, GetToastId()); |
| + |
| + ClickDismissButton(); |
| + |
| + while (GetCurrentOverlay() != nullptr) |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| + |
| +TEST_F(ToastManagerTest, QueueMessage) { |
| + manager()->Show("DUMMY1", 10); |
| + manager()->Show("DUMMY2", 10); |
| + manager()->Show("DUMMY3", 10); |
| + |
| + while (GetToastId() != 3) |
| + base::RunLoop().RunUntilIdle(); |
|
oshima
2016/03/15 09:07:32
can you check each step is showing the correct toa
yoshiki
2016/03/15 15:04:22
Done.
|
| +} |
| + |
| +} // namespace ash |