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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/copy_operation_unittest.cc

Issue 408143014: Rename OperationObserver to OperationDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 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/copy_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/task_runner_util.h" 8 #include "base/task_runner_util.h"
9 #include "chrome/browser/chromeos/drive/file_cache.h" 9 #include "chrome/browser/chromeos/drive/file_cache.h"
10 #include "chrome/browser/chromeos/drive/file_change.h" 10 #include "chrome/browser/chromeos/drive/file_change.h"
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 35
36 } // namespace 36 } // namespace
37 37
38 class CopyOperationTest : public OperationTestBase { 38 class CopyOperationTest : public OperationTestBase {
39 protected: 39 protected:
40 virtual void SetUp() OVERRIDE { 40 virtual void SetUp() OVERRIDE {
41 OperationTestBase::SetUp(); 41 OperationTestBase::SetUp();
42 operation_.reset(new CopyOperation( 42 operation_.reset(new CopyOperation(
43 blocking_task_runner(), 43 blocking_task_runner(),
44 observer(), 44 delegate(),
45 scheduler(), 45 scheduler(),
46 metadata(), 46 metadata(),
47 cache(), 47 cache(),
48 util::GetIdentityResourceIdCanonicalizer())); 48 util::GetIdentityResourceIdCanonicalizer()));
49 } 49 }
50 50
51 scoped_ptr<CopyOperation> operation_; 51 scoped_ptr<CopyOperation> operation_;
52 }; 52 };
53 53
54 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_RegularFile) { 54 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_RegularFile) {
(...skipping 14 matching lines...) Expand all
69 operation_->TransferFileFromLocalToRemote( 69 operation_->TransferFileFromLocalToRemote(
70 local_src_path, 70 local_src_path,
71 remote_dest_path, 71 remote_dest_path,
72 google_apis::test_util::CreateCopyResultCallback(&error)); 72 google_apis::test_util::CreateCopyResultCallback(&error));
73 content::RunAllBlockingPoolTasksUntilIdle(); 73 content::RunAllBlockingPoolTasksUntilIdle();
74 EXPECT_EQ(FILE_ERROR_OK, error); 74 EXPECT_EQ(FILE_ERROR_OK, error);
75 75
76 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, 76 // TransferFileFromLocalToRemote stores a copy of the local file in the cache,
77 // marks it dirty and requests the observer to upload the file. 77 // marks it dirty and requests the observer to upload the file.
78 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); 78 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry));
79 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); 79 EXPECT_EQ(1U, delegate()->updated_local_ids().count(entry.local_id()));
80 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); 80 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present());
81 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); 81 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty());
82 82
83 EXPECT_EQ(1U, observer()->get_changed_files().size()); 83 EXPECT_EQ(1U, delegate()->get_changed_files().size());
84 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); 84 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path));
85 } 85 }
86 86
87 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_Overwrite) { 87 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_Overwrite) {
88 const base::FilePath local_src_path = temp_dir().AppendASCII("local.txt"); 88 const base::FilePath local_src_path = temp_dir().AppendASCII("local.txt");
89 const base::FilePath remote_dest_path( 89 const base::FilePath remote_dest_path(
90 FILE_PATH_LITERAL("drive/root/File 1.txt")); 90 FILE_PATH_LITERAL("drive/root/File 1.txt"));
91 91
92 // Prepare a local file. 92 // Prepare a local file.
93 EXPECT_TRUE( 93 EXPECT_TRUE(
94 google_apis::test_util::WriteStringToFile(local_src_path, "hello")); 94 google_apis::test_util::WriteStringToFile(local_src_path, "hello"));
95 // Confirm that the remote file exists. 95 // Confirm that the remote file exists.
96 ResourceEntry entry; 96 ResourceEntry entry;
97 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); 97 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry));
98 98
99 // Transfer the local file to Drive. 99 // Transfer the local file to Drive.
100 FileError error = FILE_ERROR_FAILED; 100 FileError error = FILE_ERROR_FAILED;
101 operation_->TransferFileFromLocalToRemote( 101 operation_->TransferFileFromLocalToRemote(
102 local_src_path, 102 local_src_path,
103 remote_dest_path, 103 remote_dest_path,
104 google_apis::test_util::CreateCopyResultCallback(&error)); 104 google_apis::test_util::CreateCopyResultCallback(&error));
105 content::RunAllBlockingPoolTasksUntilIdle(); 105 content::RunAllBlockingPoolTasksUntilIdle();
106 EXPECT_EQ(FILE_ERROR_OK, error); 106 EXPECT_EQ(FILE_ERROR_OK, error);
107 107
108 // TransferFileFromLocalToRemote stores a copy of the local file in the cache, 108 // TransferFileFromLocalToRemote stores a copy of the local file in the cache,
109 // marks it dirty and requests the observer to upload the file. 109 // marks it dirty and requests the observer to upload the file.
110 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); 110 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry));
111 EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id())); 111 EXPECT_EQ(1U, delegate()->updated_local_ids().count(entry.local_id()));
112 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present()); 112 EXPECT_TRUE(entry.file_specific_info().cache_state().is_present());
113 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); 113 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty());
114 114
115 EXPECT_EQ(1U, observer()->get_changed_files().size()); 115 EXPECT_EQ(1U, delegate()->get_changed_files().size());
116 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); 116 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path));
117 } 117 }
118 118
119 TEST_F(CopyOperationTest, 119 TEST_F(CopyOperationTest,
120 TransferFileFromLocalToRemote_ExistingHostedDocument) { 120 TransferFileFromLocalToRemote_ExistingHostedDocument) {
121 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); 121 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc");
122 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( 122 const base::FilePath remote_dest_path(FILE_PATH_LITERAL(
123 "drive/root/Directory 1/copied.gdoc")); 123 "drive/root/Directory 1/copied.gdoc"));
124 124
125 // Prepare a local file, which is a json file of a hosted document, which 125 // Prepare a local file, which is a json file of a hosted document, which
126 // matches "drive/root/Document 1 excludeDir-test". 126 // matches "drive/root/Document 1 excludeDir-test".
(...skipping 10 matching lines...) Expand all
137 FileError error = FILE_ERROR_FAILED; 137 FileError error = FILE_ERROR_FAILED;
138 operation_->TransferFileFromLocalToRemote( 138 operation_->TransferFileFromLocalToRemote(
139 local_src_path, 139 local_src_path,
140 remote_dest_path, 140 remote_dest_path,
141 google_apis::test_util::CreateCopyResultCallback(&error)); 141 google_apis::test_util::CreateCopyResultCallback(&error));
142 content::RunAllBlockingPoolTasksUntilIdle(); 142 content::RunAllBlockingPoolTasksUntilIdle();
143 EXPECT_EQ(FILE_ERROR_OK, error); 143 EXPECT_EQ(FILE_ERROR_OK, error);
144 144
145 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); 145 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry));
146 146
147 EXPECT_EQ(1U, observer()->get_changed_files().size()); 147 EXPECT_EQ(1U, delegate()->get_changed_files().size());
148 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); 148 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path));
149 // New copy is created. 149 // New copy is created.
150 EXPECT_NE("document:5_document_resource_id", entry.resource_id()); 150 EXPECT_NE("document:5_document_resource_id", entry.resource_id());
151 } 151 }
152 152
153 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_OrphanHostedDocument) { 153 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_OrphanHostedDocument) {
154 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); 154 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc");
155 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( 155 const base::FilePath remote_dest_path(FILE_PATH_LITERAL(
156 "drive/root/Directory 1/moved.gdoc")); 156 "drive/root/Directory 1/moved.gdoc"));
157 157
158 // Prepare a local file, which is a json file of a hosted document, which 158 // Prepare a local file, which is a json file of a hosted document, which
(...skipping 11 matching lines...) Expand all
170 FileError error = FILE_ERROR_FAILED; 170 FileError error = FILE_ERROR_FAILED;
171 operation_->TransferFileFromLocalToRemote( 171 operation_->TransferFileFromLocalToRemote(
172 local_src_path, 172 local_src_path,
173 remote_dest_path, 173 remote_dest_path,
174 google_apis::test_util::CreateCopyResultCallback(&error)); 174 google_apis::test_util::CreateCopyResultCallback(&error));
175 content::RunAllBlockingPoolTasksUntilIdle(); 175 content::RunAllBlockingPoolTasksUntilIdle();
176 EXPECT_EQ(FILE_ERROR_OK, error); 176 EXPECT_EQ(FILE_ERROR_OK, error);
177 177
178 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); 178 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry));
179 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); 179 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state());
180 EXPECT_TRUE(observer()->updated_local_ids().count(entry.local_id())); 180 EXPECT_TRUE(delegate()->updated_local_ids().count(entry.local_id()));
181 181
182 EXPECT_EQ(1U, observer()->get_changed_files().size()); 182 EXPECT_EQ(1U, delegate()->get_changed_files().size());
183 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); 183 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path));
184 // The original document got new parent. 184 // The original document got new parent.
185 EXPECT_EQ("document:orphan_doc_1", entry.resource_id()); 185 EXPECT_EQ("document:orphan_doc_1", entry.resource_id());
186 } 186 }
187 187
188 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_NewHostedDocument) { 188 TEST_F(CopyOperationTest, TransferFileFromLocalToRemote_NewHostedDocument) {
189 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc"); 189 const base::FilePath local_src_path = temp_dir().AppendASCII("local.gdoc");
190 const base::FilePath remote_dest_path(FILE_PATH_LITERAL( 190 const base::FilePath remote_dest_path(FILE_PATH_LITERAL(
191 "drive/root/Directory 1/moved.gdoc")); 191 "drive/root/Directory 1/moved.gdoc"));
192 192
193 // Create a hosted document on the server that is not synced to local yet. 193 // Create a hosted document on the server that is not synced to local yet.
(...skipping 20 matching lines...) Expand all
214 FileError error = FILE_ERROR_FAILED; 214 FileError error = FILE_ERROR_FAILED;
215 operation_->TransferFileFromLocalToRemote( 215 operation_->TransferFileFromLocalToRemote(
216 local_src_path, 216 local_src_path,
217 remote_dest_path, 217 remote_dest_path,
218 google_apis::test_util::CreateCopyResultCallback(&error)); 218 google_apis::test_util::CreateCopyResultCallback(&error));
219 content::RunAllBlockingPoolTasksUntilIdle(); 219 content::RunAllBlockingPoolTasksUntilIdle();
220 EXPECT_EQ(FILE_ERROR_OK, error); 220 EXPECT_EQ(FILE_ERROR_OK, error);
221 221
222 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry)); 222 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(remote_dest_path, &entry));
223 223
224 EXPECT_EQ(1U, observer()->get_changed_files().size()); 224 EXPECT_EQ(1U, delegate()->get_changed_files().size());
225 EXPECT_TRUE(observer()->get_changed_files().count(remote_dest_path)); 225 EXPECT_TRUE(delegate()->get_changed_files().count(remote_dest_path));
226 // The original document got new parent. 226 // The original document got new parent.
227 EXPECT_EQ(new_gdoc_entry->file_id(), entry.resource_id()); 227 EXPECT_EQ(new_gdoc_entry->file_id(), entry.resource_id());
228 } 228 }
229 229
230 TEST_F(CopyOperationTest, CopyNotExistingFile) { 230 TEST_F(CopyOperationTest, CopyNotExistingFile) {
231 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); 231 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
232 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log")); 232 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Test.log"));
233 233
234 ResourceEntry entry; 234 ResourceEntry entry;
235 ASSERT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); 235 ASSERT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry));
236 236
237 FileError error = FILE_ERROR_OK; 237 FileError error = FILE_ERROR_OK;
238 operation_->Copy(src_path, 238 operation_->Copy(src_path,
239 dest_path, 239 dest_path,
240 false, 240 false,
241 google_apis::test_util::CreateCopyResultCallback(&error)); 241 google_apis::test_util::CreateCopyResultCallback(&error));
242 content::RunAllBlockingPoolTasksUntilIdle(); 242 content::RunAllBlockingPoolTasksUntilIdle();
243 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); 243 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
244 244
245 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry)); 245 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(src_path, &entry));
246 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); 246 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry));
247 EXPECT_TRUE(observer()->get_changed_files().empty()); 247 EXPECT_TRUE(delegate()->get_changed_files().empty());
248 } 248 }
249 249
250 TEST_F(CopyOperationTest, CopyFileToNonExistingDirectory) { 250 TEST_F(CopyOperationTest, CopyFileToNonExistingDirectory) {
251 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 251 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
252 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); 252 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log"));
253 253
254 ResourceEntry entry; 254 ResourceEntry entry;
255 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); 255 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry));
256 ASSERT_EQ(FILE_ERROR_NOT_FOUND, 256 ASSERT_EQ(FILE_ERROR_NOT_FOUND,
257 GetLocalResourceEntry(dest_path.DirName(), &entry)); 257 GetLocalResourceEntry(dest_path.DirName(), &entry));
258 258
259 FileError error = FILE_ERROR_OK; 259 FileError error = FILE_ERROR_OK;
260 operation_->Copy(src_path, 260 operation_->Copy(src_path,
261 dest_path, 261 dest_path,
262 false, 262 false,
263 google_apis::test_util::CreateCopyResultCallback(&error)); 263 google_apis::test_util::CreateCopyResultCallback(&error));
264 content::RunAllBlockingPoolTasksUntilIdle(); 264 content::RunAllBlockingPoolTasksUntilIdle();
265 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); 265 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
266 266
267 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); 267 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry));
268 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); 268 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry));
269 EXPECT_TRUE(observer()->get_changed_files().empty()); 269 EXPECT_TRUE(delegate()->get_changed_files().empty());
270 } 270 }
271 271
272 // Test the case where the parent of the destination path is an existing file, 272 // Test the case where the parent of the destination path is an existing file,
273 // not a directory. 273 // not a directory.
274 TEST_F(CopyOperationTest, CopyFileToInvalidPath) { 274 TEST_F(CopyOperationTest, CopyFileToInvalidPath) {
275 base::FilePath src_path(FILE_PATH_LITERAL( 275 base::FilePath src_path(FILE_PATH_LITERAL(
276 "drive/root/Document 1 excludeDir-test.gdoc")); 276 "drive/root/Document 1 excludeDir-test.gdoc"));
277 base::FilePath dest_path(FILE_PATH_LITERAL( 277 base::FilePath dest_path(FILE_PATH_LITERAL(
278 "drive/root/Duplicate Name.txt/Document 1 excludeDir-test.gdoc")); 278 "drive/root/Duplicate Name.txt/Document 1 excludeDir-test.gdoc"));
279 279
280 ResourceEntry entry; 280 ResourceEntry entry;
281 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); 281 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry));
282 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path.DirName(), &entry)); 282 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path.DirName(), &entry));
283 ASSERT_FALSE(entry.file_info().is_directory()); 283 ASSERT_FALSE(entry.file_info().is_directory());
284 284
285 FileError error = FILE_ERROR_OK; 285 FileError error = FILE_ERROR_OK;
286 operation_->Copy(src_path, 286 operation_->Copy(src_path,
287 dest_path, 287 dest_path,
288 false, 288 false,
289 google_apis::test_util::CreateCopyResultCallback(&error)); 289 google_apis::test_util::CreateCopyResultCallback(&error));
290 content::RunAllBlockingPoolTasksUntilIdle(); 290 content::RunAllBlockingPoolTasksUntilIdle();
291 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); 291 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
292 292
293 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry)); 293 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &entry));
294 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry)); 294 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(dest_path, &entry));
295 EXPECT_TRUE(observer()->get_changed_files().empty()); 295 EXPECT_TRUE(delegate()->get_changed_files().empty());
296 } 296 }
297 297
298 TEST_F(CopyOperationTest, CopyDirtyFile) { 298 TEST_F(CopyOperationTest, CopyDirtyFile) {
299 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 299 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
300 base::FilePath dest_path(FILE_PATH_LITERAL( 300 base::FilePath dest_path(FILE_PATH_LITERAL(
301 "drive/root/Directory 1/New File.txt")); 301 "drive/root/Directory 1/New File.txt"));
302 302
303 ResourceEntry src_entry; 303 ResourceEntry src_entry;
304 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry)); 304 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry));
305 305
(...skipping 21 matching lines...) Expand all
327 dest_path, 327 dest_path,
328 false, 328 false,
329 google_apis::test_util::CreateCopyResultCallback(&error)); 329 google_apis::test_util::CreateCopyResultCallback(&error));
330 content::RunAllBlockingPoolTasksUntilIdle(); 330 content::RunAllBlockingPoolTasksUntilIdle();
331 EXPECT_EQ(FILE_ERROR_OK, error); 331 EXPECT_EQ(FILE_ERROR_OK, error);
332 332
333 ResourceEntry dest_entry; 333 ResourceEntry dest_entry;
334 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry)); 334 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &dest_entry));
335 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state()); 335 EXPECT_EQ(ResourceEntry::DIRTY, dest_entry.metadata_edit_state());
336 336
337 EXPECT_EQ(1u, observer()->updated_local_ids().size()); 337 EXPECT_EQ(1u, delegate()->updated_local_ids().size());
338 EXPECT_TRUE(observer()->updated_local_ids().count(dest_entry.local_id())); 338 EXPECT_TRUE(delegate()->updated_local_ids().count(dest_entry.local_id()));
339 EXPECT_EQ(1u, observer()->get_changed_files().size()); 339 EXPECT_EQ(1u, delegate()->get_changed_files().size());
340 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); 340 EXPECT_TRUE(delegate()->get_changed_files().count(dest_path));
341 341
342 // Copied cache file should be dirty. 342 // Copied cache file should be dirty.
343 EXPECT_TRUE(dest_entry.file_specific_info().cache_state().is_dirty()); 343 EXPECT_TRUE(dest_entry.file_specific_info().cache_state().is_dirty());
344 344
345 // File contents should match. 345 // File contents should match.
346 base::FilePath cache_file_path; 346 base::FilePath cache_file_path;
347 base::PostTaskAndReplyWithResult( 347 base::PostTaskAndReplyWithResult(
348 blocking_task_runner(), 348 blocking_task_runner(),
349 FROM_HERE, 349 FROM_HERE,
350 base::Bind(&internal::FileCache::GetFile, 350 base::Bind(&internal::FileCache::GetFile,
(...skipping 21 matching lines...) Expand all
372 operation_->Copy(src_path, 372 operation_->Copy(src_path,
373 dest_path, 373 dest_path,
374 false, 374 false,
375 google_apis::test_util::CreateCopyResultCallback(&error)); 375 google_apis::test_util::CreateCopyResultCallback(&error));
376 content::RunAllBlockingPoolTasksUntilIdle(); 376 content::RunAllBlockingPoolTasksUntilIdle();
377 EXPECT_EQ(FILE_ERROR_OK, error); 377 EXPECT_EQ(FILE_ERROR_OK, error);
378 378
379 ResourceEntry new_dest_entry; 379 ResourceEntry new_dest_entry;
380 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &new_dest_entry)); 380 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &new_dest_entry));
381 381
382 EXPECT_EQ(1u, observer()->updated_local_ids().size()); 382 EXPECT_EQ(1u, delegate()->updated_local_ids().size());
383 EXPECT_TRUE(observer()->updated_local_ids().count(old_dest_entry.local_id())); 383 EXPECT_TRUE(delegate()->updated_local_ids().count(old_dest_entry.local_id()));
384 EXPECT_EQ(1u, observer()->get_changed_files().size()); 384 EXPECT_EQ(1u, delegate()->get_changed_files().size());
385 EXPECT_TRUE(observer()->get_changed_files().count(dest_path)); 385 EXPECT_TRUE(delegate()->get_changed_files().count(dest_path));
386 } 386 }
387 387
388 TEST_F(CopyOperationTest, CopyFileOverwriteDirectory) { 388 TEST_F(CopyOperationTest, CopyFileOverwriteDirectory) {
389 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 389 base::FilePath src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
390 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Directory 1")); 390 base::FilePath dest_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
391 391
392 FileError error = FILE_ERROR_OK; 392 FileError error = FILE_ERROR_OK;
393 operation_->Copy(src_path, 393 operation_->Copy(src_path,
394 dest_path, 394 dest_path,
395 false, 395 false,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 base::Bind(&internal::ResourceMetadata::AddEntry, 465 base::Bind(&internal::ResourceMetadata::AddEntry,
466 base::Unretained(metadata()), directory, &directory_local_id), 466 base::Unretained(metadata()), directory, &directory_local_id),
467 google_apis::test_util::CreateCopyResultCallback(&error)); 467 google_apis::test_util::CreateCopyResultCallback(&error));
468 content::RunAllBlockingPoolTasksUntilIdle(); 468 content::RunAllBlockingPoolTasksUntilIdle();
469 EXPECT_EQ(FILE_ERROR_OK, error); 469 EXPECT_EQ(FILE_ERROR_OK, error);
470 470
471 // Try to copy a file to the new directory which lacks resource ID. 471 // Try to copy a file to the new directory which lacks resource ID.
472 // This should result in waiting for the directory to sync. 472 // This should result in waiting for the directory to sync.
473 std::string waited_local_id; 473 std::string waited_local_id;
474 FileOperationCallback pending_callback; 474 FileOperationCallback pending_callback;
475 observer()->set_wait_for_sync_complete_handler( 475 delegate()->set_wait_for_sync_complete_handler(
476 base::Bind(&CopyWaitForSyncCompleteArguments, 476 base::Bind(&CopyWaitForSyncCompleteArguments,
477 &waited_local_id, &pending_callback)); 477 &waited_local_id, &pending_callback));
478 478
479 FileError copy_error = FILE_ERROR_FAILED; 479 FileError copy_error = FILE_ERROR_FAILED;
480 operation_->Copy(src_path, 480 operation_->Copy(src_path,
481 dest_path, 481 dest_path,
482 true, // Preserve last modified. 482 true, // Preserve last modified.
483 google_apis::test_util::CreateCopyResultCallback( 483 google_apis::test_util::CreateCopyResultCallback(
484 &copy_error)); 484 &copy_error));
485 content::RunAllBlockingPoolTasksUntilIdle(); 485 content::RunAllBlockingPoolTasksUntilIdle();
(...skipping 28 matching lines...) Expand all
514 pending_callback.Run(FILE_ERROR_OK); 514 pending_callback.Run(FILE_ERROR_OK);
515 content::RunAllBlockingPoolTasksUntilIdle(); 515 content::RunAllBlockingPoolTasksUntilIdle();
516 516
517 EXPECT_EQ(FILE_ERROR_OK, copy_error); 517 EXPECT_EQ(FILE_ERROR_OK, copy_error);
518 ResourceEntry entry; 518 ResourceEntry entry;
519 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry)); 519 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(dest_path, &entry));
520 } 520 }
521 521
522 } // namespace file_system 522 } // namespace file_system
523 } // namespace drive 523 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698