OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync_file_system/drive_backend/metadata_db_migration_ut
il.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_db_migration_ut
il.h" |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_metadata_store.
h" | 10 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_metadata_store.
h" |
11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 13 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
14 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 14 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 #include "webkit/browser/fileapi/external_mount_points.h" | 16 #include "storage/browser/fileapi/external_mount_points.h" |
17 #include "webkit/common/fileapi/file_system_util.h" | 17 #include "storage/common/fileapi/file_system_util.h" |
18 | 18 |
19 #define FPL FILE_PATH_LITERAL | 19 #define FPL FILE_PATH_LITERAL |
20 | 20 |
21 namespace sync_file_system { | 21 namespace sync_file_system { |
22 namespace drive_backend { | 22 namespace drive_backend { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const char kV0ServiceName[] = "drive"; | 26 const char kV0ServiceName[] = "drive"; |
27 | 27 |
28 bool CreateV0SerializedSyncableFileSystemURL( | 28 bool CreateV0SerializedSyncableFileSystemURL( |
29 const GURL& origin, | 29 const GURL& origin, |
30 const base::FilePath& path, | 30 const base::FilePath& path, |
31 std::string* serialized_url) { | 31 std::string* serialized_url) { |
32 fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( | 32 storage::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
33 kV0ServiceName, fileapi::kFileSystemTypeSyncable, | 33 kV0ServiceName, |
34 fileapi::FileSystemMountOption(), base::FilePath()); | 34 storage::kFileSystemTypeSyncable, |
35 fileapi::FileSystemURL url = | 35 storage::FileSystemMountOption(), |
36 fileapi::ExternalMountPoints::GetSystemInstance()-> | 36 base::FilePath()); |
37 CreateExternalFileSystemURL(origin, kV0ServiceName, path); | 37 storage::FileSystemURL url = |
38 fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( | 38 storage::ExternalMountPoints::GetSystemInstance() |
| 39 ->CreateExternalFileSystemURL(origin, kV0ServiceName, path); |
| 40 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( |
39 kV0ServiceName); | 41 kV0ServiceName); |
40 | 42 |
41 if (!url.is_valid()) | 43 if (!url.is_valid()) |
42 return false; | 44 return false; |
43 *serialized_url = fileapi::GetExternalFileSystemRootURIString( | 45 *serialized_url = |
44 origin, kV0ServiceName) + url.path().AsUTF8Unsafe(); | 46 storage::GetExternalFileSystemRootURIString(origin, kV0ServiceName) + |
| 47 url.path().AsUTF8Unsafe(); |
45 return true; | 48 return true; |
46 } | 49 } |
47 | 50 |
48 void VerifyKeyAndValue(const std::string& key, | 51 void VerifyKeyAndValue(const std::string& key, |
49 const std::string& expect_val, | 52 const std::string& expect_val, |
50 leveldb::DB* db) { | 53 leveldb::DB* db) { |
51 scoped_ptr<leveldb::Iterator> itr(db->NewIterator(leveldb::ReadOptions())); | 54 scoped_ptr<leveldb::Iterator> itr(db->NewIterator(leveldb::ReadOptions())); |
52 | 55 |
53 itr->Seek(key); | 56 itr->Seek(key); |
54 EXPECT_TRUE(itr->Valid()); | 57 EXPECT_TRUE(itr->Valid()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 const base::FilePath kFile(FPL("foo bar")); | 126 const base::FilePath kFile(FPL("foo bar")); |
124 const std::string kFileMD5("file_md5"); | 127 const std::string kFileMD5("file_md5"); |
125 | 128 |
126 base::ScopedTempDir base_dir; | 129 base::ScopedTempDir base_dir; |
127 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); | 130 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); |
128 | 131 |
129 leveldb::Options options; | 132 leveldb::Options options; |
130 options.create_if_missing = true; | 133 options.create_if_missing = true; |
131 options.max_open_files = 0; // Use minimum. | 134 options.max_open_files = 0; // Use minimum. |
132 leveldb::DB* db_ptr = NULL; | 135 leveldb::DB* db_ptr = NULL; |
133 std::string db_dir = fileapi::FilePathToString( | 136 std::string db_dir = storage::FilePathToString( |
134 base_dir.path().Append(DriveMetadataStore::kDatabaseName)); | 137 base_dir.path().Append(DriveMetadataStore::kDatabaseName)); |
135 leveldb::Status status = leveldb::DB::Open(options, db_dir, &db_ptr); | 138 leveldb::Status status = leveldb::DB::Open(options, db_dir, &db_ptr); |
136 | 139 |
137 scoped_ptr<leveldb::DB> db(db_ptr); | 140 scoped_ptr<leveldb::DB> db(db_ptr); |
138 ASSERT_TRUE(status.ok()); | 141 ASSERT_TRUE(status.ok()); |
139 | 142 |
140 // Setup the database with the schema version 0. | 143 // Setup the database with the schema version 0. |
141 leveldb::WriteBatch batch; | 144 leveldb::WriteBatch batch; |
142 batch.Put(kChangeStampKey, "1"); | 145 batch.Put(kChangeStampKey, "1"); |
143 batch.Put(kSyncRootDirectoryKey, kSyncRootResourceId); | 146 batch.Put(kSyncRootDirectoryKey, kSyncRootResourceId); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 const std::string kFileMD5("file_md5"); | 235 const std::string kFileMD5("file_md5"); |
233 | 236 |
234 RegisterSyncableFileSystem(); | 237 RegisterSyncableFileSystem(); |
235 | 238 |
236 base::ScopedTempDir base_dir; | 239 base::ScopedTempDir base_dir; |
237 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); | 240 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); |
238 | 241 |
239 leveldb::Options options; | 242 leveldb::Options options; |
240 options.create_if_missing = true; | 243 options.create_if_missing = true; |
241 leveldb::DB* db_ptr = NULL; | 244 leveldb::DB* db_ptr = NULL; |
242 std::string db_dir = fileapi::FilePathToString( | 245 std::string db_dir = storage::FilePathToString( |
243 base_dir.path().Append(DriveMetadataStore::kDatabaseName)); | 246 base_dir.path().Append(DriveMetadataStore::kDatabaseName)); |
244 leveldb::Status status = leveldb::DB::Open(options, db_dir, &db_ptr); | 247 leveldb::Status status = leveldb::DB::Open(options, db_dir, &db_ptr); |
245 | 248 |
246 scoped_ptr<leveldb::DB> db(db_ptr); | 249 scoped_ptr<leveldb::DB> db(db_ptr); |
247 ASSERT_TRUE(status.ok()); | 250 ASSERT_TRUE(status.ok()); |
248 | 251 |
249 // Setup the database with the schema version 1. | 252 // Setup the database with the schema version 1. |
250 leveldb::WriteBatch batch; | 253 leveldb::WriteBatch batch; |
251 batch.Put(kDatabaseVersionKey, "1"); | 254 batch.Put(kDatabaseVersionKey, "1"); |
252 batch.Put(kChangeStampKey, "1"); | 255 batch.Put(kChangeStampKey, "1"); |
253 batch.Put(kSyncRootDirectoryKey, kSyncRootResourceId); | 256 batch.Put(kSyncRootDirectoryKey, kSyncRootResourceId); |
254 | 257 |
255 fileapi::FileSystemURL url = CreateSyncableFileSystemURL(kOrigin1, kFile); | 258 storage::FileSystemURL url = CreateSyncableFileSystemURL(kOrigin1, kFile); |
256 | 259 |
257 // Setup drive metadata. | 260 // Setup drive metadata. |
258 DriveMetadata drive_metadata; | 261 DriveMetadata drive_metadata; |
259 drive_metadata.set_resource_id(kFileResourceId); | 262 drive_metadata.set_resource_id(kFileResourceId); |
260 drive_metadata.set_md5_checksum(kFileMD5); | 263 drive_metadata.set_md5_checksum(kFileMD5); |
261 drive_metadata.set_conflicted(false); | 264 drive_metadata.set_conflicted(false); |
262 drive_metadata.set_to_be_fetched(false); | 265 drive_metadata.set_to_be_fetched(false); |
263 std::string metadata_string; | 266 std::string metadata_string; |
264 drive_metadata.SerializeToString(&metadata_string); | 267 drive_metadata.SerializeToString(&metadata_string); |
265 std::string metadata_key = kDriveMetadataKeyPrefix + kOrigin1.spec() + | 268 std::string metadata_key = kDriveMetadataKeyPrefix + kOrigin1.spec() + |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 const char kDemotedDirtyIDKeyPrefix[] = "DEMOTED_DIRTY: "; | 352 const char kDemotedDirtyIDKeyPrefix[] = "DEMOTED_DIRTY: "; |
350 | 353 |
351 // Set up environment. | 354 // Set up environment. |
352 leveldb::DB* db_ptr = NULL; | 355 leveldb::DB* db_ptr = NULL; |
353 { | 356 { |
354 base::ScopedTempDir base_dir; | 357 base::ScopedTempDir base_dir; |
355 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); | 358 ASSERT_TRUE(base_dir.CreateUniqueTempDir()); |
356 | 359 |
357 leveldb::Options options; | 360 leveldb::Options options; |
358 options.create_if_missing = true; | 361 options.create_if_missing = true; |
359 std::string db_dir = fileapi::FilePathToString( | 362 std::string db_dir = storage::FilePathToString( |
360 base_dir.path().Append(DriveMetadataStore::kDatabaseName)); | 363 base_dir.path().Append(DriveMetadataStore::kDatabaseName)); |
361 leveldb::Status status = leveldb::DB::Open(options, db_dir, &db_ptr); | 364 leveldb::Status status = leveldb::DB::Open(options, db_dir, &db_ptr); |
362 ASSERT_TRUE(status.ok()); | 365 ASSERT_TRUE(status.ok()); |
363 } | 366 } |
364 scoped_ptr<leveldb::DB> db(db_ptr); | 367 scoped_ptr<leveldb::DB> db(db_ptr); |
365 | 368 |
366 // Setup the database with the schema version 4, without IDs. | 369 // Setup the database with the schema version 4, without IDs. |
367 leveldb::WriteBatch batch; | 370 leveldb::WriteBatch batch; |
368 batch.Put(kDatabaseVersionKey, "4"); | 371 batch.Put(kDatabaseVersionKey, "4"); |
369 batch.Put(kServiceMetadataKey, "service_metadata"); | 372 batch.Put(kServiceMetadataKey, "service_metadata"); |
(...skipping 30 matching lines...) Expand all Loading... |
400 VerifyNotExist(kMultiTrackerByFileIDKeyPrefix, db.get()); | 403 VerifyNotExist(kMultiTrackerByFileIDKeyPrefix, db.get()); |
401 VerifyNotExist(kActiveTrackerIDByParentAndTitleKeyPrefix, db.get()); | 404 VerifyNotExist(kActiveTrackerIDByParentAndTitleKeyPrefix, db.get()); |
402 VerifyNotExist(kTrackerIDByParentAndTitleKeyPrefix, db.get()); | 405 VerifyNotExist(kTrackerIDByParentAndTitleKeyPrefix, db.get()); |
403 VerifyNotExist(kMultiBackingParentAndTitleKeyPrefix, db.get()); | 406 VerifyNotExist(kMultiBackingParentAndTitleKeyPrefix, db.get()); |
404 VerifyNotExist(kDirtyIDKeyPrefix, db.get()); | 407 VerifyNotExist(kDirtyIDKeyPrefix, db.get()); |
405 VerifyNotExist(kDemotedDirtyIDKeyPrefix, db.get()); | 408 VerifyNotExist(kDemotedDirtyIDKeyPrefix, db.get()); |
406 } | 409 } |
407 | 410 |
408 } // namespace drive_backend | 411 } // namespace drive_backend |
409 } // namespace sync_file_system | 412 } // namespace sync_file_system |
OLD | NEW |