Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/shell.h" | |
| 6 #include "ash/system/toast/toast_manager.h" | |
| 7 #include "ash/test/ash_test_base.h" | |
| 8 #include "base/run_loop.h" | |
| 9 | |
| 10 namespace ash { | |
| 11 | |
| 12 // Long duration so the timeout doesn't occur. | |
| 13 const int64_t kLongLongDuration = INT64_MAX; | |
| 14 | |
| 15 class DummyEvent : public ui::Event { | |
| 16 public: | |
| 17 DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {} | |
| 18 ~DummyEvent() override {} | |
| 19 }; | |
| 20 | |
| 21 class ToastManagerTest : public test::AshTestBase { | |
| 22 public: | |
| 23 ToastManagerTest() {} | |
| 24 ~ToastManagerTest() override {} | |
| 25 | |
| 26 private: | |
| 27 void SetUp() override { | |
| 28 test::AshTestBase::SetUp(); | |
| 29 | |
| 30 manager_ = Shell::GetInstance()->toast_manager(); | |
| 31 | |
| 32 manager_->ResetToastIdForTesting(); | |
| 33 EXPECT_EQ(0, GetToastId()); | |
| 34 } | |
| 35 | |
| 36 protected: | |
| 37 ToastManager* manager() const { return manager_; } | |
| 38 | |
| 39 int GetToastId() const { return manager_->toast_id_for_testing(); } | |
| 40 | |
| 41 ToastOverlay* GetCurrentOverlay() const { | |
|
oshima
2016/03/15 09:07:33
ditto
yoshiki
2016/03/15 15:04:22
Done.
| |
| 42 return manager_->GetCurrentOverlayForTesting(); | |
| 43 } | |
| 44 | |
| 45 void ClickDismissButton() { | |
| 46 GetCurrentOverlay()->ClickDismissButtonForTesting(DummyEvent()); | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 ToastManager* manager_ = nullptr; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(ToastManagerTest); | |
| 53 }; | |
| 54 | |
| 55 TEST_F(ToastManagerTest, ShowAndCloseAutomatically) { | |
| 56 manager()->Show("DUMMY", 10); | |
| 57 base::RunLoop().RunUntilIdle(); | |
| 58 | |
| 59 EXPECT_EQ(1, GetToastId()); | |
| 60 | |
| 61 while (GetCurrentOverlay() != nullptr) | |
| 62 base::RunLoop().RunUntilIdle(); | |
| 63 } | |
| 64 | |
| 65 TEST_F(ToastManagerTest, ShowAndCloseManually) { | |
| 66 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); | |
| 67 base::RunLoop().RunUntilIdle(); | |
| 68 | |
| 69 EXPECT_EQ(1, GetToastId()); | |
| 70 | |
| 71 ClickDismissButton(); | |
| 72 | |
| 73 while (GetCurrentOverlay() != nullptr) | |
| 74 base::RunLoop().RunUntilIdle(); | |
| 75 } | |
| 76 | |
| 77 TEST_F(ToastManagerTest, QueueMessage) { | |
| 78 manager()->Show("DUMMY1", 10); | |
| 79 manager()->Show("DUMMY2", 10); | |
| 80 manager()->Show("DUMMY3", 10); | |
| 81 | |
| 82 while (GetToastId() != 3) | |
| 83 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.
| |
| 84 } | |
| 85 | |
| 86 } // namespace ash | |
| OLD | NEW |