diff options
-rw-r--r-- | chrome/browser/sync/test/integration/sync_errors_test.cc | 26 | ||||
-rw-r--r-- | chrome/browser/sync/test/integration/sync_test.cc | 10 | ||||
-rw-r--r-- | chrome/browser/sync/test/integration/sync_test.h | 4 | ||||
-rw-r--r-- | sync/test/fake_server/fake_server.cc | 65 | ||||
-rw-r--r-- | sync/test/fake_server/fake_server.h | 9 |
5 files changed, 66 insertions, 48 deletions
diff --git a/chrome/browser/sync/test/integration/sync_errors_test.cc b/chrome/browser/sync/test/integration/sync_errors_test.cc index 5ffb83a..7375bff 100644 --- a/chrome/browser/sync/test/integration/sync_errors_test.cc +++ b/chrome/browser/sync/test/integration/sync_errors_test.cc @@ -44,15 +44,24 @@ bool AwaitSyncDisabled(ProfileSyncService* service) { class SyncErrorTest : public SyncTest { public: - // TODO(pvalenzuela): Switch to SINGLE_CLIENT once FakeServer - // supports this scenario. - SyncErrorTest() : SyncTest(SINGLE_CLIENT_LEGACY) {} + SyncErrorTest() : SyncTest(SINGLE_CLIENT) {} virtual ~SyncErrorTest() {} private: DISALLOW_COPY_AND_ASSIGN(SyncErrorTest); }; +// TODO(pvalenzuela): Remove this class when all tests here are converted to +// use FakeServer. +class LegacySyncErrorTest : public SyncTest { + public: + LegacySyncErrorTest() : SyncTest(SINGLE_CLIENT_LEGACY) {} + virtual ~LegacySyncErrorTest() {} + + private: + DISALLOW_COPY_AND_ASSIGN(LegacySyncErrorTest); +}; + // Helper class that waits until the sync engine has hit an actionable error. class ActionableErrorChecker : public SingleClientStatusChangeChecker { public: @@ -85,7 +94,7 @@ IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorTest) { const BookmarkNode* node1 = AddFolder(0, 0, L"title1"); SetTitle(0, node1, L"new_title1"); ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); - TriggerBirthdayError(); + ASSERT_TRUE(GetFakeServer()->SetNewStoreBirthday("new store birthday")); // Now make one more change so we will do another sync. const BookmarkNode* node2 = AddFolder(0, 0, L"title2"); @@ -93,7 +102,7 @@ IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorTest) { ASSERT_TRUE(AwaitSyncDisabled(GetSyncService((0)))); } -IN_PROC_BROWSER_TEST_F(SyncErrorTest, ActionableErrorTest) { +IN_PROC_BROWSER_TEST_F(LegacySyncErrorTest, ActionableErrorTest) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; const BookmarkNode* node1 = AddFolder(0, 0, L"title1"); @@ -126,7 +135,7 @@ IN_PROC_BROWSER_TEST_F(SyncErrorTest, ActionableErrorTest) { } // Disabled, http://crbug.com/351160 . -IN_PROC_BROWSER_TEST_F(SyncErrorTest, DISABLED_ErrorWhileSettingUp) { +IN_PROC_BROWSER_TEST_F(LegacySyncErrorTest, DISABLED_ErrorWhileSettingUp) { ASSERT_TRUE(SetupClients()); syncer::SyncProtocolError protocol_error; @@ -156,7 +165,7 @@ IN_PROC_BROWSER_TEST_F(SyncErrorTest, DISABLED_ErrorWhileSettingUp) { } } -IN_PROC_BROWSER_TEST_F(SyncErrorTest, +IN_PROC_BROWSER_TEST_F(LegacySyncErrorTest, BirthdayErrorUsingActionableErrorTest) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; @@ -185,7 +194,8 @@ IN_PROC_BROWSER_TEST_F(SyncErrorTest, } // TODO(lipalani): Fix the typed_url dtc so this test case can pass. -IN_PROC_BROWSER_TEST_F(SyncErrorTest, DISABLED_DisableDatatypeWhileRunning) { +IN_PROC_BROWSER_TEST_F(LegacySyncErrorTest, + DISABLED_DisableDatatypeWhileRunning) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; syncer::ModelTypeSet synced_datatypes = GetSyncService((0))->GetPreferredDataTypes(); diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index aeb6416..12b80fe 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -914,16 +914,6 @@ void SyncTest::TriggerMigrationDoneError(syncer::ModelTypeSet model_types) { GetTitle())); } -void SyncTest::TriggerBirthdayError() { - ASSERT_TRUE(ServerSupportsErrorTriggering()); - std::string path = "chromiumsync/birthdayerror"; - ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); - ASSERT_EQ("Birthday error", - base::UTF16ToASCII( - browser()->tab_strip_model()->GetActiveWebContents()-> - GetTitle())); -} - void SyncTest::TriggerTransientError() { ASSERT_TRUE(ServerSupportsErrorTriggering()); std::string path = "chromiumsync/transienterror"; diff --git a/chrome/browser/sync/test/integration/sync_test.h b/chrome/browser/sync/test/integration/sync_test.h index 6c32d83..c691a37 100644 --- a/chrome/browser/sync/test/integration/sync_test.h +++ b/chrome/browser/sync/test/integration/sync_test.h @@ -234,10 +234,6 @@ class SyncTest : public InProcessBrowserTest { // only if ServerSupportsErrorTriggering() returned true. void TriggerMigrationDoneError(syncer::ModelTypeSet model_types); - // Triggers the server to set its birthday to a random value thereby - // the server would return a birthday error on next sync. - void TriggerBirthdayError(); - // Triggers a transient error on the server. Note the server will stay in // this state until shut down. void TriggerTransientError(); diff --git a/sync/test/fake_server/fake_server.cc b/sync/test/fake_server/fake_server.cc index 207f1a2..d0ea4de 100644 --- a/sync/test/fake_server/fake_server.cc +++ b/sync/test/fake_server/fake_server.cc @@ -34,8 +34,8 @@ using syncer::GetModelType; using syncer::ModelType; using syncer::ModelTypeSet; -// The default birthday value. -static const char kDefaultBirthday[] = "1234567890"; +// The default store birthday value. +static const char kDefaultStoreBirthday[] = "1234567890"; // The default keystore key. static const char kDefaultKeystoreKey[] = "1111111111111111"; @@ -145,7 +145,7 @@ scoped_ptr<UpdateSieve> UpdateSieve::Create( } // namespace -FakeServer::FakeServer() : version_(0), birthday_(kDefaultBirthday) { +FakeServer::FakeServer() : version_(0), store_birthday_(kDefaultStoreBirthday) { keystore_keys_.push_back(kDefaultKeystoreKey); CHECK(CreateDefaultPermanentItems()); } @@ -218,32 +218,41 @@ void FakeServer::HandleCommand(const string& request, bool parsed = message.ParseFromString(request); DCHECK(parsed); + sync_pb::SyncEnums_ErrorType error_code; sync_pb::ClientToServerResponse response_proto; - bool success; - switch (message.message_contents()) { - case sync_pb::ClientToServerMessage::GET_UPDATES: - success = HandleGetUpdatesRequest(message.get_updates(), - response_proto.mutable_get_updates()); - break; - case sync_pb::ClientToServerMessage::COMMIT: - success = HandleCommitRequest(message.commit(), - message.invalidator_client_id(), - response_proto.mutable_commit()); - break; - default: - callback.Run(net::ERR_NOT_IMPLEMENTED, 0, string());; + + if (message.has_store_birthday() && + message.store_birthday() != store_birthday_) { + error_code = sync_pb::SyncEnums::NOT_MY_BIRTHDAY; + } else { + bool success = false; + switch (message.message_contents()) { + case sync_pb::ClientToServerMessage::GET_UPDATES: + success = HandleGetUpdatesRequest(message.get_updates(), + response_proto.mutable_get_updates()); + break; + case sync_pb::ClientToServerMessage::COMMIT: + success = HandleCommitRequest(message.commit(), + message.invalidator_client_id(), + response_proto.mutable_commit()); + break; + default: + callback.Run(net::ERR_NOT_IMPLEMENTED, 0, string());; + return; + } + + if (!success) { + // TODO(pvalenzuela): Add logging here so that tests have more info about + // the failure. + callback.Run(net::ERR_FAILED, 0, string()); return; - } + } - if (!success) { - // TODO(pvalenzuela): Add logging here so that tests have more info about - // the failure. - callback.Run(net::ERR_FAILED, 0, string()); - return; + error_code = sync_pb::SyncEnums::SUCCESS; } - response_proto.set_error_code(sync_pb::SyncEnums::SUCCESS); - response_proto.set_store_birthday(birthday_); + response_proto.set_error_code(error_code); + response_proto.set_store_birthday(store_birthday_); callback.Run(0, net::HTTP_OK, response_proto.SerializeAsString()); } @@ -473,6 +482,14 @@ void FakeServer::InjectEntity(scoped_ptr<FakeServerEntity> entity) { SaveEntity(entity.release()); } +bool FakeServer::SetNewStoreBirthday(const string& store_birthday) { + if (store_birthday_ == store_birthday) + return false; + + store_birthday_ = store_birthday; + return true; +} + void FakeServer::AddObserver(Observer* observer) { observers_.AddObserver(observer); } diff --git a/sync/test/fake_server/fake_server.h b/sync/test/fake_server/fake_server.h index c33db91..74e5536 100644 --- a/sync/test/fake_server/fake_server.h +++ b/sync/test/fake_server/fake_server.h @@ -57,6 +57,11 @@ class FakeServer { // result in successful server operations. void InjectEntity(scoped_ptr<FakeServerEntity> entity); + // Sets a new store birthday so that tests may trigger a NOT_MY_BIRTHDAY + // error. If |store_birthday| is the same as |store_birthday_|, false is + // returned and this method has no effect. + bool SetNewStoreBirthday(const std::string& store_birthday); + // Adds |observer| to FakeServer's observer list. This should be called // before the Profile associated with |observer| is connected to the server. void AddObserver(Observer* observer); @@ -115,8 +120,8 @@ class FakeServer { // have a version number of version_ + 1. int64 version_; - // The current birthday value. - std::string birthday_; + // The current store birthday value. + std::string store_birthday_; // All SyncEntity objects saved by the server. The key value is the entity's // id string. |