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

Unified Diff: chrome/browser/sync/profile_sync_service_unittest.cc

Issue 8496002: Sync: Improve handling of database load failures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory access bugs Created 9 years, 1 month 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: chrome/browser/sync/profile_sync_service_unittest.cc
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index 470ba48f798b488a91a098018179a3e03f7aaf3d..b2e763674da1ff76b467b0e65fefe5435459013f 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -77,14 +77,15 @@ class ProfileSyncServiceTest : public testing::Test {
// TODO(akalin): Refactor the StartSyncService*() functions below.
void StartSyncService() {
- StartSyncServiceAndSetInitialSyncEnded(true, true, false, true);
+ StartSyncServiceAndSetInitialSyncEnded(true, true, false, true, true);
}
void StartSyncServiceAndSetInitialSyncEnded(
bool set_initial_sync_ended,
bool issue_auth_token,
bool synchronous_sync_configuration,
- bool sync_setup_completed) {
+ bool sync_setup_completed,
+ bool expect_create_dtm) {
if (!service_.get()) {
// Set bootstrap to true and it will provide a logged in user for test
service_.reset(new TestProfileSyncService(&factory_,
@@ -97,9 +98,13 @@ class ProfileSyncServiceTest : public testing::Test {
if (!sync_setup_completed)
profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false);
- // Register the bookmark data type.
- EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).
- WillOnce(ReturnNewDataTypeManager());
+ if (expect_create_dtm) {
+ // Register the bookmark data type.
+ EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).
+ WillOnce(ReturnNewDataTypeManager());
+ } else {
+ EXPECT_CALL(factory_, CreateDataTypeManager(_, _)).Times(0);
+ }
if (issue_auth_token) {
profile_->GetTokenService()->IssueAuthTokenForTest(
@@ -192,7 +197,7 @@ TEST_F(ProfileSyncServiceTest, JsControllerHandlersBasic) {
TEST_F(ProfileSyncServiceTest,
JsControllerHandlersDelayedBackendInitialization) {
- StartSyncServiceAndSetInitialSyncEnded(true, false, false, true);
+ StartSyncServiceAndSetInitialSyncEnded(true, false, false, true, true);
StrictMock<MockJsEventHandler> event_handler;
EXPECT_CALL(event_handler, HandleJsEvent(_, _)).Times(AtLeast(1));
@@ -234,7 +239,7 @@ TEST_F(ProfileSyncServiceTest, JsControllerProcessJsMessageBasic) {
TEST_F(ProfileSyncServiceTest,
JsControllerProcessJsMessageBasicDelayedBackendInitialization) {
- StartSyncServiceAndSetInitialSyncEnded(true, false, false, true);
+ StartSyncServiceAndSetInitialSyncEnded(true, false, false, true, true);
StrictMock<MockJsReplyHandler> reply_handler;
@@ -277,8 +282,9 @@ TEST_F(ProfileSyncServiceTest, TestStartupWithOldSyncData) {
ASSERT_NE(-1,
file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3)));
- StartSyncServiceAndSetInitialSyncEnded(false, false, true, false);
+ StartSyncServiceAndSetInitialSyncEnded(false, false, true, false, true);
EXPECT_FALSE(service_->HasSyncSetupCompleted());
+ EXPECT_FALSE(service_->sync_initialized());
// Since we're doing synchronous initialization, backend should be
// initialized by this call.
@@ -300,6 +306,28 @@ TEST_F(ProfileSyncServiceTest, TestStartupWithOldSyncData) {
ASSERT_NE(file2text.compare(nonsense2), 0);
}
+TEST_F(ProfileSyncServiceTest, CorruptDatabase) {
+ const char* nonesense = "not a database";
+
+ FilePath temp_directory = profile_->GetPath().AppendASCII("Sync Data");
+ FilePath sync_db_file = temp_directory.AppendASCII("SyncData.sqlite3");
+
+ ASSERT_TRUE(file_util::CreateDirectory(temp_directory));
+ ASSERT_NE(-1,
+ file_util::WriteFile(sync_db_file, nonesense, strlen(nonesense)));
+
+ // Initialize with HasSyncSetupCompleted() set to true and InitialSyncEnded
+ // false. This is to model the scenario that would result when opening the
+ // sync database fails.
+ StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, false);
+
+ // The backend is not ready. Ensure the PSS knows this.
+ EXPECT_FALSE(service_->sync_initialized());
+
+ // Ensure we will be prepared to initialize a fresh DB next time.
+ EXPECT_FALSE(service_->HasSyncSetupCompleted());
+}
+
} // namespace
} // namespace browser_sync
« no previous file with comments | « chrome/browser/sync/profile_sync_service.cc ('k') | chrome/browser/sync/syncable/directory_backing_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698