summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/util
diff options
context:
space:
mode:
authoridana@chromium.org <idana@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 19:59:03 +0000
committeridana@chromium.org <idana@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 19:59:03 +0000
commit19860f75acda02c670802c203ad7710c9fe4fe74 (patch)
treef7ef9c042e1f0acd9c4476c0a1d430779dda3a3e /chrome/browser/sync/util
parente7d1761ec4a007a3fc64d790ed22d015e99951de (diff)
downloadchromium_src-19860f75acda02c670802c203ad7710c9fe4fe74.zip
chromium_src-19860f75acda02c670802c203ad7710c9fe4fe74.tar.gz
chromium_src-19860f75acda02c670802c203ad7710c9fe4fe74.tar.bz2
Got rid of DieFileDie in user_settings_unittest.cc.
It turns out that the v10 -> v11 database migration code had a bug where the destination file (SyncData.sqlite3) wasn't copied into the correct directory. I fixed that problem too. BUG=21834 Review URL: http://codereview.chromium.org/366011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31272 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/util')
-rw-r--r--chrome/browser/sync/util/user_settings.cc8
-rw-r--r--chrome/browser/sync/util/user_settings_unittest.cc73
2 files changed, 49 insertions, 32 deletions
diff --git a/chrome/browser/sync/util/user_settings.cc b/chrome/browser/sync/util/user_settings.cc
index bb60af2..ea8d8e4 100644
--- a/chrome/browser/sync/util/user_settings.cc
+++ b/chrome/browser/sync/util/user_settings.cc
@@ -88,8 +88,12 @@ void UserSettings::MigrateOldVersionsAsNeeded(sqlite3* const handle,
GetColumn(share_query.get(), 0, &share_name);
GetColumn(share_query.get(), 1, &file_name);
- if (!file_util::Move(FilePath(file_name),
- DirectoryManager::GetSyncDataDatabaseFilename())) {
+ const FilePath& src_syncdata_path = FilePath(file_name);
+ FilePath dst_syncdata_path(src_syncdata_path.DirName());
+ file_util::AbsolutePath(&dst_syncdata_path);
+ dst_syncdata_path = dst_syncdata_path.Append(
+ DirectoryManager::GetSyncDataDatabaseFilename());
+ if (!file_util::Move(src_syncdata_path, dst_syncdata_path)) {
LOG(WARNING) << "Unable to upgrade UserSettings from v10";
return;
}
diff --git a/chrome/browser/sync/util/user_settings_unittest.cc b/chrome/browser/sync/util/user_settings_unittest.cc
index ec7676b..23555d4 100644
--- a/chrome/browser/sync/util/user_settings_unittest.cc
+++ b/chrome/browser/sync/util/user_settings_unittest.cc
@@ -5,7 +5,7 @@
#include <string>
#include "base/file_util.h"
-#include "base/test/test_file_util.h"
+#include "base/scoped_temp_dir.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/util/character_set_converters.h"
#include "chrome/browser/sync/util/user_settings.h"
@@ -19,22 +19,25 @@ static const FilePath::CharType kV10UserSettingsDB[] =
FILE_PATH_LITERAL("Version10Settings.sqlite3");
static const FilePath::CharType kOldStyleSyncDataDB[] =
FILE_PATH_LITERAL("OldStyleSyncData.sqlite3");
-static const FilePath::CharType kSyncDataDB[] =
- FILE_PATH_LITERAL("SyncData.sqlite3");
class UserSettingsTest : public testing::Test {
public:
UserSettingsTest() : sync_data_("Some sync data") { }
- void SetUpVersion10Databases() {
- CleanUpVersion10Databases();
+
+ // Creates and populates the V10 database files within
+ // |destination_directory|.
+ void SetUpVersion10Databases(const FilePath& destination_directory) {
sqlite3* primer_handle = NULL;
- ASSERT_TRUE(SQLITE_OK == SqliteOpen(FilePath(kV10UserSettingsDB),
- &primer_handle));
- FilePath old_sync_data(kOldStyleSyncDataDB);
+ v10_user_setting_db_path_ =
+ destination_directory.Append(FilePath(kV10UserSettingsDB));
+ ASSERT_EQ(SQLITE_OK, SqliteOpen(v10_user_setting_db_path_, &primer_handle));
+ old_style_sync_data_path_ =
+ destination_directory.Append(FilePath(kOldStyleSyncDataDB));
- ASSERT_TRUE(sync_data_.length() ==
- static_cast<size_t>(file_util::WriteFile(
- old_sync_data, sync_data_.data(), sync_data_.length())));
+ ASSERT_EQ(sync_data_.length(),
+ static_cast<size_t>(file_util::WriteFile(
+ old_style_sync_data_path_, sync_data_.data(),
+ sync_data_.length())));
// Create settings table.
ExecOrDie(primer_handle, "CREATE TABLE settings"
@@ -50,47 +53,57 @@ class UserSettingsTest : public testing::Test {
" PRIMARY KEY(email, share_name) ON CONFLICT REPLACE)");
// Populate a share.
ExecOrDie(primer_handle, "INSERT INTO shares values ( ?, ?, ?)",
- "foo@foo.com", "foo@foo.com", FilePathToUTF8(old_sync_data));
+ "foo@foo.com", "foo@foo.com",
+ FilePathToUTF8(old_style_sync_data_path_));
sqlite3_close(primer_handle);
}
- void CleanUpVersion10Databases() {
- ASSERT_TRUE(file_util::DieFileDie(FilePath(kV10UserSettingsDB), false));
- ASSERT_TRUE(file_util::DieFileDie(FilePath(kOldStyleSyncDataDB), false));
- ASSERT_TRUE(file_util::DieFileDie(FilePath(kSyncDataDB), false));
- }
-
const std::string& sync_data() const { return sync_data_; }
+ const FilePath& v10_user_setting_db_path() const {
+ return v10_user_setting_db_path_;
+ }
+ const FilePath& old_style_sync_data_path() const {
+ return old_style_sync_data_path_;
+ }
private:
+ FilePath v10_user_setting_db_path_;
+ FilePath old_style_sync_data_path_;
std::string sync_data_;
};
TEST_F(UserSettingsTest, MigrateFromV10ToV11) {
- SetUpVersion10Databases();
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ SetUpVersion10Databases(temp_dir.path());
{
// Create a UserSettings, which should trigger migration code. We do this
// inside a scoped block so it closes itself and we can poke around to see
// what happened later.
UserSettings settings;
- settings.Init(FilePath(kV10UserSettingsDB));
+ settings.Init(v10_user_setting_db_path());
}
// Now poke around using sqlite to see if UserSettings migrated properly.
sqlite3* handle = NULL;
- ASSERT_TRUE(SQLITE_OK == SqliteOpen(FilePath(kV10UserSettingsDB), &handle));
- ScopedStatement version_query(PrepareQuery(handle,
- "SELECT version FROM db_version"));
- ASSERT_TRUE(SQLITE_ROW == sqlite3_step(version_query.get()));
-
- const int version = sqlite3_column_int(version_query.get(), 0);
+ ASSERT_EQ(SQLITE_OK, SqliteOpen(v10_user_setting_db_path(), &handle));
+
+ // Note that we don't use ScopedStatement to avoid closing the sqlite handle
+ // before finalizing the statement.
+ sqlite3_stmt* version_query =
+ PrepareQuery(handle, "SELECT version FROM db_version");
+ ASSERT_EQ(SQLITE_ROW, sqlite3_step(version_query));
+ const int version = sqlite3_column_int(version_query, 0);
EXPECT_EQ(11, version);
- EXPECT_FALSE(file_util::PathExists(FilePath(kOldStyleSyncDataDB)));
+ sqlite3_finalize(version_query);
+
+ EXPECT_FALSE(file_util::PathExists(old_style_sync_data_path()));
- const FilePath& path =
- syncable::DirectoryManager::GetSyncDataDatabaseFilename();
+ FilePath new_style_path = temp_dir.path().Append(
+ syncable::DirectoryManager::GetSyncDataDatabaseFilename());
std::string contents;
- ASSERT_TRUE(file_util::ReadFileToString(FilePath(path), &contents));
+ ASSERT_TRUE(file_util::ReadFileToString(new_style_path, &contents));
EXPECT_TRUE(sync_data() == contents);
+ sqlite3_close(handle);
}