summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/profile_sync_service_unittest.cc
diff options
context:
space:
mode:
authornick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-29 01:56:00 +0000
committernick@chromium.org <nick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-29 01:56:00 +0000
commit9b3f2ae738035d0fdd285edabbe57e3103dfedc3 (patch)
tree0c6bcf3713d75cb7a0168b1afe01515d0c85e784 /chrome/browser/sync/profile_sync_service_unittest.cc
parent9d20e919c61b7627dbc79e33ebc73f58d20588fb (diff)
downloadchromium_src-9b3f2ae738035d0fdd285edabbe57e3103dfedc3.zip
chromium_src-9b3f2ae738035d0fdd285edabbe57e3103dfedc3.tar.gz
chromium_src-9b3f2ae738035d0fdd285edabbe57e3103dfedc3.tar.bz2
Fixed bug 21102 where shutdown while starting Sync leaves things weird.
Specifically, it leaves the Sync Data folder around, which causes problems later where it thinks we're already logged into sync. Patch contributed by Dan Tasse (dantasse@google.com) TEST=create new Sync Data files with nonsense data, enable sync for a user, make sure those files were replaced with real Sync Data files. BUG=21102 Review URL: http://codereview.chromium.org/557010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37482 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/profile_sync_service_unittest.cc')
-rw-r--r--chrome/browser/sync/profile_sync_service_unittest.cc63
1 files changed, 60 insertions, 3 deletions
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index 4b53582..f001f83 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -6,7 +6,6 @@
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
-
#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/string_util.h"
@@ -20,6 +19,7 @@
#include "chrome/browser/sync/glue/sync_backend_host.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
#include "chrome/test/testing_profile.h"
#include "chrome/test/sync/test_http_bridge_factory.h"
@@ -94,11 +94,12 @@ class TestProfileSyncService : public ProfileSyncService {
virtual ~TestProfileSyncService() {
}
- virtual void InitializeBackend() {
+ virtual void InitializeBackend(bool delete_sync_data_folder) {
InstallGlue<TestModelAssociator, BookmarkChangeProcessor>();
TestHttpBridgeFactory* factory = new TestHttpBridgeFactory();
TestHttpBridgeFactory* factory2 = new TestHttpBridgeFactory();
- backend()->InitializeForTestMode(L"testuser", factory, factory2);
+ backend()->InitializeForTestMode(L"testuser", factory, factory2,
+ delete_sync_data_folder);
// The SyncBackend posts a task to the current loop when initialization
// completes.
MessageLoop::current()->Run();
@@ -311,6 +312,7 @@ class ProfileSyncServiceTest : public testing::Test {
if (!service_->HasSyncSetupCompleted())
service_->EnableForUser();
}
+
void StopSyncService(SaveOption save) {
if (save == DONT_SAVE_TO_STORAGE)
service_->DisableForUser();
@@ -1316,3 +1318,58 @@ TEST_F(ProfileSyncServiceTestWithData, RecoverAfterDeletingSyncDataDirectory) {
ExpectBookmarkModelMatchesTestData();
ExpectModelMatch();
}
+
+#if defined(OS_MACOSX)
+// TODO(dantasse) This test fails on the mac. See http://crbug.com/33443
+#define MAYBE_TestStartupWithOldSyncData DISABLED_TestStartupWithOldSyncData
+#else
+#define MAYBE_TestStartupWithOldSyncData TestStartupWithOldSyncData
+#endif
+
+// 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(ProfileSyncServiceTestWithData, MAYBE_TestStartupWithOldSyncData) {
+ const char* nonsense1 = "reginald";
+ const char* nonsense2 = "beartato";
+ const char* nonsense3 = "harrison";
+ FilePath temp_directory = profile_->GetPath().AppendASCII("Sync Data");
+ FilePath sync_file1 =
+ temp_directory.AppendASCII("BookmarkSyncSettings.sqlite3");
+ FilePath sync_file2 = temp_directory.AppendASCII("SyncData.sqlite3");
+ FilePath sync_file3 = temp_directory.AppendASCII("nonsense_file");
+ file_util::CreateDirectory(temp_directory);
+ file_util::WriteFile(sync_file1, nonsense1, strlen(nonsense1));
+ file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2));
+ file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3));
+
+ LoadBookmarkModel(LOAD_FROM_STORAGE, SAVE_TO_STORAGE);
+ if (!service_.get()) {
+ service_.reset(new TestProfileSyncService(profile_.get()));
+ profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false);
+ service_->Initialize(); // will call disableForUser because sync setup
+ // hasn't been completed.
+ }
+
+ ASSERT_FALSE(service_->backend());
+ ASSERT_FALSE(service_->HasSyncSetupCompleted());
+
+ // This will actually start up the sync service.
+ service_->EnableForUser();
+
+ // Stop the service so we can read the new Sync Data files that were created.
+ service_.reset();
+
+ // This file should have been deleted when the whole directory was nuked.
+ ASSERT_FALSE(file_util::PathExists(sync_file3));
+
+ // These two will still exist, but their texts should have changed.
+ ASSERT_TRUE(file_util::PathExists(sync_file1));
+ std::string file1text;
+ file_util::ReadFileToString(sync_file1, &file1text);
+ ASSERT_FALSE(file1text.compare(nonsense1) == 0);
+
+ ASSERT_TRUE(file_util::PathExists(sync_file2));
+ std::string file2text;
+ file_util::ReadFileToString(sync_file2, &file2text);
+ ASSERT_FALSE(file2text.compare(nonsense2) == 0);
+}