Chromium Code Reviews| Index: chrome/browser/sync/profile_sync_service_startup_unittest.cc |
| diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc |
| index 59bf53516fe047333853eb5bc691a9cc2816dd6e..abe626aff7259762d552b4418b51289b1c901374 100644 |
| --- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc |
| +++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc |
| @@ -2,8 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "testing/gtest/include/gtest/gtest.h" |
| - |
| +#include "base/file_util.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/prefs/pref_service.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| @@ -32,6 +31,7 @@ |
| #include "google_apis/gaia/gaia_constants.h" |
| #include "google_apis/gaia/oauth2_token_service.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| using browser_sync::DataTypeManager; |
| using browser_sync::DataTypeManagerMock; |
| @@ -560,3 +560,102 @@ TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { |
| sync_->SetSetupInProgress(false); |
| EXPECT_FALSE(sync_->sync_initialized()); |
| } |
| + |
| +// Make sure that if sync is not configured yet but there are still files |
| +// lingering in "Sync Data" folder then sync cleans folder and initializes |
| +// successfully. |
| +TEST_F(ProfileSyncServiceStartupTest, TestStartupWithOldSyncData) { |
|
rlarocque
2013/11/11 22:30:46
I don't understand how this works.
The ProfileSyn
|
| + const char* nonsense1 = "reginald"; |
| + const char* nonsense2 = "beartato"; |
| + const char* nonsense3 = "harrison"; |
| + base::FilePath temp_directory = |
| + profile_->GetPath().AppendASCII("Sync Data"); |
| + base::FilePath sync_file1 = |
| + temp_directory.AppendASCII("BookmarkSyncSettings.sqlite3"); |
| + base::FilePath sync_file2 = temp_directory.AppendASCII("SyncData.sqlite3"); |
| + base::FilePath sync_file3 = temp_directory.AppendASCII("nonsense_file"); |
| + ASSERT_TRUE(file_util::CreateDirectory(temp_directory)); |
| + ASSERT_NE(-1, |
| + file_util::WriteFile(sync_file1, nonsense1, strlen(nonsense1))); |
| + ASSERT_NE(-1, |
| + file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2))); |
| + ASSERT_NE(-1, |
| + file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3))); |
| + |
| + // Pre load the tokens |
| + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| + "test_user@gmail.com"); |
| + SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
| + profile_.get(), NULL); |
| + CreateSyncService(); |
| + DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
| + EXPECT_CALL(*data_type_manager, Configure(_, _)); |
| + EXPECT_CALL(*data_type_manager, state()). |
| + WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
| + EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
| + EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| + |
| + profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); |
| + sync_->set_storage_option(syncer::STORAGE_ON_DISK); |
| + sync_->SetSetupInProgress(true); |
| + |
| + IssueTestTokens(); |
| + |
| + sync_->Initialize(); |
| + |
| + sync_->SetSetupInProgress(false); |
| + |
| + EXPECT_TRUE(sync_->sync_initialized()); |
| + |
| + // This file should have been deleted when the whole directory was nuked. |
| + EXPECT_FALSE(base::PathExists(sync_file3)); |
| + EXPECT_FALSE(base::PathExists(sync_file1)); |
| + |
| + // This will still exist, but the text should have changed. |
| + EXPECT_TRUE(base::PathExists(sync_file2)); |
| + std::string file2text; |
| + EXPECT_TRUE(base::ReadFileToString(sync_file2, &file2text)); |
| + EXPECT_NE(file2text.compare(nonsense2), 0); |
| + |
| +} |
| + |
| +// Simulates a scenario where a database is corrupted and it is impossible to |
| +// recreate it. This test is useful mainly when it is run under valgrind. Its |
| +// expectations are not very interesting. |
| +TEST_F(ProfileSyncServiceStartupTest, FailToOpenDatabase) { |
| + // Pre load the tokens |
| + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| + "test_user@gmail.com"); |
| + SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
| + profile_.get(), NULL); |
| + CreateSyncService(); |
| + sync_->set_storage_option(syncer::STORAGE_INVALID); |
|
rlarocque
2013/11/11 22:30:46
I think your patch is a bit behind trunk. sync_ i
|
| + EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| + |
| + IssueTestTokens(); |
| + |
| + sync_->Initialize(); |
| + |
| + EXPECT_FALSE(sync_->sync_initialized()); |
| +} |
| + |
| +// This setup will allow the database to exist, but leave it empty. The attempt |
| +// to download control types will silently fail (no downloads have any effect in |
| +// these tests). The sync_backend_host will notice this and inform the profile |
| +// sync service of the failure to initialize the backed. |
| +TEST_F(ProfileSyncServiceStartupTest, FailToDownloadControlTypes) { |
| + // Pre load the tokens |
| + profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| + "test_user@gmail.com"); |
| + SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
| + profile_.get(), NULL); |
| + CreateSyncService(); |
| + EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| + |
| + sync_->dont_set_initial_sync_ended_on_init(); |
| + IssueTestTokens(); |
| + |
| + sync_->Initialize(); |
| + |
| + EXPECT_FALSE(sync_->sync_initialized()); |
| +} |