OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/remove_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
8 #include "chrome/browser/drive/fake_drive_service.h" | 8 #include "chrome/browser/chromeos/drive/file_system_util.h" |
9 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | |
10 #include "chrome/browser/google_apis/test_util.h" | 9 #include "chrome/browser/google_apis/test_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
12 | 11 |
13 namespace drive { | 12 namespace drive { |
14 namespace file_system { | 13 namespace file_system { |
15 | 14 |
16 typedef OperationTestBase RemoveOperationTest; | 15 typedef OperationTestBase RemoveOperationTest; |
17 | 16 |
18 TEST_F(RemoveOperationTest, RemoveFile) { | 17 TEST_F(RemoveOperationTest, RemoveFile) { |
19 RemoveOperation operation(blocking_task_runner(), observer(), scheduler(), | 18 RemoveOperation operation(blocking_task_runner(), observer(), metadata(), |
20 metadata(), cache()); | 19 cache()); |
21 | 20 |
22 base::FilePath my_drive(FILE_PATH_LITERAL("drive/root")); | |
23 base::FilePath nonexisting_file( | 21 base::FilePath nonexisting_file( |
24 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | 22 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
25 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 23 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
26 base::FilePath file_in_subdir( | 24 base::FilePath file_in_subdir( |
27 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 25 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
28 | 26 |
29 // Remove a file in root. | 27 // Remove a file in root. |
30 ResourceEntry entry; | 28 ResourceEntry entry; |
31 FileError error = FILE_ERROR_FAILED; | 29 FileError error = FILE_ERROR_FAILED; |
32 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry)); | 30 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry)); |
33 operation.Remove(file_in_root, | 31 operation.Remove(file_in_root, |
34 false, // is_recursive | 32 false, // is_recursive |
35 google_apis::test_util::CreateCopyResultCallback(&error)); | 33 google_apis::test_util::CreateCopyResultCallback(&error)); |
36 test_util::RunBlockingPoolTask(); | 34 test_util::RunBlockingPoolTask(); |
37 EXPECT_EQ(FILE_ERROR_OK, error); | 35 EXPECT_EQ(FILE_ERROR_OK, error); |
38 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(file_in_root, &entry)); | 36 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(file_in_root, &entry)); |
39 | 37 |
38 const std::string id_file_in_root = entry.local_id(); | |
39 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntryById(id_file_in_root, &entry)); | |
40 EXPECT_EQ(util::kDriveOtherDirLocalId, entry.parent_local_id()); | |
41 EXPECT_TRUE(entry.deleted()); | |
42 | |
40 // Remove a file in subdirectory. | 43 // Remove a file in subdirectory. |
44 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry)); | |
45 | |
41 error = FILE_ERROR_FAILED; | 46 error = FILE_ERROR_FAILED; |
42 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry)); | |
43 const std::string resource_id = entry.resource_id(); | |
44 | |
45 operation.Remove(file_in_subdir, | 47 operation.Remove(file_in_subdir, |
46 false, // is_recursive | 48 false, // is_recursive |
47 google_apis::test_util::CreateCopyResultCallback(&error)); | 49 google_apis::test_util::CreateCopyResultCallback(&error)); |
48 test_util::RunBlockingPoolTask(); | 50 test_util::RunBlockingPoolTask(); |
49 EXPECT_EQ(FILE_ERROR_OK, error); | 51 EXPECT_EQ(FILE_ERROR_OK, error); |
50 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 52 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
51 GetLocalResourceEntry(file_in_subdir, &entry)); | 53 GetLocalResourceEntry(file_in_subdir, &entry)); |
52 | 54 |
53 // Verify the file is indeed removed in the server. | 55 const std::string id_file_in_subdir = entry.local_id(); |
54 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; | 56 EXPECT_EQ(FILE_ERROR_OK, |
55 scoped_ptr<google_apis::ResourceEntry> gdata_entry; | 57 GetLocalResourceEntryById(id_file_in_subdir, &entry)); |
56 fake_service()->GetResourceEntry( | 58 EXPECT_EQ(util::kDriveOtherDirLocalId, entry.parent_local_id()); |
57 resource_id, | 59 EXPECT_TRUE(entry.deleted()); |
58 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | |
59 &gdata_entry)); | |
60 test_util::RunBlockingPoolTask(); | |
61 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); | |
62 EXPECT_TRUE(gdata_entry->deleted()); | |
63 | 60 |
64 // Try removing non-existing file. | 61 // Try removing non-existing file. |
65 error = FILE_ERROR_FAILED; | 62 error = FILE_ERROR_FAILED; |
66 ASSERT_EQ(FILE_ERROR_NOT_FOUND, | 63 ASSERT_EQ(FILE_ERROR_NOT_FOUND, |
67 GetLocalResourceEntry(nonexisting_file, &entry)); | 64 GetLocalResourceEntry(nonexisting_file, &entry)); |
68 operation.Remove(base::FilePath::FromUTF8Unsafe("drive/root/Dummy file.txt"), | 65 operation.Remove(nonexisting_file, |
69 false, // is_recursive | 66 false, // is_recursive |
70 google_apis::test_util::CreateCopyResultCallback(&error)); | 67 google_apis::test_util::CreateCopyResultCallback(&error)); |
71 test_util::RunBlockingPoolTask(); | 68 test_util::RunBlockingPoolTask(); |
72 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); | 69 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); |
73 | 70 |
74 // Verify observer notifications. | 71 // Verify observer notifications. |
75 EXPECT_EQ(2U, observer()->get_changed_paths().size()); | 72 EXPECT_EQ(2U, observer()->get_changed_paths().size()); |
76 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName())); | 73 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName())); |
77 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_subdir.DirName())); | 74 EXPECT_TRUE(observer()->get_changed_paths().count(file_in_subdir.DirName())); |
75 | |
76 EXPECT_EQ(2U, observer()->removed_local_ids().size()); | |
77 EXPECT_TRUE(observer()->removed_local_ids().count(id_file_in_root)); | |
78 EXPECT_TRUE(observer()->removed_local_ids().count(id_file_in_subdir)); | |
78 } | 79 } |
79 | 80 |
80 TEST_F(RemoveOperationTest, RemoveDirectory) { | 81 TEST_F(RemoveOperationTest, RemoveDirectory) { |
81 RemoveOperation operation(blocking_task_runner(), observer(), scheduler(), | 82 RemoveOperation operation(blocking_task_runner(), observer(), metadata(), |
82 metadata(), cache()); | 83 cache()); |
83 | 84 |
84 base::FilePath empty_dir(FILE_PATH_LITERAL( | 85 base::FilePath empty_dir(FILE_PATH_LITERAL( |
85 "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")); | 86 "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")); |
86 base::FilePath non_empty_dir(FILE_PATH_LITERAL( | 87 base::FilePath non_empty_dir(FILE_PATH_LITERAL( |
87 "drive/root/Directory 1")); | 88 "drive/root/Directory 1")); |
88 base::FilePath file_in_non_empty_dir(FILE_PATH_LITERAL( | 89 base::FilePath file_in_non_empty_dir(FILE_PATH_LITERAL( |
89 "drive/root/Directory 1/SubDirectory File 1.txt")); | 90 "drive/root/Directory 1/SubDirectory File 1.txt")); |
90 | 91 |
91 // Empty directory can be removed even with is_recursive = false. | 92 // Empty directory can be removed even with is_recursive = false. |
92 FileError error = FILE_ERROR_FAILED; | 93 FileError error = FILE_ERROR_FAILED; |
(...skipping 24 matching lines...) Expand all Loading... | |
117 GetLocalResourceEntry(file_in_non_empty_dir, &entry)); | 118 GetLocalResourceEntry(file_in_non_empty_dir, &entry)); |
118 operation.Remove(non_empty_dir, | 119 operation.Remove(non_empty_dir, |
119 true, // is_recursive | 120 true, // is_recursive |
120 google_apis::test_util::CreateCopyResultCallback(&error)); | 121 google_apis::test_util::CreateCopyResultCallback(&error)); |
121 test_util::RunBlockingPoolTask(); | 122 test_util::RunBlockingPoolTask(); |
122 EXPECT_EQ(FILE_ERROR_OK, error); | 123 EXPECT_EQ(FILE_ERROR_OK, error); |
123 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 124 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
124 GetLocalResourceEntry(non_empty_dir, &entry)); | 125 GetLocalResourceEntry(non_empty_dir, &entry)); |
125 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 126 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
126 GetLocalResourceEntry(file_in_non_empty_dir, &entry)); | 127 GetLocalResourceEntry(file_in_non_empty_dir, &entry)); |
127 } | 128 } |
kinaba
2013/11/12 06:21:29
Could you add a check for the recursive deleted ma
hashimoto
2013/11/25 10:13:58
Stopped marking entries as deleted.
| |
128 | 129 |
129 TEST_F(RemoveOperationTest, RemoveShared) { | |
130 RemoveOperation operation(blocking_task_runner(), observer(), scheduler(), | |
131 metadata(), cache()); | |
132 | |
133 const base::FilePath kPathInMyDrive(FILE_PATH_LITERAL( | |
134 "drive/root/shared.txt")); | |
135 const base::FilePath kPathInOther(FILE_PATH_LITERAL( | |
136 "drive/other/shared.txt")); | |
137 | |
138 // Prepare a shared file to the root folder. | |
139 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; | |
140 scoped_ptr<google_apis::ResourceEntry> gdata_entry; | |
141 fake_service()->AddNewFile( | |
142 "text/plain", | |
143 "dummy content", | |
144 fake_service()->GetRootResourceId(), | |
145 kPathInMyDrive.BaseName().AsUTF8Unsafe(), | |
146 true, // shared_with_me, | |
147 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | |
148 &gdata_entry)); | |
149 test_util::RunBlockingPoolTask(); | |
150 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); | |
151 CheckForUpdates(); | |
152 | |
153 // Remove it. Locally, the file should be moved to drive/other. | |
154 FileError error = FILE_ERROR_FAILED; | |
155 ResourceEntry entry; | |
156 operation.Remove(kPathInMyDrive, | |
157 false, // is_recursive | |
158 google_apis::test_util::CreateCopyResultCallback(&error)); | |
159 test_util::RunBlockingPoolTask(); | |
160 EXPECT_EQ(FILE_ERROR_OK, error); | |
161 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | |
162 GetLocalResourceEntry(kPathInMyDrive, &entry)); | |
163 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInOther, &entry)); | |
164 | |
165 // Remotely, the entry should have lost its parent. | |
166 gdata_error = google_apis::GDATA_OTHER_ERROR; | |
167 const std::string resource_id = gdata_entry->resource_id(); | |
168 fake_service()->GetResourceEntry( | |
169 resource_id, | |
170 google_apis::test_util::CreateCopyResultCallback(&gdata_error, | |
171 &gdata_entry)); | |
172 test_util::RunBlockingPoolTask(); | |
173 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error); | |
174 EXPECT_FALSE(gdata_entry->deleted()); // It's not deleted. | |
175 EXPECT_FALSE(gdata_entry->GetLinkByType(google_apis::Link::LINK_PARENT)); | |
176 } | |
177 | |
178 } // namespace file_system | 130 } // namespace file_system |
179 } // namespace drive | 131 } // namespace drive |
OLD | NEW |