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

Unified Diff: ash/system/tray/tray_info_label_unittest.cc

Issue 2957043002: Add a row in the network tray to inform users to turn Bluetooth on to enable Tether. (Closed)
Patch Set: khorimoto@ and jamescook@ comments Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
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..4c91bea41032b85a8d5173b559bd49a39d09b019
--- /dev/null
+++ b/ash/system/tray/tray_info_label_unittest.cc
@@ -0,0 +1,92 @@
+// 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 {
+
+class TestEvent : public ui::Event {
Kyle Horimoto 2017/07/12 22:45:59 TestEvent --> TestClickEvent
lesliewatkins 2017/07/13 22:12:49 Done.
+ public:
+ TestEvent() : ui::Event(ui::ET_MOUSE_PRESSED, base::TimeTicks(), 0) {}
+};
+
+class TestNonClickableDelegate : public TrayInfoLabel::Delegate {
Kyle Horimoto 2017/07/12 22:45:59 Just make one TestDelegate class which can be set
lesliewatkins 2017/07/13 22:12:49 Done.
+ public:
+ void OnLabelClicked(int message_id) override {}
+
+ bool LabelIsClickable(int message_id) override { return false; }
+};
+
+class TestClickableDelegate : public TrayInfoLabel::Delegate {
+ public:
+ bool LabelWasClicked() { return was_clicked_; }
+
+ void OnLabelClicked(int message_id) override { was_clicked_ = true; }
+
+ bool LabelIsClickable(int message_id) override { return true; }
+
+ private:
+ bool was_clicked_ = false;
+};
+
+} // namespace
Kyle Horimoto 2017/07/12 22:45:59 nit: Newline after this.
lesliewatkins 2017/07/13 22:12:49 Done.
+namespace test {
Kyle Horimoto 2017/07/12 22:45:59 Is there a reason why you're using this extra name
lesliewatkins 2017/07/13 22:12:48 I moved the test namespace up to the top. The anon
Kyle Horimoto 2017/07/13 23:15:36 Sorry I wasn't clear - I'm referring to the test n
lesliewatkins 2017/07/14 06:41:52 Done.
+
+class TrayInfoLabelTest : public AshTestBase {
Kyle Horimoto 2017/07/12 22:45:59 Add instance variables (std::unique_ptr's) for bot
lesliewatkins 2017/07/13 22:12:48 Done.
+ public:
+ int LabelMessageId(TrayInfoLabel* label) { return label->message_id_; }
+
+ void ConfirmClickableLabel(TrayInfoLabel* label) {
+ EXPECT_TRUE(label->IsClickable());
+ }
+
+ void ConfirmNonClickableLabel(TrayInfoLabel* label) {
+ EXPECT_FALSE(label->IsClickable());
+ }
+};
+
+TEST_F(TrayInfoLabelTest, NoDelegate) {
+ TrayInfoLabel* label = new TrayInfoLabel(nullptr, 0);
+
+ ConfirmNonClickableLabel(label);
+}
+
+TEST_F(TrayInfoLabelTest, NonClickableDelegate) {
Kyle Horimoto 2017/07/12 22:45:59 For the tests with the delegate, call Update() wit
lesliewatkins 2017/07/13 22:12:48 That's what the Update test does.
Kyle Horimoto 2017/07/13 23:15:36 You just need to show that the correct values are
lesliewatkins 2017/07/14 06:41:51 I added the AX node stuff, but still not convinced
Kyle Horimoto 2017/07/14 17:54:21 Okay, that's fine! The a11y stuff was the bigger c
lesliewatkins 2017/07/14 20:43:16 Acknowledged.
+ TrayInfoLabel* label = new TrayInfoLabel(new TestNonClickableDelegate(), 0);
+
+ ConfirmNonClickableLabel(label);
+}
+
+TEST_F(TrayInfoLabelTest, ClickableDelegate) {
+ TrayInfoLabel* label = new TrayInfoLabel(new TestClickableDelegate(), 0);
+
+ ConfirmClickableLabel(label);
+}
+
+TEST_F(TrayInfoLabelTest, PerformAction) {
+ TestClickableDelegate* delegate = new TestClickableDelegate();
+ TrayInfoLabel* label = new TrayInfoLabel(delegate, 0);
+
+ ASSERT_FALSE(delegate->LabelWasClicked());
+
+ TestEvent event;
+ label->PerformAction(event);
+
+ EXPECT_TRUE(delegate->LabelWasClicked());
+}
+
+TEST_F(TrayInfoLabelTest, Update) {
+ TrayInfoLabel* label = new TrayInfoLabel(nullptr, 0);
+ ASSERT_EQ(LabelMessageId(label), 0);
+
+ label->Update(1);
+ EXPECT_EQ(LabelMessageId(label), 1);
+}
+
+} // namespace test
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698