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

Side by Side 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@ 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 unified diff | Download patch
« no previous file with comments | « ash/system/tray/tray_info_label.cc ('k') | ash/system/tray/tray_popup_item_style.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
7 #include "ash/test/ash_test_base.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/accessibility/ax_node_data.h"
10
11 namespace ash {
12
13 namespace {
14
15 const int kClickableMessageId = 1;
16 const int kNonClickableMessageId = 0;
17
18 class TestClickEvent : public ui::Event {
19 public:
20 TestClickEvent() : ui::Event(ui::ET_MOUSE_PRESSED, base::TimeTicks(), 0) {}
21 };
22
23 class TestDelegate : public TrayInfoLabel::Delegate {
24 public:
25 TestDelegate() : clicked_message_ids_(std::vector<int>()) {}
Kyle Horimoto 2017/07/14 17:54:22 std::vector has a default constructor - no need to
lesliewatkins 2017/07/14 20:43:17 Done.
26
27 const std::vector<int>& clicked_message_ids() { return clicked_message_ids_; }
28
29 void OnLabelClicked(int message_id) override {
Kyle Horimoto 2017/07/14 17:54:22 Before this line: // TrayInfoLabel::Delegate:
lesliewatkins 2017/07/14 20:43:16 Done.
30 clicked_message_ids_.push_back(message_id);
31 }
32
33 bool IsLabelClickable(int message_id) override {
34 return kClickableMessageId == message_id;
35 }
36
37 private:
38 std::vector<int> clicked_message_ids_;
39 };
40
41 } // namespace
42
43 class TrayInfoLabelTest : public test::AshTestBase {
44 public:
45 void TearDown() override {
46 AshTestBase::TearDown();
47 label_.reset();
48 delegate_.reset();
49 }
50
51 void CreateLabel(bool use_delegate, int message_id) {
52 if (use_delegate)
53 delegate_ = base::MakeUnique<TestDelegate>();
54
55 label_ = base::MakeUnique<TrayInfoLabel>(delegate_.get(), message_id);
56 }
57
58 void ClickOnLabel(bool expect_click_was_handled) {
59 bool click_was_handled = label_->PerformAction(TestClickEvent());
60 EXPECT_EQ(expect_click_was_handled, click_was_handled);
61 }
62
63 void VerifyClickability(bool expected_clickable) {
64 EXPECT_EQ(expected_clickable, label_->IsClickable());
65
66 ui::AXNodeData node_data;
67 label_->GetAccessibleNodeData(&node_data);
68
69 gfx::FontList font_list = views::Label::GetDefaultFontList();
Kyle Horimoto 2017/07/14 17:54:22 Unused - remove.
lesliewatkins 2017/07/14 20:43:17 Done.
70 if (expected_clickable)
71 EXPECT_EQ(ui::AX_ROLE_BUTTON, node_data.role);
72 else
73 EXPECT_EQ(ui::AX_ROLE_LABEL_TEXT, node_data.role);
74 }
75
76 void VerifyClicks(const std::vector<int> expected_clicked_message_ids) {
Kyle Horimoto 2017/07/14 17:54:22 const std::vector<int>&
lesliewatkins 2017/07/14 20:43:16 Done.
77 if (!delegate_) {
78 EXPECT_TRUE(expected_clicked_message_ids.empty());
79 return;
80 }
81
82 EXPECT_EQ(expected_clicked_message_ids, delegate_->clicked_message_ids());
83 }
84
85 void VerifyNoClicks() { VerifyClicks(std::vector<int>()); }
86
87 protected:
88 std::unique_ptr<TrayInfoLabel> label_;
89 std::unique_ptr<TestDelegate> delegate_;
90 };
91
92 TEST_F(TrayInfoLabelTest, NoDelegate) {
93 CreateLabel(false /* use_delegate */, kNonClickableMessageId);
94
Kyle Horimoto 2017/07/14 17:54:22 nit: Generally, tests are easier to read when the
lesliewatkins 2017/07/14 20:43:17 Done.
95 VerifyClickability(false);
96
97 label_->Update(kClickableMessageId);
98
99 VerifyClickability(false);
100 }
101
102 TEST_F(TrayInfoLabelTest, PerformAction) {
103 CreateLabel(true /* use_delegate */, kClickableMessageId);
104
105 VerifyNoClicks();
106
107 ClickOnLabel(true /* expect_click_was_handled */);
108
109 VerifyClicks(std::vector<int>({kClickableMessageId}));
110
111 label_->Update(kNonClickableMessageId);
112 ClickOnLabel(false /* expect_click_was_handled */);
113
114 VerifyClicks(std::vector<int>({kClickableMessageId}));
115 }
116
117 TEST_F(TrayInfoLabelTest, UpdateWithDelegate) {
118 CreateLabel(true /* use_delegate */, kNonClickableMessageId);
119 VerifyClickability(false);
120
121 label_->Update(kClickableMessageId);
122 VerifyClickability(true);
123
124 label_->Update(kNonClickableMessageId);
125 VerifyClickability(false);
126 }
127
128 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_info_label.cc ('k') | ash/system/tray/tray_popup_item_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698