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

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

Issue 2583393002: Send notification to users upon receiving sms messages (Closed)
Patch Set: Created 3 years, 11 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 2016 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/shelf/shelf_widget.h"
6 #include "ash/common/shelf/wm_shelf.h"
7 #include "ash/common/system/chromeos/network/sms_observer.h"
8 #include "ash/public/interfaces/vpn_list.mojom.h"
9 #include "ash/test/ash_test_base.h"
10 #include "base/macros.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/message_center/message_center.h"
15 #include "ui/message_center/notification.h"
16 #include "ui/message_center/notification_list.h"
17
18 using ash::mojom::ThirdPartyVpnProvider;
19 using ash::mojom::ThirdPartyVpnProviderPtr;
tdanderson 2017/01/26 22:19:06 Why are these needed?
yiyix 2017/02/02 20:43:56 Removed. It is leftover of some random trials i ha
tdanderson 2017/02/07 00:15:45 Acknowledged.
20
21 namespace ash {
22 namespace test {
23
24 class SmsObserverTest : public AshTestBase {
25 public:
26 SmsObserverTest() {}
27 ~SmsObserverTest() override {}
28
29 const char* kNotification = "chrome://network/sms";
30 SmsObserver* GetSmsObserver(ShelfWidget* shelf_widget) {
31 return shelf_widget->sms_observer_;
32 }
33
34 // Get the last sms notification from notification center.
35 const message_center::Notification* GetDisplayNotification() const {
36 const message_center::NotificationList::Notifications notifications =
37 message_center::MessageCenter::Get()->GetVisibleNotifications();
38 for (message_center::NotificationList::Notifications::const_iterator iter =
tdanderson 2017/01/26 22:19:07 consider using a c++11 range-based for loop instea
yiyix 2017/02/02 20:43:56 Done.
tdanderson 2017/02/07 00:15:45 I'm a bit confused... all of this code seems to ha
yiyix 2017/02/07 22:03:22 Yes, it is intentional. This method only returns t
tdanderson 2017/02/08 16:32:51 Acknowledged.
39 notifications.begin();
40 iter != notifications.end(); ++iter) {
tdanderson 2017/01/26 22:19:06 can you run 'git cl format ash' on this CL? the fo
yiyix 2017/02/02 20:43:56 It's weird. I did it... didn't change this format.
tdanderson 2017/02/07 00:15:45 Acknowledged.
41 if ((*iter)->id().find(kNotification) != std::string::npos)
42 return *iter;
43 }
44
45 return NULL;
tdanderson 2017/01/26 22:19:06 nit: nullptr
yiyix 2017/02/02 20:43:56 Done.
46 }
47
48 base::string16 GetDisplayNotificationText() const {
49 const message_center::Notification* notification = GetDisplayNotification();
50 return notification ? notification->title() : base::string16();
51 }
52
53 base::string16 GetDisplayNotificationAdditionalText() const {
54 const message_center::Notification* notification = GetDisplayNotification();
55 return notification ? notification->message() : base::string16();
56 }
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(SmsObserverTest);
60 };
61
62 // Verify if notification is received after receiving a sms message with
63 // number and content.
64 TEST_F(SmsObserverTest, SendTextMessage) {
65 SmsObserver* sms_observer = GetSmsObserver(GetPrimaryShelf()->shelf_widget());
66 EXPECT_FALSE(GetDisplayNotification());
67 base::DictionaryValue* sms = new base::DictionaryValue();
68 sms->SetString("number", "000-000-0000");
69 sms->SetString("text", "FakeSMSClient: Test Message.");
70 sms->SetString("timestamp", "Fri Jun 8 13:26:04 EDT 2016");
71
72 sms_observer->MessageReceived(*sms);
73 EXPECT_TRUE(GetDisplayNotification());
74 EXPECT_EQ(GetDisplayNotification()->title(),
75 base::ASCIIToUTF16("000-000-0000"));
76 EXPECT_EQ(GetDisplayNotification()->message(),
77 base::ASCIIToUTF16("FakeSMSClient: Test Message."));
78 message_center::MessageCenter::Get()->RemoveAllNotifications(
79 false /* by_user */, message_center::MessageCenter::RemoveType::ALL);
80 EXPECT_FALSE(GetDisplayNotification());
81 }
82
83 // Verify if no notification is received if phone number is missing in sms
84 // message.
85 TEST_F(SmsObserverTest, TextMessageMissingNumber) {
86 SmsObserver* sms_observer = GetSmsObserver(GetPrimaryShelf()->shelf_widget());
87 EXPECT_FALSE(GetDisplayNotification());
88 base::DictionaryValue* sms = new base::DictionaryValue();
89 sms->SetString("text", "FakeSMSClient: Test Message.");
90 sms->SetString("timestamp", "Fri Jun 8 13:26:04 EDT 2016");
91
92 sms_observer->MessageReceived(*sms);
93 EXPECT_FALSE(GetDisplayNotification());
94 }
95
96 // Verify if no notification is received if text body is empty in sms message.
97 TEST_F(SmsObserverTest, TextMessageEmptyText) {
98 SmsObserver* sms_observer = GetSmsObserver(GetPrimaryShelf()->shelf_widget());
99 EXPECT_FALSE(GetDisplayNotification());
100 base::DictionaryValue* sms = new base::DictionaryValue();
101 sms->SetString("number", "000-000-0000");
102 sms->SetString("text", "");
103 sms->SetString("timestamp", "Fri Jun 8 13:26:04 EDT 2016");
104
105 sms_observer->MessageReceived(*sms);
106 EXPECT_FALSE(GetDisplayNotification());
107 }
108
109 // Verify if no notification is received if the text is missing in sms message.
110 TEST_F(SmsObserverTest, TextMessageMissingText) {
tdanderson 2017/01/26 22:19:06 What's the difference between 'missing' and 'empty
yiyix 2017/02/02 20:43:56 In MessageReceived method in sms_observer, it chec
111 SmsObserver* sms_observer = GetSmsObserver(GetPrimaryShelf()->shelf_widget());
112 EXPECT_FALSE(GetDisplayNotification());
113 base::DictionaryValue* sms = new base::DictionaryValue();
114 sms->SetString("number", "000-000-0000");
115 sms->SetString("timestamp", "Fri Jun 8 13:26:04 EDT 2016");
116
117 sms_observer->MessageReceived(*sms);
118 EXPECT_FALSE(GetDisplayNotification());
119 }
tdanderson 2017/01/26 22:19:06 Also consider adding a test which sends two notifi
yiyix 2017/02/02 20:43:56 That will be a good test. Added.
120
121 } // namespace test
122 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698