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

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@ 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
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..49dbdff984fd2508026c2a5c3911d738dd838bbb
--- /dev/null
+++ b/ash/system/tray/tray_info_label_unittest.cc
@@ -0,0 +1,128 @@
+// 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"
+#include "ui/accessibility/ax_node_data.h"
+
+namespace ash {
+
+namespace {
+
+const int kClickableMessageId = 1;
+const int kNonClickableMessageId = 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>()) {}
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.
+
+ const std::vector<int>& clicked_message_ids() { return clicked_message_ids_; }
+
+ 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.
+ clicked_message_ids_.push_back(message_id);
+ }
+
+ bool IsLabelClickable(int message_id) override {
+ return kClickableMessageId == message_id;
+ }
+
+ private:
+ std::vector<int> clicked_message_ids_;
+};
+
+} // namespace
+
+class TrayInfoLabelTest : public test::AshTestBase {
+ public:
+ void TearDown() override {
+ AshTestBase::TearDown();
+ label_.reset();
+ delegate_.reset();
+ }
+
+ void CreateLabel(bool use_delegate, int message_id) {
+ if (use_delegate)
+ delegate_ = base::MakeUnique<TestDelegate>();
+
+ label_ = base::MakeUnique<TrayInfoLabel>(delegate_.get(), message_id);
+ }
+
+ void ClickOnLabel(bool expect_click_was_handled) {
+ bool click_was_handled = label_->PerformAction(TestClickEvent());
+ EXPECT_EQ(expect_click_was_handled, click_was_handled);
+ }
+
+ void VerifyClickability(bool expected_clickable) {
+ EXPECT_EQ(expected_clickable, label_->IsClickable());
+
+ ui::AXNodeData node_data;
+ label_->GetAccessibleNodeData(&node_data);
+
+ 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.
+ if (expected_clickable)
+ EXPECT_EQ(ui::AX_ROLE_BUTTON, node_data.role);
+ else
+ EXPECT_EQ(ui::AX_ROLE_LABEL_TEXT, node_data.role);
+ }
+
+ 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.
+ 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>()); }
+
+ protected:
+ std::unique_ptr<TrayInfoLabel> label_;
+ std::unique_ptr<TestDelegate> delegate_;
+};
+
+TEST_F(TrayInfoLabelTest, NoDelegate) {
+ CreateLabel(false /* use_delegate */, kNonClickableMessageId);
+
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.
+ VerifyClickability(false);
+
+ label_->Update(kClickableMessageId);
+
+ VerifyClickability(false);
+}
+
+TEST_F(TrayInfoLabelTest, PerformAction) {
+ CreateLabel(true /* use_delegate */, kClickableMessageId);
+
+ VerifyNoClicks();
+
+ ClickOnLabel(true /* expect_click_was_handled */);
+
+ VerifyClicks(std::vector<int>({kClickableMessageId}));
+
+ label_->Update(kNonClickableMessageId);
+ ClickOnLabel(false /* expect_click_was_handled */);
+
+ VerifyClicks(std::vector<int>({kClickableMessageId}));
+}
+
+TEST_F(TrayInfoLabelTest, UpdateWithDelegate) {
+ CreateLabel(true /* use_delegate */, kNonClickableMessageId);
+ VerifyClickability(false);
+
+ label_->Update(kClickableMessageId);
+ VerifyClickability(true);
+
+ label_->Update(kNonClickableMessageId);
+ VerifyClickability(false);
+}
+
+} // namespace ash
« 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