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

Unified Diff: sync/internal_api/syncapi_unittest.cc

Issue 10701085: Revert "Revert 142517 - [Sync] Refactor sync configuration logic." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix deps Created 8 years, 5 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
Index: sync/internal_api/syncapi_unittest.cc
diff --git a/sync/internal_api/syncapi_unittest.cc b/sync/internal_api/syncapi_unittest.cc
index 6fff8c5e9ea779ed57dcb72d5fddc267904e8eea..34acd8ef9d6e4903cb40769342788ed14ad49c4a 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/internal_api/public/base/model_type_test_util.h"
+#include "sync/engine/sync_scheduler.h"
#include "sync/internal_api/public/change_record.h"
#include "sync/internal_api/public/engine/model_safe_worker.h"
#include "sync/internal_api/public/engine/polling_constants.h"
@@ -57,6 +58,7 @@
#include "sync/syncable/nigori_util.h"
#include "sync/syncable/syncable_id.h"
#include "sync/syncable/write_transaction.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"
@@ -70,8 +72,10 @@ using base::ExpectDictStringValue;
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;
@@ -764,10 +768,13 @@ class SyncManagerTest : public testing::Test,
WeakHandle<JsEventHandler>(),
"bogus", 0, false,
base::MessageLoopProxy::current(),
- new TestHttpPostProviderFactory(), routing_info, workers,
+ scoped_ptr<HttpPostProviderFactory>(
+ new TestHttpPostProviderFactory()),
+ routing_info, workers,
&extensions_activity_monitor_, this,
credentials,
- sync_notifier_mock_, "",
+ scoped_ptr<SyncNotifier>(sync_notifier_mock_),
+ "",
syncer::SyncManager::TEST_IN_MEMORY,
&encryptor_,
&handler_,
@@ -906,6 +913,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_;
@@ -2485,4 +2496,78 @@ TEST_F(SyncManagerTest, SetPreviouslyEncryptedSpecifics) {
}
}
-} // namespace syncer
+class MockSyncScheduler : public SyncScheduler {
+ public:
+ MockSyncScheduler() : SyncScheduler("name", NULL, NULL) {}
+ virtual ~MockSyncScheduler() {}
+
+ MOCK_METHOD1(Start, void(SyncScheduler::Mode));
+ MOCK_METHOD1(ScheduleConfiguration, bool(const ConfigurationParams&));
+};
+
+// 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;
+ syncer::ModelTypeSet types_to_download(syncer::BOOKMARKS,
+ syncer::PREFERENCES);
+ syncer::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;
+ syncer::ModelTypeSet types_to_download(syncer::BOOKMARKS,
+ syncer::PREFERENCES);
+ syncer::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

Powered by Google App Engine
This is Rietveld 408576698