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 881ddcbf51172fe70641becd2f66d471d3980d3e..e7ccdc6138eee151aa750e493ca513cd202e6acb 100644 |
--- a/chrome/browser/sync/profile_sync_service_unittest.cc |
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc |
@@ -4,7 +4,6 @@ |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
-#include "base/file_util.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/run_loop.h" |
#include "base/values.h" |
@@ -86,19 +85,7 @@ class ProfileSyncServiceTest : public testing::Test { |
base::RunLoop().RunUntilIdle(); |
} |
- // TODO(akalin): Refactor the StartSyncService*() functions below. |
- |
- void StartSyncService() { |
- StartSyncServiceAndSetInitialSyncEnded( |
- true, true, false, true, syncer::STORAGE_IN_MEMORY); |
- } |
- |
- void StartSyncServiceAndSetInitialSyncEnded( |
- bool set_initial_sync_ended, |
- bool issue_auth_token, |
- bool synchronous_sync_configuration, |
- bool sync_setup_completed, |
- syncer::StorageOption storage_option) { |
+ void StartSyncServiceAndSetInitialSyncEnded() { |
if (service_) |
return; |
@@ -116,23 +103,12 @@ class ProfileSyncServiceTest : public testing::Test { |
oauth2_token_service, |
ProfileSyncService::AUTO_START, |
true)); |
- if (!set_initial_sync_ended) |
- service_->dont_set_initial_sync_ended_on_init(); |
- |
- if (synchronous_sync_configuration) |
- service_->set_synchronous_sync_configuration(); |
- service_->set_storage_option(storage_option); |
- if (!sync_setup_completed) |
- profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false); |
// Register the bookmark data type. |
ON_CALL(*factory, CreateDataTypeManager(_, _, _, _, _, _)). |
WillByDefault(ReturnNewDataTypeManager()); |
- if (issue_auth_token) |
- IssueTestTokens(); |
- |
service_->Initialize(); |
} |
@@ -453,7 +429,8 @@ TEST_F(ProfileSyncServiceSimpleTest, EnableSyncAndSignOut) { |
#endif // !defined(OS_CHROMEOS) |
TEST_F(ProfileSyncServiceTest, JsControllerHandlersBasic) { |
- StartSyncService(); |
+ StartSyncServiceAndSetInitialSyncEnded(); |
+ IssueTestTokens(); |
EXPECT_TRUE(service_->sync_initialized()); |
EXPECT_TRUE(service_->GetBackendForTest() != NULL); |
@@ -466,8 +443,7 @@ TEST_F(ProfileSyncServiceTest, JsControllerHandlersBasic) { |
TEST_F(ProfileSyncServiceTest, |
JsControllerHandlersDelayedBackendInitialization) { |
- StartSyncServiceAndSetInitialSyncEnded(true, false, false, true, |
- syncer::STORAGE_IN_MEMORY); |
+ StartSyncServiceAndSetInitialSyncEnded(); |
StrictMock<syncer::MockJsEventHandler> event_handler; |
EXPECT_CALL(event_handler, HandleJsEvent(_, _)).Times(AtLeast(1)); |
@@ -486,7 +462,8 @@ TEST_F(ProfileSyncServiceTest, |
} |
TEST_F(ProfileSyncServiceTest, JsControllerProcessJsMessageBasic) { |
- StartSyncService(); |
+ StartSyncServiceAndSetInitialSyncEnded(); |
+ IssueTestTokens(); |
WaitForBackendInitDone(); |
StrictMock<syncer::MockJsReplyHandler> reply_handler; |
@@ -519,8 +496,7 @@ TEST_F(ProfileSyncServiceTest, JsControllerProcessJsMessageBasic) { |
TEST_F(ProfileSyncServiceTest, |
JsControllerProcessJsMessageBasicDelayedBackendInitialization) { |
- StartSyncServiceAndSetInitialSyncEnded(true, false, false, true, |
- syncer::STORAGE_IN_MEMORY); |
+ StartSyncServiceAndSetInitialSyncEnded(); |
StrictMock<syncer::MockJsReplyHandler> reply_handler; |
@@ -548,76 +524,9 @@ TEST_F(ProfileSyncServiceTest, |
done.Wait(); |
} |
-// Make sure that things still work if sync is not enabled, but some old sync |
-// databases are lingering in the "Sync Data" folder. |
-TEST_F(ProfileSyncServiceTest, TestStartupWithOldSyncData) { |
- 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))); |
- |
- StartSyncServiceAndSetInitialSyncEnded(true, false, true, false, |
- syncer::STORAGE_ON_DISK); |
- EXPECT_FALSE(service_->HasSyncSetupCompleted()); |
- EXPECT_FALSE(service_->sync_initialized()); |
- |
- // Since we're doing synchronous initialization, backend should be |
- // initialized by this call. |
- IssueTestTokens(); |
- |
- // Stop the service so we can read the new Sync Data files that were |
- // created. |
- service_->Shutdown(); |
- service_.reset(); |
- |
- // This file should have been deleted when the whole directory was nuked. |
- ASSERT_FALSE(base::PathExists(sync_file3)); |
- ASSERT_FALSE(base::PathExists(sync_file1)); |
- |
- // This will still exist, but the text should have changed. |
- ASSERT_TRUE(base::PathExists(sync_file2)); |
- std::string file2text; |
- ASSERT_TRUE(base::ReadFileToString(sync_file2, &file2text)); |
- ASSERT_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(ProfileSyncServiceTest, FailToOpenDatabase) { |
- StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, |
- syncer::STORAGE_INVALID); |
- |
- // The backend is not ready. Ensure the PSS knows this. |
- EXPECT_FALSE(service_->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(ProfileSyncServiceTest, FailToDownloadControlTypes) { |
- StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, |
- syncer::STORAGE_IN_MEMORY); |
- |
- // The backend is not ready. Ensure the PSS knows this. |
- EXPECT_FALSE(service_->sync_initialized()); |
-} |
- |
TEST_F(ProfileSyncServiceTest, GetSyncTokenStatus) { |
- StartSyncService(); |
+ StartSyncServiceAndSetInitialSyncEnded(); |
+ IssueTestTokens(); |
ProfileSyncService::SyncTokenStatus token_status = |
service_->GetSyncTokenStatus(); |
EXPECT_EQ(syncer::CONNECTION_NOT_ATTEMPTED, token_status.connection_status); |