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

Side by Side Diff: ash/common/system/chromeos/network/sms_observer_unittest.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 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
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/common/system/chromeos/network/sms_observer.h"
6
7 #include "ash/common/shelf/shelf_widget.h"
8 #include "ash/common/shelf/wm_shelf.h"
9 #include "ash/public/interfaces/vpn_list.mojom.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "base/macros.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/message_center/message_center.h"
17 #include "ui/message_center/notification.h"
18 #include "ui/message_center/notification_list.h"
19
20 using message_center::MessageCenter;
21
22 namespace ash {
23
24 namespace {
25
26 std::unique_ptr<base::DictionaryValue> CreateMessage(
27 const char* kDefaultMessage = "FakeSMSClient: Test Message.",
28 const char* kDefaultNumber = "000-000-0000",
29 const char* kDefaultTimestamp = "Fri Jun 8 13:26:04 EDT 2016") {
30 std::unique_ptr<base::DictionaryValue> sms =
31 base::MakeUnique<base::DictionaryValue>();
32 if (kDefaultNumber)
33 sms->SetString("number", kDefaultNumber);
34 if (kDefaultMessage)
35 sms->SetString("text", kDefaultMessage);
36 if (kDefaultTimestamp)
37 sms->SetString("timestamp", kDefaultMessage);
38 return sms;
39 }
40
41 } // namespace
42
43 class SmsObserverTest : public test::AshTestBase {
44 public:
45 SmsObserverTest() {}
46 ~SmsObserverTest() override {}
47
48 SmsObserver* GetSmsObserver() {
49 return Shell::GetInstance()->sms_observer_.get();
50 }
51
52 private:
53 DISALLOW_COPY_AND_ASSIGN(SmsObserverTest);
54 };
55
56 // Verify if notification is received after receiving a sms message with
57 // number and content.
58 TEST_F(SmsObserverTest, SendTextMessage) {
59 SmsObserver* sms_observer = GetSmsObserver();
60 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
61
62 std::unique_ptr<base::DictionaryValue> sms(CreateMessage());
63 sms_observer->MessageReceived(*sms);
64
65 const message_center::NotificationList::Notifications notifications =
66 MessageCenter::Get()->GetVisibleNotifications();
67 EXPECT_EQ(1u, notifications.size());
68
69 EXPECT_EQ(base::ASCIIToUTF16("000-000-0000"),
70 (*notifications.begin())->title());
71 EXPECT_EQ(base::ASCIIToUTF16("FakeSMSClient: Test Message."),
72 (*notifications.begin())->message());
73 MessageCenter::Get()->RemoveAllNotifications(false /* by_user */,
74 MessageCenter::RemoveType::ALL);
75 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
76 }
77
78 // Verify if no notification is received if phone number is missing in sms
79 // message.
80 TEST_F(SmsObserverTest, TextMessageMissingNumber) {
81 SmsObserver* sms_observer = GetSmsObserver();
82 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
83
84 std::unique_ptr<base::DictionaryValue> sms(
85 CreateMessage("FakeSMSClient: Test Message.", nullptr));
86 sms_observer->MessageReceived(*sms);
87 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
88 }
89
90 // Verify if no notification is received if text body is empty in sms message.
91 TEST_F(SmsObserverTest, TextMessageEmptyText) {
92 SmsObserver* sms_observer = GetSmsObserver();
93 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
94
95 std::unique_ptr<base::DictionaryValue> sms(CreateMessage(""));
96 sms_observer->MessageReceived(*sms);
97 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
98 }
99
100 // Verify if no notification is received if the text is missing in sms message.
101 TEST_F(SmsObserverTest, TextMessageMissingText) {
102 SmsObserver* sms_observer = GetSmsObserver();
103 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
104 std::unique_ptr<base::DictionaryValue> sms(CreateMessage(nullptr));
105 sms_observer->MessageReceived(*sms);
106 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
107 }
108
109 // Verify if 2 notification received after receiving 2 sms messages from the
110 // same number.
111 TEST_F(SmsObserverTest, MultipleTextMessages) {
112 SmsObserver* sms_observer = GetSmsObserver();
113 EXPECT_EQ(0u, MessageCenter::Get()->GetVisibleNotifications().size());
114
115 std::unique_ptr<base::DictionaryValue> sms(CreateMessage("first message"));
116 sms_observer->MessageReceived(*sms);
117 std::unique_ptr<base::DictionaryValue> sms2(CreateMessage("second message"));
118 sms_observer->MessageReceived(*sms2);
119 const message_center::NotificationList::Notifications notifications =
120 MessageCenter::Get()->GetVisibleNotifications();
121 EXPECT_EQ(2u, notifications.size());
122
123 for (message_center::Notification* iter : notifications) {
124 if (iter->id().find("chrome://network/sms1") != std::string::npos) {
125 EXPECT_EQ(base::ASCIIToUTF16("000-000-0000"), iter->title());
126 EXPECT_EQ(base::ASCIIToUTF16("first message"), iter->message());
127 } else if (iter->id().find("chrome://network/sms2") != std::string::npos) {
128 EXPECT_EQ(base::ASCIIToUTF16("000-000-0000"), iter->title());
129 EXPECT_EQ(base::ASCIIToUTF16("second message"), iter->message());
130 } else {
131 ASSERT_TRUE(false);
132 }
133 }
134 }
135
136 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/sms_observer.cc ('k') | ash/common/system/chromeos/network/tray_network.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698