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

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

Issue 158723003: drive: Add tests for FileSystem methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change parent Created 6 years, 10 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/file_system.h" 5 #include "chrome/browser/chromeos/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"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/prefs/testing_pref_service.h" 16 #include "base/prefs/testing_pref_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "chrome/browser/chromeos/drive/change_list_loader.h" 18 #include "chrome/browser/chromeos/drive/change_list_loader.h"
19 #include "chrome/browser/chromeos/drive/drive.pb.h" 19 #include "chrome/browser/chromeos/drive/drive.pb.h"
20 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 20 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
21 #include "chrome/browser/chromeos/drive/file_system_observer.h" 21 #include "chrome/browser/chromeos/drive/file_system_observer.h"
22 #include "chrome/browser/chromeos/drive/file_system_util.h" 22 #include "chrome/browser/chromeos/drive/file_system_util.h"
23 #include "chrome/browser/chromeos/drive/job_scheduler.h" 23 #include "chrome/browser/chromeos/drive/job_scheduler.h"
24 #include "chrome/browser/chromeos/drive/sync_client.h" 24 #include "chrome/browser/chromeos/drive/sync_client.h"
25 #include "chrome/browser/chromeos/drive/test_util.h" 25 #include "chrome/browser/chromeos/drive/test_util.h"
26 #include "chrome/browser/drive/drive_api_util.h"
26 #include "chrome/browser/drive/event_logger.h" 27 #include "chrome/browser/drive/event_logger.h"
27 #include "chrome/browser/drive/fake_drive_service.h" 28 #include "chrome/browser/drive/fake_drive_service.h"
28 #include "content/public/test/test_browser_thread_bundle.h" 29 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "google_apis/drive/drive_api_parser.h" 30 #include "google_apis/drive/drive_api_parser.h"
30 #include "google_apis/drive/test_util.h" 31 #include "google_apis/drive/test_util.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 33
33 namespace drive { 34 namespace drive {
34 namespace { 35 namespace {
35 36
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 scoped_ptr<MockDirectoryChangeObserver> mock_directory_observer_; 307 scoped_ptr<MockDirectoryChangeObserver> mock_directory_observer_;
307 308
308 scoped_ptr<internal::ResourceMetadataStorage, 309 scoped_ptr<internal::ResourceMetadataStorage,
309 test_util::DestroyHelperForTests> metadata_storage_; 310 test_util::DestroyHelperForTests> metadata_storage_;
310 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; 311 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_;
311 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 312 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
312 resource_metadata_; 313 resource_metadata_;
313 scoped_ptr<FileSystem> file_system_; 314 scoped_ptr<FileSystem> file_system_;
314 }; 315 };
315 316
317 TEST_F(FileSystemTest, Copy) {
318 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
319 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Copied.txt"));
320 EXPECT_TRUE(GetResourceEntrySync(src_file_path));
321 EXPECT_FALSE(GetResourceEntrySync(dest_file_path));
322
323 FileError error = FILE_ERROR_FAILED;
324 file_system_->Copy(src_file_path,
325 dest_file_path,
326 false, // preserve_last_modified,
327 google_apis::test_util::CreateCopyResultCallback(&error));
328 test_util::RunBlockingPoolTask();
329 EXPECT_EQ(FILE_ERROR_OK, error);
330
331 // Entry is added on the server.
332 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path);
333 ASSERT_TRUE(entry);
334
335 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
336 scoped_ptr<google_apis::ResourceEntry> resource_entry;
337 fake_drive_service_->GetResourceEntry(
338 entry->resource_id(),
339 google_apis::test_util::CreateCopyResultCallback(&status,
340 &resource_entry));
341 test_util::RunBlockingPoolTask();
342 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
343 ASSERT_TRUE(resource_entry);
344 EXPECT_EQ(entry->title(), resource_entry->title());
345 EXPECT_TRUE(resource_entry->is_file());
346 }
347
348 TEST_F(FileSystemTest, Move) {
349 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
350 base::FilePath dest_file_path(
351 FILE_PATH_LITERAL("drive/root/Directory 1/Moved.txt"));
352 EXPECT_TRUE(GetResourceEntrySync(src_file_path));
353 EXPECT_FALSE(GetResourceEntrySync(dest_file_path));
354 scoped_ptr<ResourceEntry> parent =
355 GetResourceEntrySync(dest_file_path.DirName());
356 ASSERT_TRUE(parent);
357
358 FileError error = FILE_ERROR_FAILED;
359 file_system_->Move(src_file_path,
360 dest_file_path,
361 false, // preserve_last_modified,
362 google_apis::test_util::CreateCopyResultCallback(&error));
363 test_util::RunBlockingPoolTask();
364 EXPECT_EQ(FILE_ERROR_OK, error);
365
366 // Entry is moved on the server.
367 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(dest_file_path);
368 ASSERT_TRUE(entry);
369
370 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
371 scoped_ptr<google_apis::ResourceEntry> resource_entry;
372 fake_drive_service_->GetResourceEntry(
373 entry->resource_id(),
374 google_apis::test_util::CreateCopyResultCallback(&status,
375 &resource_entry));
376 test_util::RunBlockingPoolTask();
377 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
378 ASSERT_TRUE(resource_entry);
379 EXPECT_EQ(entry->title(), resource_entry->title());
380
381 const google_apis::Link* parent_link =
382 resource_entry->GetLinkByType(google_apis::Link::LINK_PARENT);
383 ASSERT_TRUE(parent_link);
384 EXPECT_EQ(parent->resource_id(),
385 util::ExtractResourceIdFromUrl(parent_link->href()));
386 }
387
388 TEST_F(FileSystemTest, Remove) {
389 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
390 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
391 ASSERT_TRUE(entry);
392
393 FileError error = FILE_ERROR_FAILED;
394 file_system_->Remove(
395 file_path,
396 false, // is_resursive
397 google_apis::test_util::CreateCopyResultCallback(&error));
398 test_util::RunBlockingPoolTask();
399 EXPECT_EQ(FILE_ERROR_OK, error);
400
401 // Entry is removed on the server.
402 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
403 scoped_ptr<google_apis::ResourceEntry> resource_entry;
404 fake_drive_service_->GetResourceEntry(
405 entry->resource_id(),
406 google_apis::test_util::CreateCopyResultCallback(&status,
407 &resource_entry));
408 test_util::RunBlockingPoolTask();
409 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
410 ASSERT_TRUE(resource_entry);
411 EXPECT_TRUE(resource_entry->deleted());
412 }
413
414 TEST_F(FileSystemTest, CreateDirectory) {
415 base::FilePath directory_path(FILE_PATH_LITERAL("drive/root/New Directory"));
416 EXPECT_FALSE(GetResourceEntrySync(directory_path));
417
418 FileError error = FILE_ERROR_FAILED;
419 file_system_->CreateDirectory(
420 directory_path,
421 true, // is_exclusive
422 false, // is_recursive
423 google_apis::test_util::CreateCopyResultCallback(&error));
424 test_util::RunBlockingPoolTask();
425 EXPECT_EQ(FILE_ERROR_OK, error);
426
427 // Directory is created on the server.
428 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(directory_path);
429 ASSERT_TRUE(entry);
430
431 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
432 scoped_ptr<google_apis::ResourceEntry> resource_entry;
433 fake_drive_service_->GetResourceEntry(
434 entry->resource_id(),
435 google_apis::test_util::CreateCopyResultCallback(&status,
436 &resource_entry));
437 test_util::RunBlockingPoolTask();
438 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
439 ASSERT_TRUE(resource_entry);
440 EXPECT_EQ(entry->title(), resource_entry->title());
441 EXPECT_TRUE(resource_entry->is_folder());
442 }
443
444 TEST_F(FileSystemTest, CreateFile) {
445 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/New File.txt"));
446 EXPECT_FALSE(GetResourceEntrySync(file_path));
447
448 FileError error = FILE_ERROR_FAILED;
449 file_system_->CreateFile(
450 file_path,
451 true, // is_exclusive
452 "text/plain",
453 google_apis::test_util::CreateCopyResultCallback(&error));
454 test_util::RunBlockingPoolTask();
455 EXPECT_EQ(FILE_ERROR_OK, error);
456
457 // File is created on the server.
458 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
459 ASSERT_TRUE(entry);
460
461 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
462 scoped_ptr<google_apis::ResourceEntry> resource_entry;
463 fake_drive_service_->GetResourceEntry(
464 entry->resource_id(),
465 google_apis::test_util::CreateCopyResultCallback(&status,
466 &resource_entry));
467 test_util::RunBlockingPoolTask();
468 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
469 ASSERT_TRUE(resource_entry);
470 EXPECT_EQ(entry->title(), resource_entry->title());
471 EXPECT_TRUE(resource_entry->is_file());
472 }
473
474 TEST_F(FileSystemTest, TouchFile) {
475 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
476 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
477 ASSERT_TRUE(entry);
478
479 base::Time last_accessed =
480 base::Time::FromInternalValue(entry->file_info().last_accessed()) +
481 base::TimeDelta::FromSeconds(1);
482 base::Time last_modified =
483 base::Time::FromInternalValue(entry->file_info().last_modified()) +
484 base::TimeDelta::FromSeconds(1);
485
486 FileError error = FILE_ERROR_FAILED;
487 file_system_->TouchFile(
488 file_path,
489 last_accessed,
490 last_modified,
491 google_apis::test_util::CreateCopyResultCallback(&error));
492 test_util::RunBlockingPoolTask();
493 EXPECT_EQ(FILE_ERROR_OK, error);
494
495 // File is touched on the server.
496 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
497 scoped_ptr<google_apis::ResourceEntry> resource_entry;
498 fake_drive_service_->GetResourceEntry(
499 entry->resource_id(),
500 google_apis::test_util::CreateCopyResultCallback(&status,
501 &resource_entry));
502 test_util::RunBlockingPoolTask();
503 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
504 ASSERT_TRUE(resource_entry);
505 EXPECT_EQ(last_accessed, resource_entry->last_viewed_time());
506 EXPECT_EQ(last_modified, resource_entry->updated_time());
507 }
508
509 TEST_F(FileSystemTest, TruncateFile) {
510 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
511 scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(file_path);
512 ASSERT_TRUE(entry);
513
514 const int64 kLength = entry->file_info().size() + 100;
515
516 FileError error = FILE_ERROR_FAILED;
517 file_system_->TruncateFile(
518 file_path,
519 kLength,
520 google_apis::test_util::CreateCopyResultCallback(&error));
521 test_util::RunBlockingPoolTask();
522 EXPECT_EQ(FILE_ERROR_OK, error);
523
524 // File is touched on the server.
525 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
526 scoped_ptr<google_apis::ResourceEntry> resource_entry;
527 fake_drive_service_->GetResourceEntry(
528 entry->resource_id(),
529 google_apis::test_util::CreateCopyResultCallback(&status,
530 &resource_entry));
531 test_util::RunBlockingPoolTask();
532 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
533 ASSERT_TRUE(resource_entry);
534 EXPECT_EQ(kLength, resource_entry->file_size());
535 }
536
316 TEST_F(FileSystemTest, DuplicatedAsyncInitialization) { 537 TEST_F(FileSystemTest, DuplicatedAsyncInitialization) {
317 base::RunLoop loop; 538 base::RunLoop loop;
318 539
319 int counter = 0; 540 int counter = 0;
320 const GetResourceEntryCallback& callback = base::Bind( 541 const GetResourceEntryCallback& callback = base::Bind(
321 &AsyncInitializationCallback, &counter, 2, loop.QuitClosure()); 542 &AsyncInitializationCallback, &counter, 2, loop.QuitClosure());
322 543
323 file_system_->GetResourceEntry( 544 file_system_->GetResourceEntry(
324 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); 545 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback);
325 file_system_->GetResourceEntry( 546 file_system_->GetResourceEntry(
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 kEmbedOrigin, 951 kEmbedOrigin,
731 google_apis::test_util::CreateCopyResultCallback(&error, &share_url)); 952 google_apis::test_util::CreateCopyResultCallback(&error, &share_url));
732 test_util::RunBlockingPoolTask(); 953 test_util::RunBlockingPoolTask();
733 954
734 // Verify the error and the share url, which should be empty. 955 // Verify the error and the share url, which should be empty.
735 EXPECT_EQ(FILE_ERROR_FAILED, error); 956 EXPECT_EQ(FILE_ERROR_FAILED, error);
736 EXPECT_TRUE(share_url.is_empty()); 957 EXPECT_TRUE(share_url.is_empty());
737 } 958 }
738 959
739 } // namespace drive 960 } // 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