OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/drive/drive_resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 namespace drive { | 24 namespace drive { |
25 namespace { | 25 namespace { |
26 | 26 |
27 // See drive.proto for the difference between the two URLs. | 27 // See drive.proto for the difference between the two URLs. |
28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; | 28 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; |
29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; | 29 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; |
30 | 30 |
31 const char kTestRootResourceId[] = "test_root"; | 31 const char kTestRootResourceId[] = "test_root"; |
32 | 32 |
33 // Callback for DriveResourceMetadata::InitFromDB. | |
34 void CopyResultsFromInitFromDBCallback(DriveFileError* expected_error, | |
35 DriveFileError actual_error) { | |
36 *expected_error = actual_error; | |
37 } | |
38 | |
39 // Copies result from GetChildDirectoriesCallback. | 33 // Copies result from GetChildDirectoriesCallback. |
40 void CopyResultFromGetChildDirectoriesCallback( | 34 void CopyResultFromGetChildDirectoriesCallback( |
41 std::set<base::FilePath>* out_child_directories, | 35 std::set<base::FilePath>* out_child_directories, |
42 const std::set<base::FilePath>& in_child_directories) { | 36 const std::set<base::FilePath>& in_child_directories) { |
43 *out_child_directories = in_child_directories; | 37 *out_child_directories = in_child_directories; |
44 } | 38 } |
45 | 39 |
46 // Copies result from GetChangestampCallback. | 40 // Copies result from GetChangestampCallback. |
47 void CopyResultFromGetChangestampCallback( | 41 void CopyResultFromGetChangestampCallback( |
48 int64* out_changestamp, int64 in_changestamp) { | 42 int64* out_changestamp, int64 in_changestamp) { |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 pair_result->first.path); | 396 pair_result->first.path); |
403 ASSERT_TRUE(pair_result->first.proto.get()); | 397 ASSERT_TRUE(pair_result->first.proto.get()); |
404 EXPECT_EQ("file4", pair_result->first.proto->base_name()); | 398 EXPECT_EQ("file4", pair_result->first.proto->base_name()); |
405 // The second entry should not be found. | 399 // The second entry should not be found. |
406 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, pair_result->second.error); | 400 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, pair_result->second.error); |
407 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), | 401 EXPECT_EQ(base::FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), |
408 pair_result->second.path); | 402 pair_result->second.path); |
409 ASSERT_FALSE(pair_result->second.proto.get()); | 403 ASSERT_FALSE(pair_result->second.proto.get()); |
410 } | 404 } |
411 | 405 |
412 TEST_F(DriveResourceMetadataTest, DBTest) { | |
413 TestingProfile profile; | |
414 scoped_refptr<base::SequencedWorkerPool> pool = | |
415 content::BrowserThread::GetBlockingPool(); | |
416 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = | |
417 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); | |
418 | |
419 DriveResourceMetadata resource_metadata(kTestRootResourceId); | |
420 Init(&resource_metadata); | |
421 | |
422 base::FilePath db_path(DriveCache::GetCacheRootPath(&profile). | |
423 AppendASCII("meta").AppendASCII("resource_metadata.db")); | |
424 // InitFromDB should fail with DRIVE_FILE_ERROR_NOT_FOUND since the db | |
425 // doesn't exist. | |
426 DriveFileError db_error; | |
427 resource_metadata.InitFromDB( | |
428 db_path, | |
429 blocking_task_runner, | |
430 base::Bind(&CopyResultsFromInitFromDBCallback, &db_error)); | |
431 google_apis::test_util::RunBlockingPoolTask(); | |
432 ASSERT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, db_error); | |
433 | |
434 // Create a file system and write it to disk. | |
435 // We cannot call SaveToDB without first having called InitFromDB because | |
436 // InitFrom initializes the db_path and blocking_task_runner needed by | |
437 // SaveToDB. | |
438 resource_metadata.SaveToDB(); | |
439 google_apis::test_util::RunBlockingPoolTask(); | |
440 | |
441 // InitFromDB should fail with DRIVE_FILE_ERROR_IN_USE. | |
442 resource_metadata.InitFromDB( | |
443 db_path, | |
444 blocking_task_runner, | |
445 base::Bind(&CopyResultsFromInitFromDBCallback, &db_error)); | |
446 google_apis::test_util::RunBlockingPoolTask(); | |
447 ASSERT_EQ(DRIVE_FILE_ERROR_IN_USE, db_error); | |
448 | |
449 // InitFromDB should succeed. | |
450 DriveResourceMetadata test_resource_metadata(kTestRootResourceId); | |
451 test_resource_metadata.InitFromDB( | |
452 db_path, | |
453 blocking_task_runner, | |
454 base::Bind(&CopyResultsFromInitFromDBCallback, &db_error)); | |
455 google_apis::test_util::RunBlockingPoolTask(); | |
456 ASSERT_EQ(DRIVE_FILE_OK, db_error); | |
457 | |
458 // Verify by checking for drive/dir2, which should have 3 children. | |
459 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | |
460 scoped_ptr<DriveEntryProtoVector> entries; | |
461 test_resource_metadata.ReadDirectoryByPath( | |
462 base::FilePath::FromUTF8Unsafe("drive/dir2"), | |
463 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | |
464 &error, &entries)); | |
465 google_apis::test_util::RunBlockingPoolTask(); | |
466 EXPECT_EQ(DRIVE_FILE_OK, error); | |
467 ASSERT_TRUE(entries.get()); | |
468 ASSERT_EQ(3U, entries->size()); | |
469 } | |
470 | |
471 TEST_F(DriveResourceMetadataTest, RemoveEntryFromParent) { | 406 TEST_F(DriveResourceMetadataTest, RemoveEntryFromParent) { |
472 // Make sure file9 is found. | 407 // Make sure file9 is found. |
473 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 408 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
474 base::FilePath drive_file_path; | 409 base::FilePath drive_file_path; |
475 const std::string file9_resource_id = "resource_id:file9"; | 410 const std::string file9_resource_id = "resource_id:file9"; |
476 scoped_ptr<DriveEntryProto> entry_proto; | 411 scoped_ptr<DriveEntryProto> entry_proto; |
477 resource_metadata_->GetEntryInfoByResourceId( | 412 resource_metadata_->GetEntryInfoByResourceId( |
478 file9_resource_id, | 413 file9_resource_id, |
479 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, | 414 base::Bind(&test_util::CopyResultsFromGetEntryInfoWithFilePathCallback, |
480 &error, &drive_file_path, &entry_proto)); | 415 &error, &drive_file_path, &entry_proto)); |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 | 1134 |
1200 // Confirm that the sub directory contains the changestamp. | 1135 // Confirm that the sub directory contains the changestamp. |
1201 ASSERT_EQ(1, new_proto.drive_directory().child_directories_size()); | 1136 ASSERT_EQ(1, new_proto.drive_directory().child_directories_size()); |
1202 const DriveDirectoryProto& dir_proto = root_proto.child_directories(0); | 1137 const DriveDirectoryProto& dir_proto = root_proto.child_directories(0); |
1203 EXPECT_EQ(kChangestamp, | 1138 EXPECT_EQ(kChangestamp, |
1204 dir_proto.drive_entry().directory_specific_info().changestamp()); | 1139 dir_proto.drive_entry().directory_specific_info().changestamp()); |
1205 | 1140 |
1206 } | 1141 } |
1207 | 1142 |
1208 } // namespace drive | 1143 } // namespace drive |
OLD | NEW |