Index: ash/system/tray/tray_info_label_unittest.cc |
diff --git a/ash/system/tray/tray_info_label_unittest.cc b/ash/system/tray/tray_info_label_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9bffc1dddbd0c1908a236508d41fa170319f2919 |
--- /dev/null |
+++ b/ash/system/tray/tray_info_label_unittest.cc |
@@ -0,0 +1,116 @@ |
+// Copyright 2017 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/system/tray/tray_info_label.h" |
+#include "ash/test/ash_test_base.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace ash { |
+namespace test { |
+ |
+namespace { |
+ |
+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.
|
+const int nonClickableMessageId = 0; |
+ |
+class TestClickEvent : public ui::Event { |
+ public: |
+ TestClickEvent() : ui::Event(ui::ET_MOUSE_PRESSED, base::TimeTicks(), 0) {} |
+}; |
+ |
+class TestDelegate : public TrayInfoLabel::Delegate { |
+ public: |
+ TestDelegate() : clicked_message_ids_(std::vector<int>()) {} |
+ |
+ const std::vector<int>& clicked_message_ids() { return clicked_message_ids_; } |
+ |
+ void OnLabelClicked(int message_id) override { |
+ clicked_message_ids_.push_back(message_id); |
+ } |
+ |
+ bool IsLabelClickable(int message_id) override { |
+ return clickableMessageId == message_id; |
+ } |
+ |
+ private: |
+ std::vector<int> clicked_message_ids_; |
+}; |
+ |
+} // namespace |
+ |
+class TrayInfoLabelTest : public AshTestBase { |
+ public: |
+ 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.
|
+ std::unique_ptr<TestDelegate> delegate_; |
+ |
+ void CreateLabel(bool use_delegate, int message_id) { |
+ if (use_delegate) |
+ 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.
|
+ |
+ label_ = base::MakeUnique<TrayInfoLabel>(delegate_.get(), message_id); |
+ } |
+ |
+ 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.
|
+ |
+ 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.
|
+ |
+ 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.
|
+ EXPECT_EQ(expected_message_id, label_->message_id_); |
+ } |
+ |
+ void VerifyClickability(bool expected_clickable) { |
+ EXPECT_EQ(expected_clickable, label_->IsClickable()); |
+ } |
+ |
+ void VerifyClicks(const std::vector<int> expected_clicked_message_ids) { |
+ if (!delegate_) { |
+ EXPECT_TRUE(expected_clicked_message_ids.empty()); |
+ return; |
+ } |
+ |
+ EXPECT_EQ(expected_clicked_message_ids, delegate_->clicked_message_ids()); |
+ } |
+ |
+ void VerifyNoClicks() { VerifyClicks(std::vector<int>()); } |
+}; |
+ |
+TEST_F(TrayInfoLabelTest, NoDelegate) { |
+ CreateLabel(false, nonClickableMessageId); |
Kyle Horimoto
2017/07/13 23:15:36
nit: /* use_delegate */
lesliewatkins
2017/07/14 06:41:52
Done.
|
+ |
+ 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.
|
+} |
+ |
+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.
|
+ CreateLabel(true, nonClickableMessageId); |
+ |
+ VerifyClickability(false); |
+} |
+ |
+TEST_F(TrayInfoLabelTest, ClickableDelegate) { |
+ CreateLabel(true, clickableMessageId); |
+ |
+ VerifyClickability(true); |
+} |
+ |
+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.
|
+ CreateLabel(true, clickableMessageId); |
+ VerifyNoClicks(); |
+ |
+ ClickOnLabel(); |
+ |
+ VerifyClicks(std::vector<int>({clickableMessageId})); |
+} |
+ |
+TEST_F(TrayInfoLabelTest, Update) { |
+ CreateLabel(true, nonClickableMessageId); |
+ VerifyMessageId(nonClickableMessageId); |
+ VerifyClickability(false); |
+ |
+ UpdateLabel(clickableMessageId); |
+ VerifyMessageId(clickableMessageId); |
+ VerifyClickability(true); |
+} |
+ |
+} // namespace test |
+} // namespace ash |