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_v1/drive_metadata_store.
h" | 5 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_metadata_store.
h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/sync_file_system/drive_backend/metadata_db_migration_ut
il.h" | 19 #include "chrome/browser/sync_file_system/drive_backend/metadata_db_migration_ut
il.h" |
20 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_servi
ce.h" | 20 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_servi
ce.h" |
21 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.
h" | 21 #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.
h" |
22 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" | 22 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" |
23 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 23 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 26 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
27 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 27 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
28 #include "webkit/browser/fileapi/isolated_context.h" | 28 #include "storage/browser/fileapi/isolated_context.h" |
29 | 29 |
30 #define FPL FILE_PATH_LITERAL | 30 #define FPL FILE_PATH_LITERAL |
31 | 31 |
32 using content::BrowserThread; | 32 using content::BrowserThread; |
33 | 33 |
34 namespace sync_file_system { | 34 namespace sync_file_system { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 const char kOrigin[] = "chrome-extension://example"; | 38 const char kOrigin[] = "chrome-extension://example"; |
39 | 39 |
40 typedef DriveMetadataStore::ResourceIdByOrigin ResourceIdByOrigin; | 40 typedef DriveMetadataStore::ResourceIdByOrigin ResourceIdByOrigin; |
41 typedef DriveMetadataStore::OriginByResourceId OriginByResourceId; | 41 typedef DriveMetadataStore::OriginByResourceId OriginByResourceId; |
42 | 42 |
43 fileapi::FileSystemURL URL(const base::FilePath& path) { | 43 storage::FileSystemURL URL(const base::FilePath& path) { |
44 return CreateSyncableFileSystemURL(GURL(kOrigin), path); | 44 return CreateSyncableFileSystemURL(GURL(kOrigin), path); |
45 } | 45 } |
46 | 46 |
47 std::string GetResourceID(const ResourceIdByOrigin& sync_origins, | 47 std::string GetResourceID(const ResourceIdByOrigin& sync_origins, |
48 const GURL& origin) { | 48 const GURL& origin) { |
49 ResourceIdByOrigin::const_iterator itr = sync_origins.find(origin); | 49 ResourceIdByOrigin::const_iterator itr = sync_origins.find(origin); |
50 if (itr == sync_origins.end()) | 50 if (itr == sync_origins.end()) |
51 return std::string(); | 51 return std::string(); |
52 return itr->second; | 52 return itr->second; |
53 } | 53 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 SyncStatusCode RemoveOrigin(const GURL& url) { | 155 SyncStatusCode RemoveOrigin(const GURL& url) { |
156 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 156 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
157 drive_metadata_store_->RemoveOrigin( | 157 drive_metadata_store_->RemoveOrigin( |
158 url, base::Bind(&DriveMetadataStoreTest::DidFinishDBTask, | 158 url, base::Bind(&DriveMetadataStoreTest::DidFinishDBTask, |
159 base::Unretained(this), &status)); | 159 base::Unretained(this), &status)); |
160 message_loop_.Run(); | 160 message_loop_.Run(); |
161 return status; | 161 return status; |
162 } | 162 } |
163 | 163 |
164 SyncStatusCode UpdateEntry(const fileapi::FileSystemURL& url, | 164 SyncStatusCode UpdateEntry(const storage::FileSystemURL& url, |
165 const DriveMetadata& metadata) { | 165 const DriveMetadata& metadata) { |
166 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 166 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
167 drive_metadata_store_->UpdateEntry( | 167 drive_metadata_store_->UpdateEntry( |
168 url, metadata, | 168 url, metadata, |
169 base::Bind(&DriveMetadataStoreTest::DidFinishDBTask, | 169 base::Bind(&DriveMetadataStoreTest::DidFinishDBTask, |
170 base::Unretained(this), &status)); | 170 base::Unretained(this), &status)); |
171 message_loop_.Run(); | 171 message_loop_.Run(); |
172 return status; | 172 return status; |
173 } | 173 } |
174 | 174 |
175 SyncStatusCode DeleteEntry(const fileapi::FileSystemURL& url) { | 175 SyncStatusCode DeleteEntry(const storage::FileSystemURL& url) { |
176 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 176 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
177 drive_metadata_store_->DeleteEntry( | 177 drive_metadata_store_->DeleteEntry( |
178 url, | 178 url, |
179 base::Bind(&DriveMetadataStoreTest::DidFinishDBTask, | 179 base::Bind(&DriveMetadataStoreTest::DidFinishDBTask, |
180 base::Unretained(this), &status)); | 180 base::Unretained(this), &status)); |
181 message_loop_.Run(); | 181 message_loop_.Run(); |
182 return status; | 182 return status; |
183 } | 183 } |
184 | 184 |
185 SyncStatusCode SetLargestChangeStamp(int64 changestamp) { | 185 SyncStatusCode SetLargestChangeStamp(int64 changestamp) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 scoped_ptr<DriveMetadataStore> drive_metadata_store_; | 294 scoped_ptr<DriveMetadataStore> drive_metadata_store_; |
295 | 295 |
296 bool created_; | 296 bool created_; |
297 | 297 |
298 DISALLOW_COPY_AND_ASSIGN(DriveMetadataStoreTest); | 298 DISALLOW_COPY_AND_ASSIGN(DriveMetadataStoreTest); |
299 }; | 299 }; |
300 | 300 |
301 void DriveMetadataStoreTest::ReadWrite_Body() { | 301 void DriveMetadataStoreTest::ReadWrite_Body() { |
302 InitializeDatabase(); | 302 InitializeDatabase(); |
303 | 303 |
304 const fileapi::FileSystemURL url = URL(base::FilePath()); | 304 const storage::FileSystemURL url = URL(base::FilePath()); |
305 DriveMetadata metadata; | 305 DriveMetadata metadata; |
306 EXPECT_EQ(SYNC_DATABASE_ERROR_NOT_FOUND, | 306 EXPECT_EQ(SYNC_DATABASE_ERROR_NOT_FOUND, |
307 metadata_store()->ReadEntry(url, &metadata)); | 307 metadata_store()->ReadEntry(url, &metadata)); |
308 | 308 |
309 metadata = CreateMetadata( | 309 metadata = CreateMetadata( |
310 "file:1234567890", "09876543210", true, false, | 310 "file:1234567890", "09876543210", true, false, |
311 DriveMetadata_ResourceType_RESOURCE_TYPE_FILE); | 311 DriveMetadata_ResourceType_RESOURCE_TYPE_FILE); |
312 EXPECT_EQ(SYNC_STATUS_OK, UpdateEntry(url, metadata)); | 312 EXPECT_EQ(SYNC_STATUS_OK, UpdateEntry(url, metadata)); |
313 EXPECT_EQ(SYNC_STATUS_OK, SetLargestChangeStamp(1)); | 313 EXPECT_EQ(SYNC_STATUS_OK, SetLargestChangeStamp(1)); |
314 | 314 |
(...skipping 13 matching lines...) Expand all Loading... |
328 EXPECT_EQ(SYNC_DATABASE_ERROR_NOT_FOUND, | 328 EXPECT_EQ(SYNC_DATABASE_ERROR_NOT_FOUND, |
329 metadata_store()->ReadEntry(url, &metadata)); | 329 metadata_store()->ReadEntry(url, &metadata)); |
330 EXPECT_EQ(SYNC_DATABASE_ERROR_NOT_FOUND, DeleteEntry(url)); | 330 EXPECT_EQ(SYNC_DATABASE_ERROR_NOT_FOUND, DeleteEntry(url)); |
331 | 331 |
332 VerifyReverseMap(); | 332 VerifyReverseMap(); |
333 } | 333 } |
334 | 334 |
335 void DriveMetadataStoreTest::GetConflictURLs_Body() { | 335 void DriveMetadataStoreTest::GetConflictURLs_Body() { |
336 InitializeDatabase(); | 336 InitializeDatabase(); |
337 | 337 |
338 fileapi::FileSystemURLSet urls; | 338 storage::FileSystemURLSet urls; |
339 EXPECT_EQ(SYNC_STATUS_OK, metadata_store()->GetConflictURLs(&urls)); | 339 EXPECT_EQ(SYNC_STATUS_OK, metadata_store()->GetConflictURLs(&urls)); |
340 EXPECT_EQ(0U, urls.size()); | 340 EXPECT_EQ(0U, urls.size()); |
341 | 341 |
342 const base::FilePath path1(FPL("file1")); | 342 const base::FilePath path1(FPL("file1")); |
343 const base::FilePath path2(FPL("file2")); | 343 const base::FilePath path2(FPL("file2")); |
344 const base::FilePath path3(FPL("file3")); | 344 const base::FilePath path3(FPL("file3")); |
345 | 345 |
346 // Populate metadata in DriveMetadataStore. The metadata identified by "file2" | 346 // Populate metadata in DriveMetadataStore. The metadata identified by "file2" |
347 // and "file3" are marked as conflicted. | 347 // and "file3" are marked as conflicted. |
348 EXPECT_EQ(SYNC_STATUS_OK, UpdateEntry( | 348 EXPECT_EQ(SYNC_STATUS_OK, UpdateEntry( |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 } | 580 } |
581 | 581 |
582 void DriveMetadataStoreTest::GetFileMetadataMap_Body() { | 582 void DriveMetadataStoreTest::GetFileMetadataMap_Body() { |
583 InitializeDatabase(); | 583 InitializeDatabase(); |
584 | 584 |
585 // Save one file and folder to the origin. | 585 // Save one file and folder to the origin. |
586 const base::FilePath file_path = base::FilePath(FPL("file_0")); | 586 const base::FilePath file_path = base::FilePath(FPL("file_0")); |
587 const base::FilePath folder_path = base::FilePath(FPL("folder_0")); | 587 const base::FilePath folder_path = base::FilePath(FPL("folder_0")); |
588 | 588 |
589 const GURL origin = GURL("chrome-extension://app_a"); | 589 const GURL origin = GURL("chrome-extension://app_a"); |
590 const fileapi::FileSystemURL url_0 = CreateSyncableFileSystemURL( | 590 const storage::FileSystemURL url_0 = |
591 origin, file_path); | 591 CreateSyncableFileSystemURL(origin, file_path); |
592 const fileapi::FileSystemURL url_1 = CreateSyncableFileSystemURL( | 592 const storage::FileSystemURL url_1 = |
593 origin, folder_path); | 593 CreateSyncableFileSystemURL(origin, folder_path); |
594 | 594 |
595 // Insert DrivaMetadata objects. | 595 // Insert DrivaMetadata objects. |
596 EXPECT_EQ(SYNC_STATUS_OK, UpdateEntry( | 596 EXPECT_EQ(SYNC_STATUS_OK, UpdateEntry( |
597 url_0, | 597 url_0, |
598 CreateMetadata("file:0", "1", false, false, | 598 CreateMetadata("file:0", "1", false, false, |
599 DriveMetadata_ResourceType_RESOURCE_TYPE_FILE))); | 599 DriveMetadata_ResourceType_RESOURCE_TYPE_FILE))); |
600 EXPECT_EQ(SYNC_STATUS_OK, UpdateEntry( | 600 EXPECT_EQ(SYNC_STATUS_OK, UpdateEntry( |
601 url_1, | 601 url_1, |
602 CreateMetadata("folder:0", "2", false, true, | 602 CreateMetadata("folder:0", "2", false, true, |
603 DriveMetadata_ResourceType_RESOURCE_TYPE_FOLDER))); | 603 DriveMetadata_ResourceType_RESOURCE_TYPE_FOLDER))); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 ASSERT_FALSE(IsDriveAPIDisabled()); | 725 ASSERT_FALSE(IsDriveAPIDisabled()); |
726 GetFileMetadataMap_Body(); | 726 GetFileMetadataMap_Body(); |
727 } | 727 } |
728 | 728 |
729 TEST_F(DriveMetadataStoreTest, GetFileMetadataMap_WAPI) { | 729 TEST_F(DriveMetadataStoreTest, GetFileMetadataMap_WAPI) { |
730 SetDisableDriveAPI(true); | 730 SetDisableDriveAPI(true); |
731 GetFileMetadataMap_Body(); | 731 GetFileMetadataMap_Body(); |
732 } | 732 } |
733 | 733 |
734 } // namespace sync_file_system | 734 } // namespace sync_file_system |
OLD | NEW |