diff options
-rw-r--r-- | sync/engine/download.cc | 31 | ||||
-rw-r--r-- | sync/engine/download.h | 7 | ||||
-rw-r--r-- | sync/engine/download_unittest.cc | 52 | ||||
-rw-r--r-- | sync/engine/syncer_unittest.cc | 58 | ||||
-rw-r--r-- | sync/internal_api/debug_info_event_listener.cc | 22 | ||||
-rw-r--r-- | sync/internal_api/debug_info_event_listener.h | 14 | ||||
-rw-r--r-- | sync/internal_api/debug_info_event_listener_unittest.cc | 18 | ||||
-rw-r--r-- | sync/internal_api/public/sessions/model_neutral_state.cc | 1 | ||||
-rw-r--r-- | sync/internal_api/public/sessions/model_neutral_state.h | 3 | ||||
-rw-r--r-- | sync/sessions/debug_info_getter.h | 11 | ||||
-rw-r--r-- | sync/sessions/status_controller.cc | 8 | ||||
-rw-r--r-- | sync/sessions/status_controller.h | 4 | ||||
-rw-r--r-- | sync/sync_tests.gypi | 2 | ||||
-rw-r--r-- | sync/test/engine/mock_connection_manager.cc | 14 | ||||
-rw-r--r-- | sync/test/engine/mock_connection_manager.h | 9 | ||||
-rw-r--r-- | sync/test/sessions/mock_debug_info_getter.cc | 29 | ||||
-rw-r--r-- | sync/test/sessions/mock_debug_info_getter.h | 39 |
17 files changed, 219 insertions, 103 deletions
diff --git a/sync/engine/download.cc b/sync/engine/download.cc index 53d36f5..7d00beb 100644 --- a/sync/engine/download.cc +++ b/sync/engine/download.cc @@ -94,11 +94,6 @@ void InitDownloadUpdatesContext( // (e.g. Bookmark URLs but not their containing folders). get_updates->set_fetch_folders(true); - sync_pb::DebugInfo* debug_info = message->mutable_debug_info(); - AppendClientDebugInfoIfNeeded(session->context()->debug_info_getter(), - session->mutable_status_controller(), - debug_info); - get_updates->set_create_mobile_bookmarks_folder( create_mobile_bookmarks_folder); bool need_encryption_key = ShouldRequestEncryptionKey(session->context()); @@ -344,6 +339,11 @@ SyncerError ExecuteDownloadUpdates( StatusController* status = session->mutable_status_controller(); bool need_encryption_key = ShouldRequestEncryptionKey(session->context()); + if (session->context()->debug_info_getter()) { + sync_pb::DebugInfo* debug_info = msg->mutable_debug_info(); + CopyClientDebugInfo(session->context()->debug_info_getter(), debug_info); + } + SyncerError result = SyncerProtoUtil::PostClientToServerMessage( msg, &update_response, @@ -366,6 +366,12 @@ SyncerError ExecuteDownloadUpdates( << update_response.get_updates().changes_remaining() << " updates left on server."; + if (session->context()->debug_info_getter()) { + // Clear debug info now that we have successfully sent it to the server. + DVLOG(1) << "Clearing client debug info."; + session->context()->debug_info_getter()->ClearDebugInfo(); + } + if (need_encryption_key || update_response.get_updates().encryption_keys_size() > 0) { syncable::Directory* dir = session->context()->directory(); @@ -392,20 +398,11 @@ SyncerError ExecuteDownloadUpdates( } } -void AppendClientDebugInfoIfNeeded( +void CopyClientDebugInfo( sessions::DebugInfoGetter* debug_info_getter, - StatusController* status, sync_pb::DebugInfo* debug_info) { - // We want to send the debug info only once per sync cycle. Check if it has - // already been sent. - if (!status->debug_info_sent()) { - DVLOG(1) << "Sending client debug info ..."; - // Could be null in some unit tests. - if (debug_info_getter) { - debug_info_getter->GetAndClearDebugInfo(debug_info); - } - status->set_debug_info_sent(); - } + DVLOG(1) << "Copying client debug info to send."; + debug_info_getter->GetDebugInfo(debug_info); } } // namespace download diff --git a/sync/engine/download.h b/sync/engine/download.h index ec085c9..952823f 100644 --- a/sync/engine/download.h +++ b/sync/engine/download.h @@ -82,11 +82,10 @@ SYNC_EXPORT_PRIVATE SyncerError sessions::SyncSession* session, sync_pb::ClientToServerMessage* msg); -// Helper function to append client debug info to the message, but only do so -// once per sync cycle. Defined here for testing. -void SYNC_EXPORT_PRIVATE AppendClientDebugInfoIfNeeded( +// Helper function to copy client debug info from debug_info_getter to +// debug_info. Defined here for testing. +void SYNC_EXPORT_PRIVATE CopyClientDebugInfo( sessions::DebugInfoGetter* debug_info_getter, - sessions::StatusController* status, sync_pb::DebugInfo* debug_info); } // namespace download diff --git a/sync/engine/download_unittest.cc b/sync/engine/download_unittest.cc index f38ab2b..9336893 100644 --- a/sync/engine/download_unittest.cc +++ b/sync/engine/download_unittest.cc @@ -14,10 +14,13 @@ #include "sync/sessions/status_controller.h" #include "sync/syncable/directory.h" #include "sync/test/engine/test_directory_setter_upper.h" +#include "sync/test/sessions/mock_debug_info_getter.h" #include "testing/gtest/include/gtest/gtest.h" namespace syncer { +using sessions::MockDebugInfoGetter; + // A test fixture for tests exercising download updates functions. class DownloadUpdatesTest : public ::testing::Test { protected: @@ -201,24 +204,6 @@ TEST_F(DownloadUpdatesTest, PollTest) { EXPECT_TRUE(proto_request_types().Equals(progress_types)); } -class MockDebugInfoGetter : public sessions::DebugInfoGetter { - public: - MockDebugInfoGetter() {} - virtual ~MockDebugInfoGetter() {} - - virtual void GetAndClearDebugInfo(sync_pb::DebugInfo* debug_info) OVERRIDE { - debug_info->CopyFrom(debug_info_); - debug_info_.Clear(); - } - - void AddDebugEvent() { - debug_info_.add_events(); - } - - private: - sync_pb::DebugInfo debug_info_; -}; - class DownloadUpdatesDebugInfoTest : public ::testing::Test { public: DownloadUpdatesDebugInfoTest() {} @@ -242,33 +227,20 @@ class DownloadUpdatesDebugInfoTest : public ::testing::Test { }; -// Verify AppendDebugInfo when there are no events to upload. -TEST_F(DownloadUpdatesDebugInfoTest, VerifyAppendDebugInfo_Empty) { +// Verify CopyClientDebugInfo when there are no events to upload. +TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyClientDebugInfo_Empty) { sync_pb::DebugInfo debug_info; - download::AppendClientDebugInfoIfNeeded(debug_info_getter(), - status(), - &debug_info); + download::CopyClientDebugInfo(debug_info_getter(), &debug_info); EXPECT_EQ(0, debug_info.events_size()); } -// We should upload debug info only once per sync cycle. -TEST_F(DownloadUpdatesDebugInfoTest, TryDoubleAppend) { - sync_pb::DebugInfo debug_info1; - - AddDebugEvent(); - download::AppendClientDebugInfoIfNeeded(debug_info_getter(), - status(), - &debug_info1); - EXPECT_EQ(1, debug_info1.events_size()); - - - // Repeated invocations should not send up more events. +TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { + sync_pb::DebugInfo debug_info; AddDebugEvent(); - sync_pb::DebugInfo debug_info2; - download::AppendClientDebugInfoIfNeeded(debug_info_getter(), - status(), - &debug_info2); - EXPECT_EQ(0, debug_info2.events_size()); + download::CopyClientDebugInfo(debug_info_getter(), &debug_info); + EXPECT_EQ(1, debug_info.events_size()); + download::CopyClientDebugInfo(debug_info_getter(), &debug_info); + EXPECT_EQ(1, debug_info.events_size()); } } // namespace syncer diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index e31a08e..e4755b6 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -50,6 +50,7 @@ #include "sync/test/engine/test_syncable_utils.h" #include "sync/test/fake_encryptor.h" #include "sync/test/fake_sync_encryption_handler.h" +#include "sync/test/sessions/mock_debug_info_getter.h" #include "sync/util/cryptographer.h" #include "sync/util/extensions_activity.h" #include "sync/util/time.h" @@ -104,6 +105,7 @@ using syncable::SPECIFICS; using syncable::SYNCING; using syncable::UNITTEST; +using sessions::MockDebugInfoGetter; using sessions::StatusController; using sessions::SyncSessionContext; using sessions::SyncSession; @@ -204,6 +206,7 @@ class SyncerTest : public testing::Test, dir_maker_.SetUp(); mock_server_.reset(new MockConnectionManager(directory(), &cancelation_signal_)); + debug_info_getter_.reset(new MockDebugInfoGetter); EnableDatatype(BOOKMARKS); EnableDatatype(NIGORI); EnableDatatype(PREFERENCES); @@ -222,7 +225,7 @@ class SyncerTest : public testing::Test, new SyncSessionContext( mock_server_.get(), directory(), workers, extensions_activity_, - listeners, NULL, &traffic_recorder_, + listeners, debug_info_getter_.get(), &traffic_recorder_, true, // enable keystore encryption false, // force enable pre-commit GU avoidance experiment "fake_invalidator_client_id")); @@ -490,6 +493,7 @@ class SyncerTest : public testing::Test, ModelTypeSet enabled_datatypes_; TrafficRecorder traffic_recorder_; sessions::NudgeTracker nudge_tracker_; + scoped_ptr<MockDebugInfoGetter> debug_info_getter_; DISALLOW_COPY_AND_ASSIGN(SyncerTest); }; @@ -2515,6 +2519,58 @@ TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { directory()->unsynced_entity_count()); } +// Tests that sending debug info events works. +TEST_F(SyncerTest, SendDebugInfoEvents_HappyCase) { + debug_info_getter_->AddDebugEvent(); + debug_info_getter_->AddDebugEvent(); + + SyncShareNudge(); + + // Verify we received one request with two debug info events. + EXPECT_EQ(1U, mock_server_->requests().size()); + EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size()); + + SyncShareNudge(); + + // See that we received another request, but that it contains no debug info + // events. + EXPECT_EQ(2U, mock_server_->requests().size()); + EXPECT_EQ(0, mock_server_->requests().back().debug_info().events_size()); + + debug_info_getter_->AddDebugEvent(); + + SyncShareNudge(); + + // See that we received another request and it contains one debug info event. + EXPECT_EQ(3U, mock_server_->requests().size()); + EXPECT_EQ(1, mock_server_->requests().back().debug_info().events_size()); +} + +// Tests that debug info events are dropped on server error. +TEST_F(SyncerTest, SendDebugInfoEvents_PostFailsDontDrop) { + debug_info_getter_->AddDebugEvent(); + debug_info_getter_->AddDebugEvent(); + + mock_server_->FailNextPostBufferToPathCall(); + SyncShareNudge(); + + // Verify we attempted to send one request with two debug info events. + EXPECT_EQ(1U, mock_server_->requests().size()); + EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size()); + + SyncShareNudge(); + + // See that the client resent the two debug info events. + EXPECT_EQ(2U, mock_server_->requests().size()); + EXPECT_EQ(2, mock_server_->requests().back().debug_info().events_size()); + + // The previous send was successful so this next one shouldn't generate any + // debug info events. + SyncShareNudge(); + EXPECT_EQ(3U, mock_server_->requests().size()); + EXPECT_EQ(0, mock_server_->requests().back().debug_info().events_size()); +} + TEST_F(SyncerTest, HugeConflict) { int item_count = 300; // We should be able to do 300 or 3000 w/o issue. diff --git a/sync/internal_api/debug_info_event_listener.cc b/sync/internal_api/debug_info_event_listener.cc index 7875ed9..f46c4ee 100644 --- a/sync/internal_api/debug_info_event_listener.cc +++ b/sync/internal_api/debug_info_event_listener.cc @@ -144,22 +144,28 @@ void DebugInfoEventListener::OnIncomingNotification( AddEventToQueue(event_info); } -void DebugInfoEventListener::GetAndClearDebugInfo( - sync_pb::DebugInfo* debug_info) { +void DebugInfoEventListener::GetDebugInfo(sync_pb::DebugInfo* debug_info) { DCHECK(thread_checker_.CalledOnValidThread()); DCHECK_LE(events_.size(), kMaxEntries); - while (!events_.empty()) { + + for (DebugEventInfoQueue::const_iterator iter = events_.begin(); + iter != events_.end(); + ++iter) { sync_pb::DebugEventInfo* event_info = debug_info->add_events(); - const sync_pb::DebugEventInfo& debug_event_info = events_.front(); - event_info->CopyFrom(debug_event_info); - events_.pop(); + event_info->CopyFrom(*iter); } debug_info->set_events_dropped(events_dropped_); debug_info->set_cryptographer_ready(cryptographer_ready_); debug_info->set_cryptographer_has_pending_keys( cryptographer_has_pending_keys_); +} + +void DebugInfoEventListener::ClearDebugInfo() { + DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_LE(events_.size(), kMaxEntries); + events_.clear(); events_dropped_ = false; } @@ -255,10 +261,10 @@ void DebugInfoEventListener::AddEventToQueue( DVLOG(1) << "DebugInfoEventListener::AddEventToQueue Dropping an old event " << "because of full queue"; - events_.pop(); + events_.pop_front(); events_dropped_ = true; } - events_.push(event_info); + events_.push_back(event_info); } } // namespace syncer diff --git a/sync/internal_api/debug_info_event_listener.h b/sync/internal_api/debug_info_event_listener.h index ee12c54..15cc0a6 100644 --- a/sync/internal_api/debug_info_event_listener.h +++ b/sync/internal_api/debug_info_event_listener.h @@ -5,7 +5,7 @@ #ifndef SYNC_INTERNAL_API_DEBUG_INFO_EVENT_LISTENER_H_ #define SYNC_INTERNAL_API_DEBUG_INFO_EVENT_LISTENER_H_ -#include <queue> +#include <deque> #include <string> #include "base/compiler_specific.h" @@ -75,7 +75,10 @@ class SYNC_EXPORT_PRIVATE DebugInfoEventListener void OnIncomingNotification(const ObjectIdInvalidationMap& invalidations); // DebugInfoGetter implementation. - virtual void GetAndClearDebugInfo(sync_pb::DebugInfo* debug_info) OVERRIDE; + virtual void GetDebugInfo(sync_pb::DebugInfo* debug_info) OVERRIDE; + + // DebugInfoGetter implementation. + virtual void ClearDebugInfo() OVERRIDE; // DataTypeDebugInfoListener implementation. virtual void OnDataTypeConfigureComplete( @@ -88,11 +91,14 @@ class SYNC_EXPORT_PRIVATE DebugInfoEventListener private: FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyEventsAdded); FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyQueueSize); - FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyGetAndClearEvents); + FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyGetEvents); + FRIEND_TEST_ALL_PREFIXES(DebugInfoEventListenerTest, VerifyClearEvents); void AddEventToQueue(const sync_pb::DebugEventInfo& event_info); void CreateAndAddEvent(sync_pb::DebugEventInfo::SingletonEventType type); - std::queue<sync_pb::DebugEventInfo> events_; + + typedef std::deque<sync_pb::DebugEventInfo> DebugEventInfoQueue; + DebugEventInfoQueue events_; // True indicates we had to drop one or more events to keep our limit of // |kMaxEntries|. diff --git a/sync/internal_api/debug_info_event_listener_unittest.cc b/sync/internal_api/debug_info_event_listener_unittest.cc index 131728b..31f16f8 100644 --- a/sync/internal_api/debug_info_event_listener_unittest.cc +++ b/sync/internal_api/debug_info_event_listener_unittest.cc @@ -29,23 +29,33 @@ TEST_F(DebugInfoEventListenerTest, VerifyQueueSize) { sync_pb::DebugEventInfo::ENCRYPTION_COMPLETE); } sync_pb::DebugInfo debug_info; - debug_info_event_listener.GetAndClearDebugInfo(&debug_info); + debug_info_event_listener.GetDebugInfo(&debug_info); + debug_info_event_listener.ClearDebugInfo(); ASSERT_TRUE(debug_info.events_dropped()); ASSERT_EQ(static_cast<int>(kMaxEntries), debug_info.events_size()); } -TEST_F(DebugInfoEventListenerTest, VerifyGetAndClearEvents) { +TEST_F(DebugInfoEventListenerTest, VerifyGetEvents) { DebugInfoEventListener debug_info_event_listener; debug_info_event_listener.CreateAndAddEvent( sync_pb::DebugEventInfo::ENCRYPTION_COMPLETE); ASSERT_EQ(debug_info_event_listener.events_.size(), 1U); sync_pb::DebugInfo debug_info; - debug_info_event_listener.GetAndClearDebugInfo(&debug_info); - ASSERT_EQ(debug_info_event_listener.events_.size(), 0U); + debug_info_event_listener.GetDebugInfo(&debug_info); + ASSERT_EQ(debug_info_event_listener.events_.size(), 1U); ASSERT_EQ(debug_info.events_size(), 1); ASSERT_TRUE(debug_info.events(0).has_singleton_event()); ASSERT_EQ(debug_info.events(0).singleton_event(), sync_pb::DebugEventInfo::ENCRYPTION_COMPLETE); } +TEST_F(DebugInfoEventListenerTest, VerifyClearEvents) { + DebugInfoEventListener debug_info_event_listener; + debug_info_event_listener.CreateAndAddEvent( + sync_pb::DebugEventInfo::ENCRYPTION_COMPLETE); + ASSERT_EQ(debug_info_event_listener.events_.size(), 1U); + debug_info_event_listener.ClearDebugInfo(); + ASSERT_EQ(debug_info_event_listener.events_.size(), 0U); +} + } // namespace syncer diff --git a/sync/internal_api/public/sessions/model_neutral_state.cc b/sync/internal_api/public/sessions/model_neutral_state.cc index b1a1706..fa2b019 100644 --- a/sync/internal_api/public/sessions/model_neutral_state.cc +++ b/sync/internal_api/public/sessions/model_neutral_state.cc @@ -23,7 +23,6 @@ ModelNeutralState::ModelNeutralState() last_download_updates_result(UNSET), commit_result(UNSET), items_committed(false), - debug_info_sent(false), num_server_changes_remaining(0) { } diff --git a/sync/internal_api/public/sessions/model_neutral_state.h b/sync/internal_api/public/sessions/model_neutral_state.h index 3a9d744..ee9c974 100644 --- a/sync/internal_api/public/sessions/model_neutral_state.h +++ b/sync/internal_api/public/sessions/model_neutral_state.h @@ -63,9 +63,6 @@ struct SYNC_EXPORT ModelNeutralState { // Set to true by PostCommitMessageCommand if any commits were successful. bool items_committed; - // True indicates debug info has been sent once this session. - bool debug_info_sent; - // Number of changes remaining, according to the server. // Take it as an estimate unless it's value is zero, in which case there // really is nothing more to download. diff --git a/sync/sessions/debug_info_getter.h b/sync/sessions/debug_info_getter.h index c1536ba..7efe0cb 100644 --- a/sync/sessions/debug_info_getter.h +++ b/sync/sessions/debug_info_getter.h @@ -15,9 +15,13 @@ namespace sessions { // to communicate the debug info data to the syncer. class SYNC_EXPORT_PRIVATE DebugInfoGetter { public: - // Gets the client debug info and clears the state so the same data is not - // sent again. - virtual void GetAndClearDebugInfo(sync_pb::DebugInfo* debug_info) = 0; + // Gets the client debug info. Be sure to clear the info to ensure the data + // isn't sent multiple times. + virtual void GetDebugInfo(sync_pb::DebugInfo* debug_info) = 0; + + // Clears the debug info. + virtual void ClearDebugInfo() = 0; + virtual ~DebugInfoGetter() {} }; @@ -25,4 +29,3 @@ class SYNC_EXPORT_PRIVATE DebugInfoGetter { } // namespace syncer #endif // SYNC_SESSIONS_DEBUG_INFO_GETTER_H_ - diff --git a/sync/sessions/status_controller.cc b/sync/sessions/status_controller.cc index abd6f1e..f6fbdb5 100644 --- a/sync/sessions/status_controller.cc +++ b/sync/sessions/status_controller.cc @@ -163,13 +163,5 @@ bool StatusController::ServerSaysNothingMoreToDownload() const { return updates_response().get_updates().changes_remaining() == 0; } -void StatusController::set_debug_info_sent() { - model_neutral_.debug_info_sent = true; -} - -bool StatusController::debug_info_sent() const { - return model_neutral_.debug_info_sent; -} - } // namespace sessions } // namespace syncer diff --git a/sync/sessions/status_controller.h b/sync/sessions/status_controller.h index 101e583..75b8b82 100644 --- a/sync/sessions/status_controller.h +++ b/sync/sessions/status_controller.h @@ -141,10 +141,6 @@ class SYNC_EXPORT_PRIVATE StatusController { void UpdateStartTime(); - void set_debug_info_sent(); - - bool debug_info_sent() const; - private: friend class ScopedModelSafeGroupRestriction; diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi index f3acf45..1b5871a85 100644 --- a/sync/sync_tests.gypi +++ b/sync/sync_tests.gypi @@ -56,6 +56,8 @@ 'test/null_transaction_observer.cc', 'test/null_transaction_observer.h', 'test/sessions/test_scoped_session_event_listener.h', + 'test/sessions/mock_debug_info_getter.h', + 'test/sessions/mock_debug_info_getter.cc', 'test/test_directory_backing_store.cc', 'test/test_directory_backing_store.h', 'test/test_transaction_observer.cc', diff --git a/sync/test/engine/mock_connection_manager.cc b/sync/test/engine/mock_connection_manager.cc index 624e022..434f6c3 100644 --- a/sync/test/engine/mock_connection_manager.cc +++ b/sync/test/engine/mock_connection_manager.cc @@ -83,7 +83,8 @@ bool MockConnectionManager::PostBufferToPath(PostBufferParams* params, CHECK(post.has_protocol_version()); CHECK(post.has_api_key()); CHECK(post.has_bag_of_chips()); - last_request_.CopyFrom(post); + + requests_.push_back(post); client_stuck_ = post.sync_problem_detected(); sync_pb::ClientToServerResponse response; response.Clear(); @@ -686,6 +687,17 @@ const CommitResponse& MockConnectionManager::last_commit_response() const { return *commit_responses_.back(); } +const sync_pb::ClientToServerMessage& + MockConnectionManager::last_request() const { + EXPECT_TRUE(!requests_.empty()); + return requests_.back(); +} + +const std::vector<sync_pb::ClientToServerMessage>& + MockConnectionManager::requests() const { + return requests_; +} + bool MockConnectionManager::IsModelTypePresentInSpecifics( const google::protobuf::RepeatedPtrField< sync_pb::DataTypeProgressMarker>& filter, diff --git a/sync/test/engine/mock_connection_manager.h b/sync/test/engine/mock_connection_manager.h index afeaac8..6b95eab 100644 --- a/sync/test/engine/mock_connection_manager.h +++ b/sync/test/engine/mock_connection_manager.h @@ -194,9 +194,10 @@ class MockConnectionManager : public ServerConnectionManager { const sync_pb::CommitResponse& last_commit_response() const; // Retrieve the last request submitted to the server (regardless of type). - const sync_pb::ClientToServerMessage& last_request() const { - return last_request_; - } + const sync_pb::ClientToServerMessage& last_request() const; + + // Retrieve the cumulative collection of all requests sent by clients. + const std::vector<sync_pb::ClientToServerMessage>& requests() const; void set_conflict_all_commits(bool value) { conflict_all_commits_ = value; @@ -395,7 +396,7 @@ class MockConnectionManager : public ServerConnectionManager { std::string next_token_; - sync_pb::ClientToServerMessage last_request_; + std::vector<sync_pb::ClientToServerMessage> requests_; DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); }; diff --git a/sync/test/sessions/mock_debug_info_getter.cc b/sync/test/sessions/mock_debug_info_getter.cc new file mode 100644 index 0000000..524c5cf --- /dev/null +++ b/sync/test/sessions/mock_debug_info_getter.cc @@ -0,0 +1,29 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "sync/test/sessions/mock_debug_info_getter.h" + +namespace syncer { +namespace sessions { + +MockDebugInfoGetter::MockDebugInfoGetter() { +} + +MockDebugInfoGetter::~MockDebugInfoGetter() { +} + +void MockDebugInfoGetter::GetDebugInfo(sync_pb::DebugInfo* debug_info) { + debug_info->CopyFrom(debug_info_); +} + +void MockDebugInfoGetter::ClearDebugInfo() { + debug_info_.Clear(); +} + +void MockDebugInfoGetter::AddDebugEvent() { + debug_info_.add_events(); +} + +} // namespace sessions +} // namespace syncer diff --git a/sync/test/sessions/mock_debug_info_getter.h b/sync/test/sessions/mock_debug_info_getter.h new file mode 100644 index 0000000..e66a962 --- /dev/null +++ b/sync/test/sessions/mock_debug_info_getter.h @@ -0,0 +1,39 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SYNC_SESSIONS_MOCK_DEBUG_INFO_GETTER_H_ +#define SYNC_SESSIONS_MOCK_DEBUG_INFO_GETTER_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "sync/base/sync_export.h" +#include "sync/protocol/sync.pb.h" +#include "sync/sessions/debug_info_getter.h" + +namespace syncer { +namespace sessions { + +// A mock implementation of DebugInfoGetter to be used in tests. Events added by +// AddDebugEvent are accessible via DebugInfoGetter methods. +class MockDebugInfoGetter : public sessions::DebugInfoGetter { + public: + MockDebugInfoGetter(); + virtual ~MockDebugInfoGetter(); + + // DebugInfoGetter implementation. + virtual void GetDebugInfo(sync_pb::DebugInfo* debug_info) OVERRIDE; + virtual void ClearDebugInfo() OVERRIDE; + + void AddDebugEvent(); + + private: + sync_pb::DebugInfo debug_info_; + + DISALLOW_COPY_AND_ASSIGN(MockDebugInfoGetter); +}; + +} // namespace sessions +} // namespace syncer + +#endif // SYNC_SESSIONS_MOCK_DEBUG_INFO_GETTER_H_ |