Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" | |
| 6 | |
| 7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | |
| 8 #include "chrome/browser/google_apis/fake_drive_service.h" | |
| 9 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | |
| 10 #include "chrome/browser/google_apis/test_util.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace drive { | |
| 14 namespace file_system { | |
| 15 | |
| 16 typedef OperationTestBase RemoveOperationTest; | |
| 17 | |
| 18 TEST_F(RemoveOperationTest, RemoveFile) { | |
| 19 RemoveOperation operation(observer(), scheduler(), metadata(), cache()); | |
| 20 | |
| 21 base::FilePath my_drive(FILE_PATH_LITERAL("drive/root")); | |
| 22 base::FilePath nonexisting_file( | |
| 23 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | |
| 24 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
| 25 base::FilePath file_in_subdir( | |
| 26 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 27 | |
| 28 // Remove a file in root. | |
| 29 ResourceEntry entry; | |
| 30 FileError error = FILE_ERROR_FAILED; | |
| 31 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry)); | |
| 32 operation.Remove(file_in_root, | |
| 33 false, | |
|
hashimoto
2013/05/28 02:34:45
nit: Please add comments to describe about these b
kinaba
2013/05/28 03:31:28
Done.
| |
| 34 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 35 google_apis::test_util::RunBlockingPoolTask(); | |
| 36 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 37 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(file_in_root, &entry)); | |
| 38 | |
| 39 // Remove a file in subdirectory. | |
| 40 error = FILE_ERROR_FAILED; | |
| 41 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry)); | |
| 42 operation.Remove(file_in_subdir, | |
| 43 false, | |
| 44 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 45 google_apis::test_util::RunBlockingPoolTask(); | |
| 46 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 47 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | |
| 48 GetLocalResourceEntry(file_in_subdir, &entry)); | |
| 49 | |
| 50 // Try removing non-existing file. | |
| 51 error = FILE_ERROR_FAILED; | |
| 52 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | |
| 53 GetLocalResourceEntry(nonexisting_file, &entry)); | |
| 54 operation.Remove(base::FilePath::FromUTF8Unsafe("drive/root/Dummy file.txt"), | |
| 55 false, | |
| 56 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 57 google_apis::test_util::RunBlockingPoolTask(); | |
| 58 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | |
| 59 | |
| 60 // Verify observer notifications. | |
| 61 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | |
| 62 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName())); | |
| 63 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_subdir.DirName())); | |
| 64 } | |
| 65 | |
| 66 TEST_F(RemoveOperationTest, RemoveDirectory) { | |
| 67 RemoveOperation operation(observer(), scheduler(), metadata(), cache()); | |
| 68 | |
| 69 base::FilePath empty_dir(FILE_PATH_LITERAL( | |
| 70 "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")); | |
| 71 base::FilePath non_empty_dir(FILE_PATH_LITERAL( | |
| 72 "drive/root/Directory 1")); | |
| 73 base::FilePath file_in_non_empty_dir(FILE_PATH_LITERAL( | |
| 74 "drive/root/Directory 1/SubDirectory File 1.txt")); | |
| 75 | |
| 76 // Empty directory can be removed even with is_recursive = false. | |
| 77 FileError error = FILE_ERROR_FAILED; | |
| 78 ResourceEntry entry; | |
| 79 operation.Remove(empty_dir, | |
| 80 false, | |
| 81 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 82 google_apis::test_util::RunBlockingPoolTask(); | |
| 83 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 84 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | |
| 85 GetLocalResourceEntry(empty_dir, &entry)); | |
| 86 | |
| 87 // Non-empty directory, cannot. | |
| 88 error = FILE_ERROR_FAILED; | |
| 89 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(non_empty_dir, &entry)); | |
| 90 operation.Remove(non_empty_dir, | |
| 91 false, | |
| 92 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 93 google_apis::test_util::RunBlockingPoolTask(); | |
| 94 EXPECT_EQ(FILE_ERROR_NOT_EMPTY, error); | |
| 95 EXPECT_EQ(FILE_ERROR_OK, | |
| 96 GetLocalResourceEntry(non_empty_dir, &entry)); | |
| 97 | |
| 98 // With is_recursive = true, it can be deleted, however. Descendant entries | |
| 99 // are moved together. | |
|
hashimoto
2013/05/28 02:34:45
nit: s/moved/removed/?
kinaba
2013/05/28 03:31:28
Good catch.
| |
| 100 error = FILE_ERROR_FAILED; | |
| 101 ASSERT_EQ(FILE_ERROR_OK, | |
| 102 GetLocalResourceEntry(file_in_non_empty_dir, &entry)); | |
| 103 operation.Remove(non_empty_dir, | |
| 104 true, | |
| 105 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 106 google_apis::test_util::RunBlockingPoolTask(); | |
| 107 EXPECT_EQ(FILE_ERROR_OK, error); | |
| 108 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | |
| 109 GetLocalResourceEntry(non_empty_dir, &entry)); | |
| 110 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | |
| 111 GetLocalResourceEntry(file_in_non_empty_dir, &entry)); | |
| 112 } | |
| 113 | |
| 114 } // namespace file_system | |
| 115 } // namespace drive | |
| OLD | NEW |