Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: ash/system/toast/toast_manager_unittest.cc

Issue 1782793002: Ash: Implement Toasts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 void TearDown() override { test::AshTestBase::TearDown(); }
oshima 2016/03/11 09:40:24 this isn't necessary
yoshiki 2016/03/11 14:30:35 Done.
37
38 protected:
39 ToastManager* manager() const { return manager_; }
40
41 int GetToastId() const { return manager_->toast_id_for_testing(); }
oshima 2016/03/11 09:40:24 new line
yoshiki 2016/03/11 14:30:35 Done.
42 ToastOverlay* GetCurrentOverlay() const {
43 return manager_->GetCurrentOverlayForTesting();
44 }
oshima 2016/03/11 09:40:24 new line
yoshiki 2016/03/11 14:30:34 Done.
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 }
oshima 2016/03/11 09:40:24 can you also add the cases where messages are queu
yoshiki 2016/03/11 14:30:34 Done.
76
77 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698