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

Unified Diff: sync/internal_api/syncapi_unittest.cc

Issue 10483015: [Sync] Refactor sync configuration logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use mock sync scheduler instead of DoConfigureSyncer 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/internal_api/sync_manager.cc ('k') | sync/sync.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/internal_api/syncapi_unittest.cc
diff --git a/sync/internal_api/syncapi_unittest.cc b/sync/internal_api/syncapi_unittest.cc
index 991aed6b0a6f82dcc38a483c8f23e35a11e18a7f..6380db3f8b5cb82052923b6cddff2cfc600da44d 100644
--- a/sync/internal_api/syncapi_unittest.cc
+++ b/sync/internal_api/syncapi_unittest.cc
@@ -24,6 +24,7 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "sync/engine/nigori_util.h"
+#include "sync/engine/sync_scheduler.h"
#include "sync/internal_api/change_record.h"
#include "sync/internal_api/http_post_provider_factory.h"
#include "sync/internal_api/http_post_provider_interface.h"
@@ -54,6 +55,7 @@
#include "sync/sessions/sync_session.h"
#include "sync/syncable/syncable.h"
#include "sync/syncable/syncable_id.h"
+#include "sync/test/callback_counter.h"
#include "sync/test/fake_encryptor.h"
#include "sync/test/fake_extensions_activity_monitor.h"
#include "sync/util/cryptographer.h"
@@ -64,6 +66,8 @@
#include "testing/gtest/include/gtest/gtest.h"
using base::ExpectDictStringValue;
+using browser_sync::CallbackCounter;
+using browser_sync::ConfigurationParams;
using browser_sync::Cryptographer;
using browser_sync::FakeEncryptor;
using browser_sync::FakeExtensionsActivityMonitor;
@@ -80,6 +84,7 @@ using browser_sync::MockJsReplyHandler;
using browser_sync::ModelSafeRoutingInfo;
using browser_sync::ModelSafeWorker;
using browser_sync::sessions::SyncSessionSnapshot;
+using browser_sync::SyncScheduler;
using browser_sync::TestUnrecoverableErrorHandler;
using browser_sync::WeakHandle;
using syncable::IS_DEL;
@@ -92,8 +97,10 @@ using syncable::SPECIFICS;
using testing::_;
using testing::AnyNumber;
using testing::AtLeast;
+using testing::DoAll;
using testing::InSequence;
using testing::Invoke;
+using testing::Return;
using testing::SaveArg;
using testing::StrictMock;
@@ -926,6 +933,10 @@ class SyncManagerTest : public testing::Test,
return true;
}
+ void SetScheduler(scoped_ptr<SyncScheduler> scheduler) {
+ sync_manager_.SetSyncSchedulerForTest(scheduler.Pass());
+ }
+
private:
// Needed by |sync_manager_|.
MessageLoop message_loop_;
@@ -2507,4 +2518,82 @@ TEST_F(SyncManagerTest, SetPreviouslyEncryptedSpecifics) {
}
}
+namespace {
+
+class MockSyncScheduler : public SyncScheduler {
+ public:
+ MockSyncScheduler() : SyncScheduler("name", NULL, NULL) {}
+ virtual ~MockSyncScheduler() {}
+
+ MOCK_METHOD1(Start, void(SyncScheduler::Mode));
+ MOCK_METHOD1(ScheduleConfiguration, bool(const ConfigurationParams&));
+};
+
+} // namespace
+
+// Test that the configuration params are properly created and sent to
+// ScheduleConfigure. No callback should be invoked.
+TEST_F(SyncManagerTest, BasicConfiguration) {
+ ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
+ syncable::ModelTypeSet types_to_download(syncable::BOOKMARKS,
+ syncable::PREFERENCES);
+ browser_sync::ModelSafeRoutingInfo new_routing_info;
+ GetModelSafeRoutingInfo(&new_routing_info);
+
+ scoped_ptr<MockSyncScheduler> scheduler(new MockSyncScheduler());
+ ConfigurationParams params;
+ EXPECT_CALL(*scheduler, Start(SyncScheduler::CONFIGURATION_MODE));
+ EXPECT_CALL(*scheduler, ScheduleConfiguration(_)).
+ WillOnce(DoAll(SaveArg<0>(&params), Return(true)));
+ SetScheduler(scheduler.PassAs<SyncScheduler>());
+
+ CallbackCounter ready_task_counter, retry_task_counter;
+ sync_manager_.ConfigureSyncer(
+ reason,
+ types_to_download,
+ new_routing_info,
+ base::Bind(&CallbackCounter::Callback,
+ base::Unretained(&ready_task_counter)),
+ base::Bind(&CallbackCounter::Callback,
+ base::Unretained(&retry_task_counter)));
+ EXPECT_EQ(0, ready_task_counter.times_called());
+ EXPECT_EQ(0, retry_task_counter.times_called());
+ EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
+ params.source);
+ EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
+ EXPECT_EQ(new_routing_info, params.routing_info);
+}
+
+// Test that the retry callback is invoked on configuration failure.
+TEST_F(SyncManagerTest, ConfigurationRetry) {
+ ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION;
+ syncable::ModelTypeSet types_to_download(syncable::BOOKMARKS,
+ syncable::PREFERENCES);
+ browser_sync::ModelSafeRoutingInfo new_routing_info;
+ GetModelSafeRoutingInfo(&new_routing_info);
+
+ scoped_ptr<MockSyncScheduler> scheduler(new MockSyncScheduler());
+ ConfigurationParams params;
+ EXPECT_CALL(*scheduler, Start(SyncScheduler::CONFIGURATION_MODE));
+ EXPECT_CALL(*scheduler, ScheduleConfiguration(_)).
+ WillOnce(DoAll(SaveArg<0>(&params), Return(false)));
+ SetScheduler(scheduler.PassAs<SyncScheduler>());
+
+ CallbackCounter ready_task_counter, retry_task_counter;
+ sync_manager_.ConfigureSyncer(
+ reason,
+ types_to_download,
+ new_routing_info,
+ base::Bind(&CallbackCounter::Callback,
+ base::Unretained(&ready_task_counter)),
+ base::Bind(&CallbackCounter::Callback,
+ base::Unretained(&retry_task_counter)));
+ EXPECT_EQ(0, ready_task_counter.times_called());
+ EXPECT_EQ(1, retry_task_counter.times_called());
+ EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
+ params.source);
+ EXPECT_TRUE(types_to_download.Equals(params.types_to_download));
+ EXPECT_EQ(new_routing_info, params.routing_info);
+}
+
} // namespace browser_sync
« no previous file with comments | « sync/internal_api/sync_manager.cc ('k') | sync/sync.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698