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

Side by Side Diff: sync/notifier/chrome_invalidation_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 <string> 5 #include <string>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "google/cacheinvalidation/include/invalidation-client.h" 8 #include "google/cacheinvalidation/include/invalidation-client.h"
9 #include "google/cacheinvalidation/include/types.h" 9 #include "google/cacheinvalidation/include/types.h"
10 #include "google/cacheinvalidation/v2/types.pb.h" 10 #include "google/cacheinvalidation/v2/types.pb.h"
11 #include "jingle/notifier/listener/fake_push_client.h" 11 #include "jingle/notifier/listener/fake_push_client.h"
12 #include "sync/internal_api/public/syncable/model_type.h" 12 #include "sync/internal_api/public/syncable/model_type.h"
13 #include "sync/internal_api/public/syncable/model_type_payload_map.h" 13 #include "sync/internal_api/public/syncable/model_type_payload_map.h"
14 #include "sync/internal_api/public/util/weak_handle.h" 14 #include "sync/internal_api/public/util/weak_handle.h"
15 #include "sync/notifier/chrome_invalidation_client.h" 15 #include "sync/notifier/chrome_invalidation_client.h"
16 #include "sync/notifier/mock_invalidation_state_tracker.h" 16 #include "sync/notifier/mock_invalidation_state_tracker.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace sync_notifier { 20 namespace sync_notifier {
21 21
22 using ::testing::_; 22 using ::testing::_;
23 using ::testing::InSequence;
23 using ::testing::Return; 24 using ::testing::Return;
24 using ::testing::StrictMock; 25 using ::testing::StrictMock;
25 26
26 namespace { 27 namespace {
27 28
28 const char kClientId[] = "client_id"; 29 const char kClientId[] = "client_id";
29 const char kClientInfo[] = "client_info"; 30 const char kClientInfo[] = "client_info";
30 const char kState[] = "state"; 31 const char kState[] = "state";
31 const char kNewState[] = "new_state"; 32 const char kNewState[] = "new_state";
32 33
33 class MockInvalidationClient : public invalidation::InvalidationClient { 34 class MockInvalidationClient : public invalidation::InvalidationClient {
34 public: 35 public:
35 MOCK_METHOD0(Start, void()); 36 MOCK_METHOD0(Start, void());
36 MOCK_METHOD0(Stop, void()); 37 MOCK_METHOD0(Stop, void());
37 MOCK_METHOD1(Register, void(const invalidation::ObjectId&)); 38 MOCK_METHOD1(Register, void(const invalidation::ObjectId&));
38 MOCK_METHOD1(Register, void(const std::vector<invalidation::ObjectId>&)); 39 MOCK_METHOD1(Register, void(const std::vector<invalidation::ObjectId>&));
39 MOCK_METHOD1(Unregister, void(const invalidation::ObjectId&)); 40 MOCK_METHOD1(Unregister, void(const invalidation::ObjectId&));
40 MOCK_METHOD1(Unregister, void(const std::vector<invalidation::ObjectId>&)); 41 MOCK_METHOD1(Unregister, void(const std::vector<invalidation::ObjectId>&));
41 MOCK_METHOD1(Acknowledge, void(const invalidation::AckHandle&)); 42 MOCK_METHOD1(Acknowledge, void(const invalidation::AckHandle&));
42 }; 43 };
43 44
44 class MockListener : public ChromeInvalidationClient::Listener { 45 class MockListener : public ChromeInvalidationClient::Listener {
45 public: 46 public:
46 MOCK_METHOD1(OnInvalidate, void(const syncable::ModelTypePayloadMap&)); 47 MOCK_METHOD1(OnInvalidate, void(const syncable::ModelTypePayloadMap&));
47 MOCK_METHOD1(OnSessionStatusChanged, void(bool)); 48 MOCK_METHOD0(OnNotificationsEnabled, void());
49 MOCK_METHOD1(OnNotificationsDisabled, void(NotificationsDisabledReason));
48 }; 50 };
49 51
50 } // namespace 52 } // namespace
51 53
52 class ChromeInvalidationClientTest : public testing::Test { 54 class ChromeInvalidationClientTest : public testing::Test {
53 protected: 55 protected:
54 ChromeInvalidationClientTest() 56 ChromeInvalidationClientTest()
55 : client_( 57 : fake_push_client_(new notifier::FakePushClient()),
56 scoped_ptr<notifier::PushClient>( 58 client_(scoped_ptr<notifier::PushClient>(fake_push_client_)) {}
57 new notifier::FakePushClient())) {}
58 59
59 virtual void SetUp() { 60 virtual void SetUp() {
60 client_.Start(kClientId, kClientInfo, kState, 61 client_.Start(kClientId, kClientInfo, kState,
61 InvalidationVersionMap(), 62 InvalidationVersionMap(),
62 browser_sync::MakeWeakHandle( 63 browser_sync::MakeWeakHandle(
63 mock_invalidation_state_tracker_.AsWeakPtr()), 64 mock_invalidation_state_tracker_.AsWeakPtr()),
64 &mock_listener_); 65 &mock_listener_);
65 } 66 }
66 67
67 virtual void TearDown() { 68 virtual void TearDown() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 invalidation::AckHandle ack_handle("fakedata"); 110 invalidation::AckHandle ack_handle("fakedata");
110 EXPECT_CALL(mock_invalidation_client_, Acknowledge(ack_handle)); 111 EXPECT_CALL(mock_invalidation_client_, Acknowledge(ack_handle));
111 client_.InvalidateAll(&mock_invalidation_client_, ack_handle); 112 client_.InvalidateAll(&mock_invalidation_client_, ack_handle);
112 } 113 }
113 114
114 MessageLoop message_loop_; 115 MessageLoop message_loop_;
115 StrictMock<MockListener> mock_listener_; 116 StrictMock<MockListener> mock_listener_;
116 StrictMock<MockInvalidationStateTracker> 117 StrictMock<MockInvalidationStateTracker>
117 mock_invalidation_state_tracker_; 118 mock_invalidation_state_tracker_;
118 StrictMock<MockInvalidationClient> mock_invalidation_client_; 119 StrictMock<MockInvalidationClient> mock_invalidation_client_;
120 notifier::FakePushClient* const fake_push_client_;
119 ChromeInvalidationClient client_; 121 ChromeInvalidationClient client_;
120 }; 122 };
121 123
122 namespace { 124 namespace {
123 125
124 syncable::ModelTypePayloadMap MakeMap(syncable::ModelType model_type, 126 syncable::ModelTypePayloadMap MakeMap(syncable::ModelType model_type,
125 const std::string& payload) { 127 const std::string& payload) {
126 syncable::ModelTypePayloadMap type_payloads; 128 syncable::ModelTypePayloadMap type_payloads;
127 type_payloads[model_type] = payload; 129 type_payloads[model_type] = payload;
128 return type_payloads; 130 return type_payloads;
(...skipping 23 matching lines...) Expand all
152 } 154 }
153 155
154 TEST_F(ChromeInvalidationClientTest, InvalidateWithPayload) { 156 TEST_F(ChromeInvalidationClientTest, InvalidateWithPayload) {
155 EXPECT_CALL(mock_listener_, 157 EXPECT_CALL(mock_listener_,
156 OnInvalidate(MakeMap(syncable::PREFERENCES, "payload"))); 158 OnInvalidate(MakeMap(syncable::PREFERENCES, "payload")));
157 EXPECT_CALL(mock_invalidation_state_tracker_, 159 EXPECT_CALL(mock_invalidation_state_tracker_,
158 SetMaxVersion(syncable::PREFERENCES, 1)); 160 SetMaxVersion(syncable::PREFERENCES, 1));
159 FireInvalidate("PREFERENCE", 1, "payload"); 161 FireInvalidate("PREFERENCE", 1, "payload");
160 } 162 }
161 163
162 TEST_F(ChromeInvalidationClientTest, WriteState) {
163 EXPECT_CALL(mock_invalidation_state_tracker_,
164 SetInvalidationState(kNewState));
165 client_.WriteState(kNewState);
166 }
167
168 TEST_F(ChromeInvalidationClientTest, InvalidateVersion) { 164 TEST_F(ChromeInvalidationClientTest, InvalidateVersion) {
169 using ::testing::Mock; 165 using ::testing::Mock;
170 166
171 EXPECT_CALL(mock_listener_, 167 EXPECT_CALL(mock_listener_,
172 OnInvalidate(MakeMap(syncable::APPS, ""))); 168 OnInvalidate(MakeMap(syncable::APPS, "")));
173 EXPECT_CALL(mock_invalidation_state_tracker_, 169 EXPECT_CALL(mock_invalidation_state_tracker_,
174 SetMaxVersion(syncable::APPS, 1)); 170 SetMaxVersion(syncable::APPS, 1));
175 171
176 // Should trigger. 172 // Should trigger.
177 FireInvalidate("APP", 1, NULL); 173 FireInvalidate("APP", 1, NULL);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 TEST_F(ChromeInvalidationClientTest, RegisterTypes) { 255 TEST_F(ChromeInvalidationClientTest, RegisterTypes) {
260 syncable::ModelTypeSet types(syncable::PREFERENCES, syncable::EXTENSIONS); 256 syncable::ModelTypeSet types(syncable::PREFERENCES, syncable::EXTENSIONS);
261 client_.RegisterTypes(types); 257 client_.RegisterTypes(types);
262 // Registered types should be preserved across Stop/Start. 258 // Registered types should be preserved across Stop/Start.
263 TearDown(); 259 TearDown();
264 SetUp(); 260 SetUp();
265 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); 261 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, "")));
266 FireInvalidateAll(); 262 FireInvalidateAll();
267 } 263 }
268 264
269 // TODO(akalin): Flesh out unit tests. 265 TEST_F(ChromeInvalidationClientTest, WriteState) {
266 EXPECT_CALL(mock_invalidation_state_tracker_,
267 SetInvalidationState(kNewState));
268 client_.WriteState(kNewState);
269 }
270
271 TEST_F(ChromeInvalidationClientTest, StateChangesNotReady) {
272 InSequence dummy;
273 EXPECT_CALL(mock_listener_,
274 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
275 EXPECT_CALL(mock_listener_,
276 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
277 EXPECT_CALL(mock_listener_,
278 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
279
280 fake_push_client_->DisableNotifications(
281 notifier::TRANSIENT_NOTIFICATION_ERROR);
282 fake_push_client_->DisableNotifications(
283 notifier::NOTIFICATION_CREDENTIALS_REJECTED);
284 fake_push_client_->EnableNotifications();
285 }
286
287 TEST_F(ChromeInvalidationClientTest, StateChangesReady) {
288 InSequence dummy;
289 EXPECT_CALL(mock_listener_,
290 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
291 EXPECT_CALL(mock_listener_, OnNotificationsEnabled());
292 EXPECT_CALL(mock_listener_,
293 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
294 EXPECT_CALL(mock_listener_,
295 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED));
296 EXPECT_CALL(mock_listener_, OnNotificationsEnabled());
297
298 fake_push_client_->EnableNotifications();
299 client_.Ready(NULL);
300 fake_push_client_->DisableNotifications(
301 notifier::TRANSIENT_NOTIFICATION_ERROR);
302 fake_push_client_->DisableNotifications(
303 notifier::NOTIFICATION_CREDENTIALS_REJECTED);
304 fake_push_client_->EnableNotifications();
305 }
306
307 TEST_F(ChromeInvalidationClientTest, StateChangesAuthError) {
308 InSequence dummy;
309 EXPECT_CALL(mock_listener_,
310 OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR));
311 EXPECT_CALL(mock_listener_, OnNotificationsEnabled());
312 EXPECT_CALL(mock_listener_,
313 OnNotificationsDisabled(NOTIFICATION_CREDENTIALS_REJECTED))
314 .Times(4);
315 EXPECT_CALL(mock_listener_, OnNotificationsEnabled());
316
317 fake_push_client_->EnableNotifications();
318 client_.Ready(NULL);
319
320 client_.InformError(
321 NULL,
322 invalidation::ErrorInfo(
323 invalidation::ErrorReason::AUTH_FAILURE,
324 false /* is_transient */,
325 "auth error",
326 invalidation::ErrorContext()));
327 fake_push_client_->DisableNotifications(
328 notifier::TRANSIENT_NOTIFICATION_ERROR);
329 fake_push_client_->DisableNotifications(
330 notifier::NOTIFICATION_CREDENTIALS_REJECTED);
331 fake_push_client_->EnableNotifications();
332 client_.Ready(NULL);
333 }
270 334
271 } // namespace sync_notifier 335 } // namespace sync_notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698