Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/chromeos/drive/drive_file_system_unittest.cc

Issue 12679008: chromeos: Stop dealing with metadata proto from DriveFileSystemTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_file_system.h" 5 #include "chrome/browser/chromeos/drive/drive_file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 google_apis::test_util::RunBlockingPoolTask(); 392 google_apis::test_util::RunBlockingPoolTask();
393 return error == DRIVE_FILE_OK; 393 return error == DRIVE_FILE_OK;
394 } 394 }
395 395
396 // Flag for specifying the timestamp of the test filesystem cache. 396 // Flag for specifying the timestamp of the test filesystem cache.
397 enum SaveTestFileSystemParam { 397 enum SaveTestFileSystemParam {
398 USE_OLD_TIMESTAMP, 398 USE_OLD_TIMESTAMP,
399 USE_SERVER_TIMESTAMP, 399 USE_SERVER_TIMESTAMP,
400 }; 400 };
401 401
402 // Creates a proto file representing a filesystem with directories: 402 // Saves a file representing a filesystem with directories:
403 // drive, drive/Dir1, drive/Dir1/SubDir2 403 // drive, drive/Dir1, drive/Dir1/SubDir2
404 // and files 404 // and files
405 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. 405 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3.
406 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321, 406 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321,
407 // equal to that of "account_metadata.json" test data, indicating the cache is 407 // equal to that of "account_metadata.json" test data, indicating the cache is
408 // holding the latest file system info. 408 // holding the latest file system info.
409 void SaveTestFileSystem(SaveTestFileSystemParam param) { 409 void SaveTestFileSystem(SaveTestFileSystemParam param) {
410 DriveRootDirectoryProto root; 410 const std::string root_resource_id =
411 root.set_version(kProtoVersion); 411 fake_drive_service_->GetRootResourceId();
412 root.set_largest_changestamp(param == USE_SERVER_TIMESTAMP ? 654321 : 1); 412 DriveResourceMetadata resource_metadata(root_resource_id,
413 DriveDirectoryProto* root_dir = root.mutable_drive_directory(); 413 blocking_task_runner_);
414 DriveEntryProto* dir_base = root_dir->mutable_drive_entry(); 414
415 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); 415 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
416 dir_base->set_title("drive"); 416 resource_metadata.SetLargestChangestamp(
417 dir_base->set_resource_id(fake_drive_service_->GetRootResourceId()); 417 param == USE_SERVER_TIMESTAMP ? 654321 : 1,
418 dir_base->set_upload_url("http://resumable-create-media/1"); 418 google_apis::test_util::CreateCopyResultCallback(&error));
419 platform_info->set_is_directory(true); 419 google_apis::test_util::RunBlockingPoolTask();
420 EXPECT_EQ(DRIVE_FILE_OK, error);
hidehiko 2013/03/18 08:53:08 This is a kind of set up, how about checking the e
hashimoto 2013/03/18 09:10:05 Done. Return bool and assert the result.
420 421
421 // drive/File1 422 // drive/File1
422 DriveEntryProto* file = root_dir->add_child_files(); 423 DriveEntryProto file1;
423 file->set_title("File1"); 424 file1.set_title("File1");
424 file->set_resource_id("resource_id:File1"); 425 file1.set_resource_id("resource_id:File1");
425 file->set_parent_resource_id(root_dir->drive_entry().resource_id()); 426 file1.set_parent_resource_id(root_resource_id);
426 file->set_upload_url("http://resumable-edit-media/1"); 427 file1.set_upload_url("http://resumable-edit-media/1");
427 file->mutable_file_specific_info()->set_file_md5("md5"); 428 file1.mutable_file_specific_info()->set_file_md5("md5");
428 platform_info = file->mutable_file_info(); 429 file1.mutable_file_info()->set_is_directory(false);
429 platform_info->set_is_directory(false); 430 file1.mutable_file_info()->set_size(1048576);
430 platform_info->set_size(1048576); 431 base::FilePath file_path;
432 resource_metadata.AddEntry(
433 file1,
434 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
435 google_apis::test_util::RunBlockingPoolTask();
436 EXPECT_EQ(DRIVE_FILE_OK, error);
431 437
432 // drive/Dir1 438 // drive/Dir1
433 DriveDirectoryProto* dir1 = root_dir->add_child_directories(); 439 DriveEntryProto dir1;
434 dir_base = dir1->mutable_drive_entry(); 440 dir1.set_title("Dir1");
435 dir_base->set_title("Dir1"); 441 dir1.set_resource_id("resource_id:Dir1");
436 dir_base->set_resource_id("resource_id:Dir1"); 442 dir1.set_parent_resource_id(root_resource_id);
437 dir_base->set_parent_resource_id(root_dir->drive_entry().resource_id()); 443 dir1.set_upload_url("http://resumable-create-media/2");
438 dir_base->set_upload_url("http://resumable-create-media/2"); 444 dir1.mutable_file_info()->set_is_directory(true);
439 platform_info = dir_base->mutable_file_info(); 445 resource_metadata.AddEntry(
440 platform_info->set_is_directory(true); 446 dir1,
447 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
448 google_apis::test_util::RunBlockingPoolTask();
449 EXPECT_EQ(DRIVE_FILE_OK, error);
441 450
442 // drive/Dir1/File2 451 // drive/Dir1/File2
443 file = dir1->add_child_files(); 452 DriveEntryProto file2;
444 file->set_title("File2"); 453 file2.set_title("File2");
445 file->set_resource_id("resource_id:File2"); 454 file2.set_resource_id("resource_id:File2");
446 file->set_parent_resource_id(dir1->drive_entry().resource_id()); 455 file2.set_parent_resource_id(dir1.resource_id());
447 file->set_upload_url("http://resumable-edit-media/2"); 456 file2.set_upload_url("http://resumable-edit-media/2");
448 file->mutable_file_specific_info()->set_file_md5("md5"); 457 file2.mutable_file_specific_info()->set_file_md5("md5");
449 platform_info = file->mutable_file_info(); 458 file2.mutable_file_info()->set_is_directory(false);
450 platform_info->set_is_directory(false); 459 file2.mutable_file_info()->set_size(555);
451 platform_info->set_size(555); 460 resource_metadata.AddEntry(
461 file2,
462 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
463 google_apis::test_util::RunBlockingPoolTask();
464 EXPECT_EQ(DRIVE_FILE_OK, error);
452 465
453 // drive/Dir1/SubDir2 466 // drive/Dir1/SubDir2
454 DriveDirectoryProto* dir2 = dir1->add_child_directories(); 467 DriveEntryProto dir2;
455 dir_base = dir2->mutable_drive_entry(); 468 dir2.set_title("SubDir2");
456 dir_base->set_title("SubDir2"); 469 dir2.set_resource_id("resource_id:SubDir2");
457 dir_base->set_resource_id("resource_id:SubDir2"); 470 dir2.set_parent_resource_id(dir1.resource_id());
458 dir_base->set_parent_resource_id(dir1->drive_entry().resource_id()); 471 dir2.set_upload_url("http://resumable-create-media/3");
459 dir_base->set_upload_url("http://resumable-create-media/3"); 472 dir2.mutable_file_info()->set_is_directory(true);
460 platform_info = dir_base->mutable_file_info(); 473 resource_metadata.AddEntry(
461 platform_info->set_is_directory(true); 474 dir2,
475 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
476 google_apis::test_util::RunBlockingPoolTask();
477 EXPECT_EQ(DRIVE_FILE_OK, error);
462 478
463 // drive/Dir1/SubDir2/File3 479 // drive/Dir1/SubDir2/File3
464 file = dir2->add_child_files(); 480 DriveEntryProto file3;
465 file->set_title("File3"); 481 file3.set_title("File3");
466 file->set_resource_id("resource_id:File3"); 482 file3.set_resource_id("resource_id:File3");
467 file->set_parent_resource_id(dir2->drive_entry().resource_id()); 483 file3.set_parent_resource_id(dir2.resource_id());
468 file->set_upload_url("http://resumable-edit-media/3"); 484 file3.set_upload_url("http://resumable-edit-media/3");
469 file->mutable_file_specific_info()->set_file_md5("md5"); 485 file3.mutable_file_specific_info()->set_file_md5("md5");
470 platform_info = file->mutable_file_info(); 486 file3.mutable_file_info()->set_is_directory(false);
471 platform_info->set_is_directory(false); 487 file3.mutable_file_info()->set_size(12345);
472 platform_info->set_size(12345); 488 resource_metadata.AddEntry(
489 file3,
490 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
491 google_apis::test_util::RunBlockingPoolTask();
492 EXPECT_EQ(DRIVE_FILE_OK, error);
473 493
474 // Write this proto out to GCache/vi/meta/file_system.pb 494 // Write resource metadata.
475 std::string serialized_proto; 495 base::FilePath cache_dir_path =
476 ASSERT_TRUE(root.SerializeToString(&serialized_proto)); 496 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META);
477 ASSERT_TRUE(!serialized_proto.empty());
478
479 base::FilePath cache_dir_path = profile_->GetPath().Append(
480 FILE_PATH_LITERAL("GCache/v1/meta/"));
481 ASSERT_TRUE(file_util::CreateDirectory(cache_dir_path)); 497 ASSERT_TRUE(file_util::CreateDirectory(cache_dir_path));
482 const int file_size = static_cast<int>(serialized_proto.length()); 498 resource_metadata.MaybeSave(cache_dir_path);
483 ASSERT_EQ(file_util::WriteFile(cache_dir_path.AppendASCII("file_system.pb"), 499 google_apis::test_util::RunBlockingPoolTask();
484 serialized_proto.data(), file_size), file_size);
485 } 500 }
486 501
487 // Verifies that |file_path| is a valid JSON file for the hosted document 502 // Verifies that |file_path| is a valid JSON file for the hosted document
488 // associated with |entry| (i.e. |url| and |resource_id| match). 503 // associated with |entry| (i.e. |url| and |resource_id| match).
489 void VerifyHostedDocumentJSONFile(const DriveEntryProto& entry_proto, 504 void VerifyHostedDocumentJSONFile(const DriveEntryProto& entry_proto,
490 const base::FilePath& file_path) { 505 const base::FilePath& file_path) {
491 std::string error; 506 std::string error;
492 JSONFileValueSerializer serializer(file_path); 507 JSONFileValueSerializer serializer(file_path);
493 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error)); 508 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error));
494 ASSERT_TRUE(value.get()) << "Parse error " << file_path.value() 509 ASSERT_TRUE(value.get()) << "Parse error " << file_path.value()
(...skipping 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 2193
2179 // An app for foo.exe should now be found, as the registry was loaded. 2194 // An app for foo.exe should now be found, as the registry was loaded.
2180 drive_webapps_registry_->GetWebAppsForFile( 2195 drive_webapps_registry_->GetWebAppsForFile(
2181 base::FilePath(FILE_PATH_LITERAL("foo.exe")), 2196 base::FilePath(FILE_PATH_LITERAL("foo.exe")),
2182 "" /* mime_type */, 2197 "" /* mime_type */,
2183 &apps); 2198 &apps);
2184 EXPECT_EQ(1U, apps.size()); 2199 EXPECT_EQ(1U, apps.size());
2185 } 2200 }
2186 2201
2187 } // namespace drive 2202 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698