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

Side by Side Diff: sync/notifier/chrome_invalidation_client_unittest.cc

Issue 10436013: [Sync] Make InvalidationNotifier use PushClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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/base/fake_base_task.h" 11 #include "jingle/notifier/listener/fake_push_client.h"
12 #include "sync/notifier/chrome_invalidation_client.h" 12 #include "sync/notifier/chrome_invalidation_client.h"
13 #include "sync/notifier/state_writer.h" 13 #include "sync/notifier/state_writer.h"
14 #include "sync/syncable/model_type.h" 14 #include "sync/syncable/model_type.h"
15 #include "sync/syncable/model_type_payload_map.h" 15 #include "sync/syncable/model_type_payload_map.h"
16 #include "sync/util/weak_handle.h" 16 #include "sync/util/weak_handle.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
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 class MockStateWriter : public StateWriter { 57 class MockStateWriter : public StateWriter {
58 public: 58 public:
59 MOCK_METHOD1(WriteState, void(const std::string&)); 59 MOCK_METHOD1(WriteState, void(const std::string&));
60 }; 60 };
61 61
62 } // namespace 62 } // namespace
63 63
64 class ChromeInvalidationClientTest : public testing::Test { 64 class ChromeInvalidationClientTest : public testing::Test {
65 protected: 65 protected:
66 ChromeInvalidationClientTest()
67 : client_(
68 scoped_ptr<notifier::PushClient>(
69 new notifier::FakePushClient())) {}
70
66 virtual void SetUp() { 71 virtual void SetUp() {
67 client_.Start(kClientId, kClientInfo, kState, 72 client_.Start(kClientId, kClientInfo, kState,
68 InvalidationVersionMap(), 73 InvalidationVersionMap(),
69 browser_sync::MakeWeakHandle( 74 browser_sync::MakeWeakHandle(
70 mock_invalidation_state_tracker_.AsWeakPtr()), 75 mock_invalidation_state_tracker_.AsWeakPtr()),
71 &mock_listener_, &mock_state_writer_, 76 &mock_listener_, &mock_state_writer_);
72 fake_base_task_.AsWeakPtr());
73 } 77 }
74 78
75 virtual void TearDown() { 79 virtual void TearDown() {
76 // client_.Stop() stops the invalidation scheduler, which deletes any 80 // client_.Stop() stops the invalidation scheduler, which deletes any
77 // pending tasks without running them. Some tasks "run and delete" another 81 // pending tasks without running them. Some tasks "run and delete" another
78 // task, so they must be run in order to avoid leaking the inner task. 82 // task, so they must be run in order to avoid leaking the inner task.
79 // client_.Stop() does not schedule any tasks, so it's both necessary and 83 // client_.Stop() does not schedule any tasks, so it's both necessary and
80 // sufficient to drain the task queue before calling it. 84 // sufficient to drain the task queue before calling it.
81 message_loop_.RunAllPending(); 85 message_loop_.RunAllPending();
82 client_.Stop(); 86 client_.Stop();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 EXPECT_CALL(mock_invalidation_client_, Acknowledge(ack_handle)); 122 EXPECT_CALL(mock_invalidation_client_, Acknowledge(ack_handle));
119 client_.InvalidateAll(&mock_invalidation_client_, ack_handle); 123 client_.InvalidateAll(&mock_invalidation_client_, ack_handle);
120 } 124 }
121 125
122 MessageLoop message_loop_; 126 MessageLoop message_loop_;
123 StrictMock<MockListener> mock_listener_; 127 StrictMock<MockListener> mock_listener_;
124 StrictMock<MockInvalidationStateTracker> 128 StrictMock<MockInvalidationStateTracker>
125 mock_invalidation_state_tracker_; 129 mock_invalidation_state_tracker_;
126 StrictMock<MockStateWriter> mock_state_writer_; 130 StrictMock<MockStateWriter> mock_state_writer_;
127 StrictMock<MockInvalidationClient> mock_invalidation_client_; 131 StrictMock<MockInvalidationClient> mock_invalidation_client_;
128 notifier::FakeBaseTask fake_base_task_;
129 ChromeInvalidationClient client_; 132 ChromeInvalidationClient client_;
130 }; 133 };
131 134
132 namespace { 135 namespace {
133 136
134 syncable::ModelTypePayloadMap MakeMap(syncable::ModelType model_type, 137 syncable::ModelTypePayloadMap MakeMap(syncable::ModelType model_type,
135 const std::string& payload) { 138 const std::string& payload) {
136 syncable::ModelTypePayloadMap type_payloads; 139 syncable::ModelTypePayloadMap type_payloads;
137 type_payloads[model_type] = payload; 140 type_payloads[model_type] = payload;
138 return type_payloads; 141 return type_payloads;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Registered types should be preserved across Stop/Start. 269 // Registered types should be preserved across Stop/Start.
267 TearDown(); 270 TearDown();
268 SetUp(); 271 SetUp();
269 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, ""))); 272 EXPECT_CALL(mock_listener_, OnInvalidate(MakeMapFromSet(types, "")));
270 FireInvalidateAll(); 273 FireInvalidateAll();
271 } 274 }
272 275
273 // TODO(akalin): Flesh out unit tests. 276 // TODO(akalin): Flesh out unit tests.
274 277
275 } // namespace sync_notifier 278 } // namespace sync_notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698