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

Side by Side Diff: jingle/notifier/listener/xmpp_push_client_unittest.cc

Issue 10545170: [Sync] Propagate XMPP auth errors to SyncNotifierObservers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix deps, win compile error Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "jingle/notifier/listener/xmpp_push_client.h" 5 #include "jingle/notifier/listener/xmpp_push_client.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "jingle/notifier/base/fake_base_task.h" 10 #include "jingle/notifier/base/fake_base_task.h"
11 #include "jingle/notifier/base/notifier_options.h" 11 #include "jingle/notifier/base/notifier_options.h"
12 #include "jingle/notifier/listener/push_client_observer.h" 12 #include "jingle/notifier/listener/push_client_observer.h"
13 #include "net/url_request/url_request_test_util.h" 13 #include "net/url_request/url_request_test_util.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace notifier { 17 namespace notifier {
18 18
19 namespace { 19 namespace {
20 20
21 using ::testing::_; 21 using ::testing::_;
22 using ::testing::Mock; 22 using ::testing::Mock;
23 using ::testing::StrictMock; 23 using ::testing::StrictMock;
24 24
25 class MockObserver : public PushClientObserver { 25 class MockObserver : public PushClientObserver {
26 public: 26 public:
27 MOCK_METHOD1(OnNotificationStateChange, void(bool)); 27 MOCK_METHOD0(OnNotificationsEnabled, void());
28 MOCK_METHOD1(OnNotificationsDisabled, void(NotificationsDisabledReason));
28 MOCK_METHOD1(OnIncomingNotification, void(const Notification&)); 29 MOCK_METHOD1(OnIncomingNotification, void(const Notification&));
29 }; 30 };
30 31
31 class XmppPushClientTest : public testing::Test { 32 class XmppPushClientTest : public testing::Test {
32 protected: 33 protected:
33 XmppPushClientTest() { 34 XmppPushClientTest() {
34 notifier_options_.request_context_getter = 35 notifier_options_.request_context_getter =
35 new TestURLRequestContextGetter(message_loop_.message_loop_proxy()); 36 new TestURLRequestContextGetter(message_loop_.message_loop_proxy());
36 } 37 }
37 38
(...skipping 22 matching lines...) Expand all
60 // Make sure the XMPP push client notifies its observers of incoming 61 // Make sure the XMPP push client notifies its observers of incoming
61 // notifications properly. 62 // notifications properly.
62 TEST_F(XmppPushClientTest, OnIncomingNotification) { 63 TEST_F(XmppPushClientTest, OnIncomingNotification) {
63 EXPECT_CALL(mock_observer_, OnIncomingNotification(_)); 64 EXPECT_CALL(mock_observer_, OnIncomingNotification(_));
64 xmpp_push_client_->OnNotificationReceived(Notification()); 65 xmpp_push_client_->OnNotificationReceived(Notification());
65 } 66 }
66 67
67 // Make sure the XMPP push client notifies its observers of a 68 // Make sure the XMPP push client notifies its observers of a
68 // successful connection properly. 69 // successful connection properly.
69 TEST_F(XmppPushClientTest, ConnectAndSubscribe) { 70 TEST_F(XmppPushClientTest, ConnectAndSubscribe) {
70 EXPECT_CALL(mock_observer_, OnNotificationStateChange(true)); 71 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
71 xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr()); 72 xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr());
72 xmpp_push_client_->OnSubscribed(); 73 xmpp_push_client_->OnSubscribed();
73 } 74 }
74 75
75 // Make sure the XMPP push client notifies its observers of a 76 // Make sure the XMPP push client notifies its observers of a
76 // terminated connection properly. 77 // terminated connection properly.
77 TEST_F(XmppPushClientTest, Disconnect) { 78 TEST_F(XmppPushClientTest, Disconnect) {
78 EXPECT_CALL(mock_observer_, OnNotificationStateChange(false)); 79 EXPECT_CALL(mock_observer_,
79 xmpp_push_client_->OnDisconnect(); 80 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
81 xmpp_push_client_->OnTransientDisconnection();
82 }
83
84 // Make sure the XMPP push client notifies its observers of
85 // rejected credentials properly.
86 TEST_F(XmppPushClientTest, RejectCredentials) {
87 EXPECT_CALL(mock_observer_,
88 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
89 xmpp_push_client_->OnCredentialsRejected();
80 } 90 }
81 91
82 // Make sure the XMPP push client notifies its observers of a 92 // Make sure the XMPP push client notifies its observers of a
83 // subscription error properly. 93 // subscription error properly.
84 TEST_F(XmppPushClientTest, SubscriptionError) { 94 TEST_F(XmppPushClientTest, SubscriptionError) {
85 EXPECT_CALL(mock_observer_, OnNotificationStateChange(false)); 95 EXPECT_CALL(mock_observer_,
96 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
86 xmpp_push_client_->OnSubscriptionError(); 97 xmpp_push_client_->OnSubscriptionError();
87 } 98 }
88 99
89 // Make sure nothing blows up when the XMPP push client sends a 100 // Make sure nothing blows up when the XMPP push client sends a
90 // notification. 101 // notification.
91 // 102 //
92 // TODO(akalin): Figure out how to test that the notification was 103 // TODO(akalin): Figure out how to test that the notification was
93 // actually sent. 104 // actually sent.
94 TEST_F(XmppPushClientTest, SendNotification) { 105 TEST_F(XmppPushClientTest, SendNotification) {
95 EXPECT_CALL(mock_observer_, OnNotificationStateChange(true)); 106 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
96 107
97 xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr()); 108 xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr());
98 xmpp_push_client_->OnSubscribed(); 109 xmpp_push_client_->OnSubscribed();
99 xmpp_push_client_->SendNotification(Notification()); 110 xmpp_push_client_->SendNotification(Notification());
100 } 111 }
101 112
102 // Make sure nothing blows up when the XMPP push client sends a 113 // Make sure nothing blows up when the XMPP push client sends a
103 // notification when disconnected, and the client connects. 114 // notification when disconnected, and the client connects.
104 // 115 //
105 // TODO(akalin): Figure out how to test that the notification was 116 // TODO(akalin): Figure out how to test that the notification was
106 // actually sent. 117 // actually sent.
107 TEST_F(XmppPushClientTest, SendNotificationPending) { 118 TEST_F(XmppPushClientTest, SendNotificationPending) {
108 xmpp_push_client_->SendNotification(Notification()); 119 xmpp_push_client_->SendNotification(Notification());
109 120
110 Mock::VerifyAndClearExpectations(&mock_observer_); 121 Mock::VerifyAndClearExpectations(&mock_observer_);
111 122
112 EXPECT_CALL(mock_observer_, OnNotificationStateChange(true)); 123 EXPECT_CALL(mock_observer_, OnNotificationsEnabled());
113 124
114 xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr()); 125 xmpp_push_client_->OnConnect(fake_base_task_.AsWeakPtr());
115 xmpp_push_client_->OnSubscribed(); 126 xmpp_push_client_->OnSubscribed();
116 } 127 }
117 128
118 } // namespace 129 } // namespace
119 130
120 } // namespace notifier 131 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698