OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/system/tray/tray_info_label.h" | |
6 #include "ash/test/ash_test_base.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace ash { | |
10 namespace test { | |
11 | |
12 namespace { | |
13 | |
14 const int clickableMessageId = 1; | |
Kyle Horimoto
2017/07/13 23:15:36
nit: Constants are prefixed with a k: (e.g., kClic
lesliewatkins
2017/07/14 06:41:52
Acknowledged.
I really would prefer to keep the c
Kyle Horimoto
2017/07/14 17:54:22
The reason that I do not like these is because the
lesliewatkins
2017/07/14 20:43:16
Alrighty, done.
| |
15 const int nonClickableMessageId = 0; | |
16 | |
17 class TestClickEvent : public ui::Event { | |
18 public: | |
19 TestClickEvent() : ui::Event(ui::ET_MOUSE_PRESSED, base::TimeTicks(), 0) {} | |
20 }; | |
21 | |
22 class TestDelegate : public TrayInfoLabel::Delegate { | |
23 public: | |
24 TestDelegate() : clicked_message_ids_(std::vector<int>()) {} | |
25 | |
26 const std::vector<int>& clicked_message_ids() { return clicked_message_ids_; } | |
27 | |
28 void OnLabelClicked(int message_id) override { | |
29 clicked_message_ids_.push_back(message_id); | |
30 } | |
31 | |
32 bool IsLabelClickable(int message_id) override { | |
33 return clickableMessageId == message_id; | |
34 } | |
35 | |
36 private: | |
37 std::vector<int> clicked_message_ids_; | |
38 }; | |
39 | |
40 } // namespace | |
41 | |
42 class TrayInfoLabelTest : public AshTestBase { | |
43 public: | |
44 std::unique_ptr<TrayInfoLabel> label_; | |
Kyle Horimoto
2017/07/13 23:15:36
nit: Move these to the bottom of the test class -
lesliewatkins
2017/07/14 06:41:52
Done.
| |
45 std::unique_ptr<TestDelegate> delegate_; | |
46 | |
47 void CreateLabel(bool use_delegate, int message_id) { | |
48 if (use_delegate) | |
49 delegate_ = base::MakeUnique<TestDelegate>() else delegate_ = nullptr; | |
Kyle Horimoto
2017/07/13 23:15:36
Instead of setting delegate_ to nullptr in the els
lesliewatkins
2017/07/14 06:41:52
Done.
| |
50 | |
51 label_ = base::MakeUnique<TrayInfoLabel>(delegate_.get(), message_id); | |
52 } | |
53 | |
54 void UpdateLabel(int message_id) { label_->Update(message_id); } | |
Kyle Horimoto
2017/07/13 23:15:37
No need for this function - Update() is already a
lesliewatkins
2017/07/14 06:41:52
Done.
| |
55 | |
56 void ClickOnLabel() { label_->PerformAction(TestClickEvent()); } | |
Kyle Horimoto
2017/07/13 23:15:36
Let's also verify that the correct bool is returne
lesliewatkins
2017/07/14 06:41:52
Done.
| |
57 | |
58 VerifyMessageId(int expected_message_id) { | |
Kyle Horimoto
2017/07/13 23:15:37
No need for this function either. In general, you
lesliewatkins
2017/07/14 06:41:52
Done.
| |
59 EXPECT_EQ(expected_message_id, label_->message_id_); | |
60 } | |
61 | |
62 void VerifyClickability(bool expected_clickable) { | |
63 EXPECT_EQ(expected_clickable, label_->IsClickable()); | |
64 } | |
65 | |
66 void VerifyClicks(const std::vector<int> expected_clicked_message_ids) { | |
67 if (!delegate_) { | |
68 EXPECT_TRUE(expected_clicked_message_ids.empty()); | |
69 return; | |
70 } | |
71 | |
72 EXPECT_EQ(expected_clicked_message_ids, delegate_->clicked_message_ids()); | |
73 } | |
74 | |
75 void VerifyNoClicks() { VerifyClicks(std::vector<int>()); } | |
76 }; | |
77 | |
78 TEST_F(TrayInfoLabelTest, NoDelegate) { | |
79 CreateLabel(false, nonClickableMessageId); | |
Kyle Horimoto
2017/07/13 23:15:36
nit: /* use_delegate */
lesliewatkins
2017/07/14 06:41:52
Done.
| |
80 | |
81 VerifyClickability(false); | |
Kyle Horimoto
2017/07/13 23:15:37
After this, update the label to another message ID
lesliewatkins
2017/07/14 06:41:52
Done.
| |
82 } | |
83 | |
84 TEST_F(TrayInfoLabelTest, NonClickableDelegate) { | |
Kyle Horimoto
2017/07/13 23:15:36
Instead of having a delegate which is entirely cli
lesliewatkins
2017/07/14 06:41:52
Done.
| |
85 CreateLabel(true, nonClickableMessageId); | |
86 | |
87 VerifyClickability(false); | |
88 } | |
89 | |
90 TEST_F(TrayInfoLabelTest, ClickableDelegate) { | |
91 CreateLabel(true, clickableMessageId); | |
92 | |
93 VerifyClickability(true); | |
94 } | |
95 | |
96 TEST_F(TrayInfoLabelTest, PerformAction) { | |
Kyle Horimoto
2017/07/13 23:15:36
To test performing actions, verify that you can cl
lesliewatkins
2017/07/14 06:41:52
Done.
Kyle Horimoto
2017/07/14 17:54:21
Hey Leslie, doesn't look like this was done. Your
lesliewatkins
2017/07/14 20:43:16
Okay, I added some more clicks.
| |
97 CreateLabel(true, clickableMessageId); | |
98 VerifyNoClicks(); | |
99 | |
100 ClickOnLabel(); | |
101 | |
102 VerifyClicks(std::vector<int>({clickableMessageId})); | |
103 } | |
104 | |
105 TEST_F(TrayInfoLabelTest, Update) { | |
106 CreateLabel(true, nonClickableMessageId); | |
107 VerifyMessageId(nonClickableMessageId); | |
108 VerifyClickability(false); | |
109 | |
110 UpdateLabel(clickableMessageId); | |
111 VerifyMessageId(clickableMessageId); | |
112 VerifyClickability(true); | |
113 } | |
114 | |
115 } // namespace test | |
116 } // namespace ash | |
OLD | NEW |