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

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

Issue 12706012: chromeos: Destruct DriveResourceMetadata on the blocking pool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add note 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
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 fake_drive_service_->LoadAppListForDriveApi("chromeos/drive/applist.json"); 209 fake_drive_service_->LoadAppListForDriveApi("chromeos/drive/applist.json");
210 210
211 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); 211 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter);
212 212
213 scoped_refptr<base::SequencedWorkerPool> pool = 213 scoped_refptr<base::SequencedWorkerPool> pool =
214 content::BrowserThread::GetBlockingPool(); 214 content::BrowserThread::GetBlockingPool();
215 blocking_task_runner_ = 215 blocking_task_runner_ =
216 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); 216 pool->GetSequencedTaskRunner(pool->GetSequenceToken());
217 217
218 // Likewise, this will be owned by DriveFileSystem. 218 // Likewise, this will be owned by DriveFileSystem.
219 cache_ = new DriveCache( 219 cache_.reset(new DriveCache(DriveCache::GetCacheRootPath(profile_.get()),
220 DriveCache::GetCacheRootPath(profile_.get()), 220 blocking_task_runner_,
221 blocking_task_runner_, 221 fake_free_disk_space_getter_.get()));
222 fake_free_disk_space_getter_.get());
223 222
224 fake_uploader_.reset(new FakeDriveUploader); 223 fake_uploader_.reset(new FakeDriveUploader);
225 drive_webapps_registry_.reset(new DriveWebAppsRegistry); 224 drive_webapps_registry_.reset(new DriveWebAppsRegistry);
226 225
227 ASSERT_FALSE(file_system_); 226 ASSERT_FALSE(file_system_);
228 file_system_ = new DriveFileSystem(profile_.get(), 227 file_system_ = new DriveFileSystem(profile_.get(),
229 cache_, 228 cache_.get(),
230 fake_drive_service_, 229 fake_drive_service_,
231 fake_uploader_.get(), 230 fake_uploader_.get(),
232 drive_webapps_registry_.get(), 231 drive_webapps_registry_.get(),
233 blocking_task_runner_); 232 blocking_task_runner_);
234 233
235 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); 234 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>);
236 cache_->AddObserver(mock_cache_observer_.get()); 235 cache_->AddObserver(mock_cache_observer_.get());
237 236
238 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>); 237 mock_directory_observer_.reset(new StrictMock<MockDirectoryChangeObserver>);
239 file_system_->AddObserver(mock_directory_observer_.get()); 238 file_system_->AddObserver(mock_directory_observer_.get());
240 239
241 file_system_->Initialize(); 240 file_system_->Initialize();
242 cache_->RequestInitializeForTesting(); 241 cache_->RequestInitializeForTesting();
243 google_apis::test_util::RunBlockingPoolTask(); 242 google_apis::test_util::RunBlockingPoolTask();
244 } 243 }
245 244
246 virtual void TearDown() OVERRIDE { 245 virtual void TearDown() OVERRIDE {
247 ASSERT_TRUE(file_system_); 246 ASSERT_TRUE(file_system_);
248 delete file_system_; 247 delete file_system_;
249 file_system_ = NULL; 248 file_system_ = NULL;
250 delete fake_drive_service_; 249 delete fake_drive_service_;
251 fake_drive_service_ = NULL; 250 fake_drive_service_ = NULL;
252 test_util::DeleteDriveCache(cache_); 251 cache_.reset();
253 profile_.reset(NULL); 252 profile_.reset(NULL);
254 } 253 }
255 254
256 // Loads test json file as root ("/drive") element. 255 // Loads test json file as root ("/drive") element.
257 bool LoadRootFeedDocument() { 256 bool LoadRootFeedDocument() {
258 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 257 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
259 file_system_->change_list_loader()->LoadFromServerIfNeeded( 258 file_system_->change_list_loader()->LoadFromServerIfNeeded(
260 DirectoryFetchInfo(), 259 DirectoryFetchInfo(),
261 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, 260 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback,
262 &error)); 261 &error));
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 // Saves a file representing a filesystem with directories: 401 // Saves a file representing a filesystem with directories:
403 // drive, drive/Dir1, drive/Dir1/SubDir2 402 // drive, drive/Dir1, drive/Dir1/SubDir2
404 // and files 403 // and files
405 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. 404 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3.
406 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321, 405 // 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 406 // equal to that of "account_metadata.json" test data, indicating the cache is
408 // holding the latest file system info. 407 // holding the latest file system info.
409 bool SaveTestFileSystem(SaveTestFileSystemParam param) { 408 bool SaveTestFileSystem(SaveTestFileSystemParam param) {
410 const std::string root_resource_id = 409 const std::string root_resource_id =
411 fake_drive_service_->GetRootResourceId(); 410 fake_drive_service_->GetRootResourceId();
412 DriveResourceMetadata resource_metadata(root_resource_id, 411 scoped_ptr<DriveResourceMetadata, test_util::DestroyHelperForTests>
413 blocking_task_runner_); 412 resource_metadata(new DriveResourceMetadata(root_resource_id,
413 blocking_task_runner_));
414 414
415 DriveFileError error = DRIVE_FILE_ERROR_FAILED; 415 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
416 resource_metadata.SetLargestChangestamp( 416 resource_metadata->SetLargestChangestamp(
417 param == USE_SERVER_TIMESTAMP ? 654321 : 1, 417 param == USE_SERVER_TIMESTAMP ? 654321 : 1,
418 google_apis::test_util::CreateCopyResultCallback(&error)); 418 google_apis::test_util::CreateCopyResultCallback(&error));
419 google_apis::test_util::RunBlockingPoolTask(); 419 google_apis::test_util::RunBlockingPoolTask();
420 if (error != DRIVE_FILE_OK) 420 if (error != DRIVE_FILE_OK)
421 return false; 421 return false;
422 422
423 // drive/File1 423 // drive/File1
424 DriveEntryProto file1; 424 DriveEntryProto file1;
425 file1.set_title("File1"); 425 file1.set_title("File1");
426 file1.set_resource_id("resource_id:File1"); 426 file1.set_resource_id("resource_id:File1");
427 file1.set_parent_resource_id(root_resource_id); 427 file1.set_parent_resource_id(root_resource_id);
428 file1.set_upload_url("http://resumable-edit-media/1"); 428 file1.set_upload_url("http://resumable-edit-media/1");
429 file1.mutable_file_specific_info()->set_file_md5("md5"); 429 file1.mutable_file_specific_info()->set_file_md5("md5");
430 file1.mutable_file_info()->set_is_directory(false); 430 file1.mutable_file_info()->set_is_directory(false);
431 file1.mutable_file_info()->set_size(1048576); 431 file1.mutable_file_info()->set_size(1048576);
432 base::FilePath file_path; 432 base::FilePath file_path;
433 resource_metadata.AddEntry( 433 resource_metadata->AddEntry(
434 file1, 434 file1,
435 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 435 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
436 google_apis::test_util::RunBlockingPoolTask(); 436 google_apis::test_util::RunBlockingPoolTask();
437 if (error != DRIVE_FILE_OK) 437 if (error != DRIVE_FILE_OK)
438 return false; 438 return false;
439 439
440 // drive/Dir1 440 // drive/Dir1
441 DriveEntryProto dir1; 441 DriveEntryProto dir1;
442 dir1.set_title("Dir1"); 442 dir1.set_title("Dir1");
443 dir1.set_resource_id("resource_id:Dir1"); 443 dir1.set_resource_id("resource_id:Dir1");
444 dir1.set_parent_resource_id(root_resource_id); 444 dir1.set_parent_resource_id(root_resource_id);
445 dir1.set_upload_url("http://resumable-create-media/2"); 445 dir1.set_upload_url("http://resumable-create-media/2");
446 dir1.mutable_file_info()->set_is_directory(true); 446 dir1.mutable_file_info()->set_is_directory(true);
447 resource_metadata.AddEntry( 447 resource_metadata->AddEntry(
448 dir1, 448 dir1,
449 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 449 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
450 google_apis::test_util::RunBlockingPoolTask(); 450 google_apis::test_util::RunBlockingPoolTask();
451 if (error != DRIVE_FILE_OK) 451 if (error != DRIVE_FILE_OK)
452 return false; 452 return false;
453 453
454 // drive/Dir1/File2 454 // drive/Dir1/File2
455 DriveEntryProto file2; 455 DriveEntryProto file2;
456 file2.set_title("File2"); 456 file2.set_title("File2");
457 file2.set_resource_id("resource_id:File2"); 457 file2.set_resource_id("resource_id:File2");
458 file2.set_parent_resource_id(dir1.resource_id()); 458 file2.set_parent_resource_id(dir1.resource_id());
459 file2.set_upload_url("http://resumable-edit-media/2"); 459 file2.set_upload_url("http://resumable-edit-media/2");
460 file2.mutable_file_specific_info()->set_file_md5("md5"); 460 file2.mutable_file_specific_info()->set_file_md5("md5");
461 file2.mutable_file_info()->set_is_directory(false); 461 file2.mutable_file_info()->set_is_directory(false);
462 file2.mutable_file_info()->set_size(555); 462 file2.mutable_file_info()->set_size(555);
463 resource_metadata.AddEntry( 463 resource_metadata->AddEntry(
464 file2, 464 file2,
465 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 465 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
466 google_apis::test_util::RunBlockingPoolTask(); 466 google_apis::test_util::RunBlockingPoolTask();
467 if (error != DRIVE_FILE_OK) 467 if (error != DRIVE_FILE_OK)
468 return false; 468 return false;
469 469
470 // drive/Dir1/SubDir2 470 // drive/Dir1/SubDir2
471 DriveEntryProto dir2; 471 DriveEntryProto dir2;
472 dir2.set_title("SubDir2"); 472 dir2.set_title("SubDir2");
473 dir2.set_resource_id("resource_id:SubDir2"); 473 dir2.set_resource_id("resource_id:SubDir2");
474 dir2.set_parent_resource_id(dir1.resource_id()); 474 dir2.set_parent_resource_id(dir1.resource_id());
475 dir2.set_upload_url("http://resumable-create-media/3"); 475 dir2.set_upload_url("http://resumable-create-media/3");
476 dir2.mutable_file_info()->set_is_directory(true); 476 dir2.mutable_file_info()->set_is_directory(true);
477 resource_metadata.AddEntry( 477 resource_metadata->AddEntry(
478 dir2, 478 dir2,
479 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 479 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
480 google_apis::test_util::RunBlockingPoolTask(); 480 google_apis::test_util::RunBlockingPoolTask();
481 if (error != DRIVE_FILE_OK) 481 if (error != DRIVE_FILE_OK)
482 return false; 482 return false;
483 483
484 // drive/Dir1/SubDir2/File3 484 // drive/Dir1/SubDir2/File3
485 DriveEntryProto file3; 485 DriveEntryProto file3;
486 file3.set_title("File3"); 486 file3.set_title("File3");
487 file3.set_resource_id("resource_id:File3"); 487 file3.set_resource_id("resource_id:File3");
488 file3.set_parent_resource_id(dir2.resource_id()); 488 file3.set_parent_resource_id(dir2.resource_id());
489 file3.set_upload_url("http://resumable-edit-media/3"); 489 file3.set_upload_url("http://resumable-edit-media/3");
490 file3.mutable_file_specific_info()->set_file_md5("md5"); 490 file3.mutable_file_specific_info()->set_file_md5("md5");
491 file3.mutable_file_info()->set_is_directory(false); 491 file3.mutable_file_info()->set_is_directory(false);
492 file3.mutable_file_info()->set_size(12345); 492 file3.mutable_file_info()->set_size(12345);
493 resource_metadata.AddEntry( 493 resource_metadata->AddEntry(
494 file3, 494 file3,
495 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 495 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
496 google_apis::test_util::RunBlockingPoolTask(); 496 google_apis::test_util::RunBlockingPoolTask();
497 if (error != DRIVE_FILE_OK) 497 if (error != DRIVE_FILE_OK)
498 return false; 498 return false;
499 499
500 // Write resource metadata. 500 // Write resource metadata.
501 base::FilePath cache_dir_path = 501 base::FilePath cache_dir_path =
502 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META); 502 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META);
503 if (!file_util::CreateDirectory(cache_dir_path)) 503 if (!file_util::CreateDirectory(cache_dir_path))
504 return false; 504 return false;
505 resource_metadata.MaybeSave(cache_dir_path); 505 resource_metadata->MaybeSave(cache_dir_path);
506 google_apis::test_util::RunBlockingPoolTask(); 506 google_apis::test_util::RunBlockingPoolTask();
507 507
508 return true; 508 return true;
509 } 509 }
510 510
511 // Verifies that |file_path| is a valid JSON file for the hosted document 511 // Verifies that |file_path| is a valid JSON file for the hosted document
512 // associated with |entry| (i.e. |url| and |resource_id| match). 512 // associated with |entry| (i.e. |url| and |resource_id| match).
513 void VerifyHostedDocumentJSONFile(const DriveEntryProto& entry_proto, 513 void VerifyHostedDocumentJSONFile(const DriveEntryProto& entry_proto,
514 const base::FilePath& file_path) { 514 const base::FilePath& file_path) {
515 std::string error; 515 std::string error;
(...skipping 12 matching lines...) Expand all
528 edit_url); 528 edit_url);
529 EXPECT_EQ(entry_proto.resource_id(), resource_id); 529 EXPECT_EQ(entry_proto.resource_id(), resource_id);
530 } 530 }
531 531
532 MessageLoopForUI message_loop_; 532 MessageLoopForUI message_loop_;
533 // The order of the test threads is important, do not change the order. 533 // The order of the test threads is important, do not change the order.
534 // See also content/browser/browser_thread_impl.cc. 534 // See also content/browser/browser_thread_impl.cc.
535 content::TestBrowserThread ui_thread_; 535 content::TestBrowserThread ui_thread_;
536 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 536 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
537 scoped_ptr<TestingProfile> profile_; 537 scoped_ptr<TestingProfile> profile_;
538 DriveCache* cache_; 538 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_;
539 scoped_ptr<FakeDriveUploader> fake_uploader_; 539 scoped_ptr<FakeDriveUploader> fake_uploader_;
540 DriveFileSystem* file_system_; 540 DriveFileSystem* file_system_;
541 google_apis::FakeDriveService* fake_drive_service_; 541 google_apis::FakeDriveService* fake_drive_service_;
542 scoped_ptr<DriveWebAppsRegistry> drive_webapps_registry_; 542 scoped_ptr<DriveWebAppsRegistry> drive_webapps_registry_;
543 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; 543 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
544 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; 544 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_;
545 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 545 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
546 546
547 bool expected_success_; 547 bool expected_success_;
548 std::string expected_file_extension_; 548 std::string expected_file_extension_;
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 2202
2203 // An app for foo.exe should now be found, as the registry was loaded. 2203 // An app for foo.exe should now be found, as the registry was loaded.
2204 drive_webapps_registry_->GetWebAppsForFile( 2204 drive_webapps_registry_->GetWebAppsForFile(
2205 base::FilePath(FILE_PATH_LITERAL("foo.exe")), 2205 base::FilePath(FILE_PATH_LITERAL("foo.exe")),
2206 "" /* mime_type */, 2206 "" /* mime_type */,
2207 &apps); 2207 &apps);
2208 EXPECT_EQ(1U, apps.size()); 2208 EXPECT_EQ(1U, apps.size());
2209 } 2209 }
2210 2210
2211 } // namespace drive 2211 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_system.h ('k') | chrome/browser/chromeos/drive/drive_file_system_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698