diff options
author | lipalani@chromium.org <lipalani@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-30 02:17:37 +0000 |
---|---|---|
committer | lipalani@chromium.org <lipalani@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-30 02:17:37 +0000 |
commit | a887390640cf23cea3c5c97840744d5eaf145f7f (patch) | |
tree | 359dd6073f6fe92daac3fa9579b8fa8ac025df6e | |
parent | 153b8f2a9522b68ee55941164e6bda5a5cbfd6bf (diff) | |
download | chromium_src-a887390640cf23cea3c5c97840744d5eaf145f7f.zip chromium_src-a887390640cf23cea3c5c97840744d5eaf145f7f.tar.gz chromium_src-a887390640cf23cea3c5c97840744d5eaf145f7f.tar.bz2 |
Test birtday error.
BUG=
TEST=
Review URL: http://codereview.chromium.org/7481009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94818 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/sync/engine/syncer_proto_util.cc | 5 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_harness.cc | 16 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service_harness.h | 7 | ||||
-rw-r--r-- | chrome/browser/sync/protocol/sync.proto | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/test/live_sync/live_sync_test.cc | 8 | ||||
-rw-r--r-- | chrome/test/live_sync/live_sync_test.h | 4 | ||||
-rw-r--r-- | chrome/test/live_sync/sync_errors_test.cc | 34 | ||||
-rwxr-xr-x | net/tools/testserver/chromiumsync.py | 20 | ||||
-rwxr-xr-x | net/tools/testserver/testserver.py | 15 |
10 files changed, 105 insertions, 7 deletions
diff --git a/chrome/browser/sync/engine/syncer_proto_util.cc b/chrome/browser/sync/engine/syncer_proto_util.cc index e96af94..6dae768 100644 --- a/chrome/browser/sync/engine/syncer_proto_util.cc +++ b/chrome/browser/sync/engine/syncer_proto_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -99,7 +99,8 @@ bool SyncerProtoUtil::VerifyResponseBirthday(syncable::Directory* dir, std::string local_birthday = dir->store_birthday(); - if (response->error_code() == ClientToServerResponse::CLEAR_PENDING) { + if (response->error_code() == ClientToServerResponse::CLEAR_PENDING || + response->error_code() == ClientToServerResponse::NOT_MY_BIRTHDAY) { // Birthday verification failures result in stopping sync and deleting // local sync data. return false; diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc index 44ef947..d2fb640 100644 --- a/chrome/browser/sync/profile_sync_service_harness.cc +++ b/chrome/browser/sync/profile_sync_service_harness.cc @@ -319,6 +319,14 @@ bool ProfileSyncServiceHarness::RunStateChangeMachine() { } break; } + case WAITING_FOR_SYNC_DISABLED: { + VLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_DISABLED"); + if (service()->HasSyncSetupCompleted() == false) { + // Sync has been disabled. + SignalStateCompleteWithNextState(SYNC_DISABLED); + } + break; + } case SERVER_UNREACHABLE: { VLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); if (GetStatus().server_reachable) { @@ -461,6 +469,14 @@ bool ProfileSyncServiceHarness::AwaitSyncCycleCompletion( } } +bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { + DCHECK(service()->HasSyncSetupCompleted()); + DCHECK_NE(wait_state_, SYNC_DISABLED); + wait_state_ = WAITING_FOR_SYNC_DISABLED; + AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); + return wait_state_ == SYNC_DISABLED; +} + bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( ProfileSyncServiceHarness* partner) { VLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); diff --git a/chrome/browser/sync/profile_sync_service_harness.h b/chrome/browser/sync/profile_sync_service_harness.h index fa8e9d9..4423e87 100644 --- a/chrome/browser/sync/profile_sync_service_harness.h +++ b/chrome/browser/sync/profile_sync_service_harness.h @@ -72,6 +72,10 @@ class ProfileSyncServiceHarness : public ProfileSyncServiceObserver { // since the previous one. Returns true if a sync cycle has completed. bool AwaitSyncCycleCompletion(const std::string& reason); + // Blocks the caller until the sync has been disabled for this client. Returns + // true if sync is disabled. + bool AwaitSyncDisabled(const std::string& reason); + // Blocks the caller until this harness has observed that the sync engine // has downloaded all the changes seen by the |partner| harness's client. bool WaitUntilTimestampMatches( @@ -183,6 +187,9 @@ class ProfileSyncServiceHarness : public ProfileSyncServiceObserver { // full sync cycle is not expected to occur. WAITING_FOR_SYNC_CONFIGURATION, + // The sync client is waiting for the sync to be disabled for this client. + WAITING_FOR_SYNC_DISABLED, + // The sync client needs a passphrase in order to decrypt data. SET_PASSPHRASE_FAILED, diff --git a/chrome/browser/sync/protocol/sync.proto b/chrome/browser/sync/protocol/sync.proto index 2fee8da..80cef9f 100644 --- a/chrome/browser/sync/protocol/sync.proto +++ b/chrome/browser/sync/protocol/sync.proto @@ -419,7 +419,7 @@ message ClearUserDataResponse { message ClientToServerMessage { required string share = 1; - optional int32 protocol_version = 2 [default = 28]; + optional int32 protocol_version = 2 [default = 29]; enum Contents { COMMIT = 1; GET_UPDATES = 2; diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index be7f7e5..8c45f72 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -3538,6 +3538,7 @@ 'test/live_sync/single_client_preferences_sync_test.cc', 'test/live_sync/sync_datatype_helper.cc', 'test/live_sync/sync_datatype_helper.h', + 'test/live_sync/sync_errors_test.cc', 'test/live_sync/two_client_bookmarks_sync_test.cc', 'test/live_sync/two_client_live_apps_sync_test.cc', 'test/live_sync/two_client_live_autofill_sync_test.cc', diff --git a/chrome/test/live_sync/live_sync_test.cc b/chrome/test/live_sync/live_sync_test.cc index 7198387..571e9a3 100644 --- a/chrome/test/live_sync/live_sync_test.cc +++ b/chrome/test/live_sync/live_sync_test.cc @@ -515,6 +515,14 @@ void LiveSyncTest::TriggerMigrationDoneError( browser()->GetSelectedTabContents()->GetTitle()); } +void LiveSyncTest::TriggerBirthdayError() { + ASSERT_TRUE(ServerSupportsErrorTriggering()); + std::string path = "chromiumsync/birthdayerror"; + ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); + ASSERT_EQ(ASCIIToUTF16("Birthday error"), + browser()->GetSelectedTabContents()->GetTitle()); +} + void LiveSyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, const net::ProxyConfig& proxy_config) { base::WaitableEvent done(false, false); diff --git a/chrome/test/live_sync/live_sync_test.h b/chrome/test/live_sync/live_sync_test.h index 6e088ab..0888fd4 100644 --- a/chrome/test/live_sync/live_sync_test.h +++ b/chrome/test/live_sync/live_sync_test.h @@ -138,6 +138,10 @@ class LiveSyncTest : public InProcessBrowserTest { // only if ServerSupportsErrorTriggering() returned true. void TriggerMigrationDoneError(const syncable::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(); + protected: // InProcessBrowserTest override. Destroys all the sync clients and sync // profiles created by a test. diff --git a/chrome/test/live_sync/sync_errors_test.cc b/chrome/test/live_sync/sync_errors_test.cc new file mode 100644 index 0000000..f062cca --- /dev/null +++ b/chrome/test/live_sync/sync_errors_test.cc @@ -0,0 +1,34 @@ +// Copyright (c) 2011 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 "chrome/browser/sync/profile_sync_service_harness.h" + +#include "chrome/test/live_sync/live_sync_test.h" + +#include "chrome/test/live_sync/bookmarks_helper.h" + +class SyncErrorTest : public LiveSyncTest{ + public: + SyncErrorTest() : LiveSyncTest(SINGLE_CLIENT) { + } + ~SyncErrorTest() {} + + private: + DISALLOW_COPY_AND_ASSIGN(SyncErrorTest); + +}; + +IN_PROC_BROWSER_TEST_F(SyncErrorTest, BirthdayErrorTest) { + ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; + + const BookmarkNode* node1 = BookmarksHelper::AddFolder(0, 0, L"title1"); + BookmarksHelper::SetTitle(0, node1, L"new_title1"); + ASSERT_TRUE(GetClient(0)->AwaitSyncCycleCompletion("Offline state change.")); + TriggerBirthdayError(); + + // Now make one more change so we will do another sync. + const BookmarkNode* node2 = BookmarksHelper::AddFolder(0, 0, L"title2"); + BookmarksHelper::SetTitle(0, node2, L"new_title2"); + ASSERT_TRUE(GetClient(0)->AwaitSyncDisabled("Birthday error.")); +} diff --git a/net/tools/testserver/chromiumsync.py b/net/tools/testserver/chromiumsync.py index 8257009..ac50e7d 100755 --- a/net/tools/testserver/chromiumsync.py +++ b/net/tools/testserver/chromiumsync.py @@ -407,8 +407,7 @@ class SyncDataModel(object): # SyncEntity protocol buffer. self._entries = {} - # TODO(nick): uuid.uuid1() is better, but python 2.5 only. - self.store_birthday = '%0.30f' % random.random() + self.ResetStoreBirthday() self.migration_history = MigrationHistory() @@ -560,6 +559,15 @@ class SyncDataModel(object): if spec.sync_type in requested_types: self._CreatePermanentItem(spec) + def ResetStoreBirthday(self): + """Resets the store birthday to a random value.""" + # TODO(nick): uuid.uuid1() is better, but python 2.5 only. + self.store_birthday = '%0.30f' % random.random() + + def StoreBirthday(self): + """Gets the store birthday.""" + return self.store_birthday + def GetChanges(self, sieve): """Get entries which have changed, oldest first. @@ -884,7 +892,7 @@ class TestServer(object): """Raises StoreBirthdayError if the request's birthday is a mismatch.""" if not request.HasField('store_birthday'): return - if self.account.store_birthday != request.store_birthday: + if self.account.StoreBirthday() != request.store_birthday: raise StoreBirthdayError def HandleMigrate(self, path): @@ -909,6 +917,12 @@ class TestServer(object): return (code, '<html><title>Migration: %d</title><H1>%d %s</H1></html>' % (code, code, response)) + def HandleCreateBirthdayError(self): + self.account.ResetStoreBirthday() + return ( + 200, + '<html><title>Birthday error</title><H1>Birthday error</H1></html>') + def HandleCommand(self, query, raw_request): """Decode and handle a sync command from a raw input of bytes. diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py index 693b50b..c9444ba 100755 --- a/net/tools/testserver/testserver.py +++ b/net/tools/testserver/testserver.py @@ -1404,7 +1404,8 @@ class SyncPageHandler(BasePageHandler): def __init__(self, request, client_address, sync_http_server): get_handlers = [self.ChromiumSyncMigrationOpHandler, - self.ChromiumSyncTimeHandler] + self.ChromiumSyncTimeHandler, + self.ChromiumSyncBirthdayErrorOpHandler] post_handlers = [self.ChromiumSyncCommandHandler, self.ChromiumSyncTimeHandler] BasePageHandler.__init__(self, request, client_address, @@ -1467,6 +1468,18 @@ class SyncPageHandler(BasePageHandler): self.wfile.write(raw_reply) return True + def ChromiumSyncBirthdayErrorOpHandler(self): + test_name = "/chromiumsync/birthdayerror" + if not self._ShouldHandleRequest(test_name): + return False + result, raw_reply = self.server._sync_handler.HandleCreateBirthdayError() + self.send_response(result) + self.send_header('Content-Type', 'text/html') + self.send_header('Content-Length', len(raw_reply)) + self.end_headers() + self.wfile.write(raw_reply) + return True; + def MakeDataDir(): if options.data_dir: |