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

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_change_tracker_unittest.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 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/sync_file_system/local/local_file_change_tracker.h" 5 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 base::MessageLoopForIO message_loop_; 108 base::MessageLoopForIO message_loop_;
109 CannedSyncableFileSystem file_system_; 109 CannedSyncableFileSystem file_system_;
110 110
111 private: 111 private:
112 scoped_refptr<LocalFileSyncContext> sync_context_; 112 scoped_refptr<LocalFileSyncContext> sync_context_;
113 113
114 DISALLOW_COPY_AND_ASSIGN(LocalFileChangeTrackerTest); 114 DISALLOW_COPY_AND_ASSIGN(LocalFileChangeTrackerTest);
115 }; 115 };
116 116
117 TEST_F(LocalFileChangeTrackerTest, GetChanges) { 117 TEST_F(LocalFileChangeTrackerTest, GetChanges) {
118 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); 118 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
119 119
120 // Test URLs (no parent/child relationships, as we test such cases 120 // Test URLs (no parent/child relationships, as we test such cases
121 // mainly in LocalFileSyncStatusTest). 121 // mainly in LocalFileSyncStatusTest).
122 const char kPath0[] = "test/dir a/dir"; 122 const char kPath0[] = "test/dir a/dir";
123 const char kPath1[] = "test/dir b"; 123 const char kPath1[] = "test/dir b";
124 const char kPath2[] = "test/foo.txt"; 124 const char kPath2[] = "test/foo.txt";
125 const char kPath3[] = "test/bar"; 125 const char kPath3[] = "test/bar";
126 const char kPath4[] = "temporary/dir a"; 126 const char kPath4[] = "temporary/dir a";
127 const char kPath5[] = "temporary/foo"; 127 const char kPath5[] = "temporary/foo";
128 128
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 sync_file_system::SYNC_FILE_TYPE_FILE)); 223 sync_file_system::SYNC_FILE_TYPE_FILE));
224 VerifyAndClearChange(URL(kPath4), 224 VerifyAndClearChange(URL(kPath4),
225 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 225 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
226 sync_file_system::SYNC_FILE_TYPE_FILE)); 226 sync_file_system::SYNC_FILE_TYPE_FILE));
227 VerifyAndClearChange(URL(kPath5), 227 VerifyAndClearChange(URL(kPath5),
228 FileChange(FileChange::FILE_CHANGE_DELETE, 228 FileChange(FileChange::FILE_CHANGE_DELETE,
229 sync_file_system::SYNC_FILE_TYPE_FILE)); 229 sync_file_system::SYNC_FILE_TYPE_FILE));
230 } 230 }
231 231
232 TEST_F(LocalFileChangeTrackerTest, RestoreCreateAndModifyChanges) { 232 TEST_F(LocalFileChangeTrackerTest, RestoreCreateAndModifyChanges) {
233 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); 233 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
234 234
235 FileSystemURLSet urls; 235 FileSystemURLSet urls;
236 236
237 const char kPath0[] = "file a"; 237 const char kPath0[] = "file a";
238 const char kPath1[] = "dir a"; 238 const char kPath1[] = "dir a";
239 const char kPath2[] = "dir a/dir"; 239 const char kPath2[] = "dir a/dir";
240 const char kPath3[] = "dir a/file a"; 240 const char kPath3[] = "dir a/file a";
241 const char kPath4[] = "dir a/file b"; 241 const char kPath4[] = "dir a/file b";
242 242
243 file_system_.GetChangedURLsInTracker(&urls); 243 file_system_.GetChangedURLsInTracker(&urls);
244 ASSERT_EQ(0U, urls.size()); 244 ASSERT_EQ(0U, urls.size());
245 245
246 const std::string kData("Lorem ipsum."); 246 const std::string kData("Lorem ipsum.");
247 MockBlobURLRequestContext url_request_context(file_system_context()); 247 MockBlobURLRequestContext url_request_context(file_system_context());
248 ScopedTextBlob blob(url_request_context, "blob_id:test", kData); 248 ScopedTextBlob blob(url_request_context, "blob_id:test", kData);
249 249
250 // Create files and nested directories. 250 // Create files and nested directories.
251 EXPECT_EQ(base::PLATFORM_FILE_OK, 251 EXPECT_EQ(base::File::FILE_OK,
252 file_system_.CreateFile(URL(kPath0))); // Creates a file. 252 file_system_.CreateFile(URL(kPath0))); // Creates a file.
253 EXPECT_EQ(base::PLATFORM_FILE_OK, 253 EXPECT_EQ(base::File::FILE_OK,
254 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. 254 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir.
255 EXPECT_EQ(base::PLATFORM_FILE_OK, 255 EXPECT_EQ(base::File::FILE_OK,
256 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. 256 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir.
257 EXPECT_EQ(base::PLATFORM_FILE_OK, 257 EXPECT_EQ(base::File::FILE_OK,
258 file_system_.CreateFile(URL(kPath3))); // Creates a file. 258 file_system_.CreateFile(URL(kPath3))); // Creates a file.
259 EXPECT_EQ(base::PLATFORM_FILE_OK, 259 EXPECT_EQ(base::File::FILE_OK,
260 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. 260 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file.
261 EXPECT_EQ(base::PLATFORM_FILE_OK, 261 EXPECT_EQ(base::File::FILE_OK,
262 file_system_.CreateFile(URL(kPath4))); // Creates another file. 262 file_system_.CreateFile(URL(kPath4))); // Creates another file.
263 EXPECT_EQ(static_cast<int64>(kData.size()), // Modifies the file. 263 EXPECT_EQ(static_cast<int64>(kData.size()), // Modifies the file.
264 file_system_.Write(&url_request_context, 264 file_system_.Write(&url_request_context,
265 URL(kPath4), blob.GetBlobDataHandle())); 265 URL(kPath4), blob.GetBlobDataHandle()));
266 266
267 // Verify the changes. 267 // Verify the changes.
268 file_system_.GetChangedURLsInTracker(&urls); 268 file_system_.GetChangedURLsInTracker(&urls);
269 EXPECT_EQ(5U, urls.size()); 269 EXPECT_EQ(5U, urls.size());
270 270
271 // Reset the changes in in-memory tracker. 271 // Reset the changes in in-memory tracker.
(...skipping 20 matching lines...) Expand all
292 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); 292 sync_file_system::SYNC_FILE_TYPE_DIRECTORY));
293 VerifyAndClearChange(URL(kPath3), 293 VerifyAndClearChange(URL(kPath3),
294 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 294 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
295 sync_file_system::SYNC_FILE_TYPE_FILE)); 295 sync_file_system::SYNC_FILE_TYPE_FILE));
296 VerifyAndClearChange(URL(kPath4), 296 VerifyAndClearChange(URL(kPath4),
297 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 297 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
298 sync_file_system::SYNC_FILE_TYPE_FILE)); 298 sync_file_system::SYNC_FILE_TYPE_FILE));
299 } 299 }
300 300
301 TEST_F(LocalFileChangeTrackerTest, RestoreRemoveChanges) { 301 TEST_F(LocalFileChangeTrackerTest, RestoreRemoveChanges) {
302 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); 302 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
303 303
304 FileSystemURLSet urls; 304 FileSystemURLSet urls;
305 305
306 const char kPath0[] = "file"; 306 const char kPath0[] = "file";
307 const char kPath1[] = "dir a"; 307 const char kPath1[] = "dir a";
308 const char kPath2[] = "dir b"; 308 const char kPath2[] = "dir b";
309 const char kPath3[] = "dir b/file"; 309 const char kPath3[] = "dir b/file";
310 const char kPath4[] = "dir b/dir c"; 310 const char kPath4[] = "dir b/dir c";
311 const char kPath5[] = "dir b/dir c/file"; 311 const char kPath5[] = "dir b/dir c/file";
312 312
313 file_system_.GetChangedURLsInTracker(&urls); 313 file_system_.GetChangedURLsInTracker(&urls);
314 ASSERT_EQ(0U, urls.size()); 314 ASSERT_EQ(0U, urls.size());
315 315
316 // Creates and removes a same file. 316 // Creates and removes a same file.
317 EXPECT_EQ(base::PLATFORM_FILE_OK, 317 EXPECT_EQ(base::File::FILE_OK,
318 file_system_.CreateFile(URL(kPath0))); 318 file_system_.CreateFile(URL(kPath0)));
319 EXPECT_EQ(base::PLATFORM_FILE_OK, 319 EXPECT_EQ(base::File::FILE_OK,
320 file_system_.Remove(URL(kPath0), false /* recursive */)); 320 file_system_.Remove(URL(kPath0), false /* recursive */));
321 321
322 // Creates and removes a same directory. 322 // Creates and removes a same directory.
323 EXPECT_EQ(base::PLATFORM_FILE_OK, 323 EXPECT_EQ(base::File::FILE_OK,
324 file_system_.CreateDirectory(URL(kPath1))); 324 file_system_.CreateDirectory(URL(kPath1)));
325 EXPECT_EQ(base::PLATFORM_FILE_OK, 325 EXPECT_EQ(base::File::FILE_OK,
326 file_system_.Remove(URL(kPath1), false /* recursive */)); 326 file_system_.Remove(URL(kPath1), false /* recursive */));
327 327
328 // Creates files and nested directories, then removes the parent directory. 328 // Creates files and nested directories, then removes the parent directory.
329 EXPECT_EQ(base::PLATFORM_FILE_OK, 329 EXPECT_EQ(base::File::FILE_OK,
330 file_system_.CreateDirectory(URL(kPath2))); 330 file_system_.CreateDirectory(URL(kPath2)));
331 EXPECT_EQ(base::PLATFORM_FILE_OK, 331 EXPECT_EQ(base::File::FILE_OK,
332 file_system_.CreateFile(URL(kPath3))); 332 file_system_.CreateFile(URL(kPath3)));
333 EXPECT_EQ(base::PLATFORM_FILE_OK, 333 EXPECT_EQ(base::File::FILE_OK,
334 file_system_.CreateDirectory(URL(kPath4))); 334 file_system_.CreateDirectory(URL(kPath4)));
335 EXPECT_EQ(base::PLATFORM_FILE_OK, 335 EXPECT_EQ(base::File::FILE_OK,
336 file_system_.CreateFile(URL(kPath5))); 336 file_system_.CreateFile(URL(kPath5)));
337 EXPECT_EQ(base::PLATFORM_FILE_OK, 337 EXPECT_EQ(base::File::FILE_OK,
338 file_system_.Remove(URL(kPath2), true /* recursive */)); 338 file_system_.Remove(URL(kPath2), true /* recursive */));
339 339
340 file_system_.GetChangedURLsInTracker(&urls); 340 file_system_.GetChangedURLsInTracker(&urls);
341 EXPECT_EQ(3U, urls.size()); 341 EXPECT_EQ(3U, urls.size());
342 342
343 DropChangesInTracker(); 343 DropChangesInTracker();
344 344
345 // Make sure we have no in-memory changes in the tracker. 345 // Make sure we have no in-memory changes in the tracker.
346 file_system_.GetChangedURLsInTracker(&urls); 346 file_system_.GetChangedURLsInTracker(&urls);
347 ASSERT_EQ(0U, urls.size()); 347 ASSERT_EQ(0U, urls.size());
(...skipping 20 matching lines...) Expand all
368 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); 368 sync_file_system::SYNC_FILE_TYPE_UNKNOWN));
369 VerifyAndClearChange(URL(kPath4), 369 VerifyAndClearChange(URL(kPath4),
370 FileChange(FileChange::FILE_CHANGE_DELETE, 370 FileChange(FileChange::FILE_CHANGE_DELETE,
371 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); 371 sync_file_system::SYNC_FILE_TYPE_UNKNOWN));
372 VerifyAndClearChange(URL(kPath5), 372 VerifyAndClearChange(URL(kPath5),
373 FileChange(FileChange::FILE_CHANGE_DELETE, 373 FileChange(FileChange::FILE_CHANGE_DELETE,
374 sync_file_system::SYNC_FILE_TYPE_UNKNOWN)); 374 sync_file_system::SYNC_FILE_TYPE_UNKNOWN));
375 } 375 }
376 376
377 TEST_F(LocalFileChangeTrackerTest, RestoreCopyChanges) { 377 TEST_F(LocalFileChangeTrackerTest, RestoreCopyChanges) {
378 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); 378 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
379 379
380 FileSystemURLSet urls; 380 FileSystemURLSet urls;
381 381
382 const char kPath0[] = "file a"; 382 const char kPath0[] = "file a";
383 const char kPath1[] = "dir a"; 383 const char kPath1[] = "dir a";
384 const char kPath2[] = "dir a/dir"; 384 const char kPath2[] = "dir a/dir";
385 const char kPath3[] = "dir a/file a"; 385 const char kPath3[] = "dir a/file a";
386 const char kPath4[] = "dir a/file b"; 386 const char kPath4[] = "dir a/file b";
387 387
388 const char kPath0Copy[] = "file b"; // To be copied from kPath0 388 const char kPath0Copy[] = "file b"; // To be copied from kPath0
389 const char kPath1Copy[] = "dir b"; // To be copied from kPath1 389 const char kPath1Copy[] = "dir b"; // To be copied from kPath1
390 const char kPath2Copy[] = "dir b/dir"; // To be copied from kPath2 390 const char kPath2Copy[] = "dir b/dir"; // To be copied from kPath2
391 const char kPath3Copy[] = "dir b/file a"; // To be copied from kPath3 391 const char kPath3Copy[] = "dir b/file a"; // To be copied from kPath3
392 const char kPath4Copy[] = "dir b/file b"; // To be copied from kPath4 392 const char kPath4Copy[] = "dir b/file b"; // To be copied from kPath4
393 393
394 file_system_.GetChangedURLsInTracker(&urls); 394 file_system_.GetChangedURLsInTracker(&urls);
395 ASSERT_EQ(0U, urls.size()); 395 ASSERT_EQ(0U, urls.size());
396 396
397 const std::string kData("Lorem ipsum."); 397 const std::string kData("Lorem ipsum.");
398 MockBlobURLRequestContext url_request_context(file_system_context()); 398 MockBlobURLRequestContext url_request_context(file_system_context());
399 ScopedTextBlob blob(url_request_context, "blob_id:test", kData); 399 ScopedTextBlob blob(url_request_context, "blob_id:test", kData);
400 400
401 // Create files and nested directories. 401 // Create files and nested directories.
402 EXPECT_EQ(base::PLATFORM_FILE_OK, 402 EXPECT_EQ(base::File::FILE_OK,
403 file_system_.CreateFile(URL(kPath0))); // Creates a file. 403 file_system_.CreateFile(URL(kPath0))); // Creates a file.
404 EXPECT_EQ(base::PLATFORM_FILE_OK, 404 EXPECT_EQ(base::File::FILE_OK,
405 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir. 405 file_system_.CreateDirectory(URL(kPath1))); // Creates a dir.
406 EXPECT_EQ(base::PLATFORM_FILE_OK, 406 EXPECT_EQ(base::File::FILE_OK,
407 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir. 407 file_system_.CreateDirectory(URL(kPath2))); // Creates another dir.
408 EXPECT_EQ(base::PLATFORM_FILE_OK, 408 EXPECT_EQ(base::File::FILE_OK,
409 file_system_.CreateFile(URL(kPath3))); // Creates a file. 409 file_system_.CreateFile(URL(kPath3))); // Creates a file.
410 EXPECT_EQ(base::PLATFORM_FILE_OK, 410 EXPECT_EQ(base::File::FILE_OK,
411 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file. 411 file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file.
412 EXPECT_EQ(base::PLATFORM_FILE_OK, 412 EXPECT_EQ(base::File::FILE_OK,
413 file_system_.CreateFile(URL(kPath4))); // Creates another file. 413 file_system_.CreateFile(URL(kPath4))); // Creates another file.
414 EXPECT_EQ(static_cast<int64>(kData.size()), 414 EXPECT_EQ(static_cast<int64>(kData.size()),
415 file_system_.Write(&url_request_context, // Modifies the file. 415 file_system_.Write(&url_request_context, // Modifies the file.
416 URL(kPath4), blob.GetBlobDataHandle())); 416 URL(kPath4), blob.GetBlobDataHandle()));
417 417
418 // Verify we have 5 changes for preparation. 418 // Verify we have 5 changes for preparation.
419 file_system_.GetChangedURLsInTracker(&urls); 419 file_system_.GetChangedURLsInTracker(&urls);
420 EXPECT_EQ(5U, urls.size()); 420 EXPECT_EQ(5U, urls.size());
421 change_tracker()->ClearChangesForURL(URL(kPath0)); 421 change_tracker()->ClearChangesForURL(URL(kPath0));
422 change_tracker()->ClearChangesForURL(URL(kPath1)); 422 change_tracker()->ClearChangesForURL(URL(kPath1));
423 change_tracker()->ClearChangesForURL(URL(kPath2)); 423 change_tracker()->ClearChangesForURL(URL(kPath2));
424 change_tracker()->ClearChangesForURL(URL(kPath3)); 424 change_tracker()->ClearChangesForURL(URL(kPath3));
425 change_tracker()->ClearChangesForURL(URL(kPath4)); 425 change_tracker()->ClearChangesForURL(URL(kPath4));
426 426
427 // Make sure we have no changes. 427 // Make sure we have no changes.
428 file_system_.GetChangedURLsInTracker(&urls); 428 file_system_.GetChangedURLsInTracker(&urls);
429 EXPECT_TRUE(urls.empty()); 429 EXPECT_TRUE(urls.empty());
430 430
431 // Copy the file and the parent directory. 431 // Copy the file and the parent directory.
432 EXPECT_EQ(base::PLATFORM_FILE_OK, 432 EXPECT_EQ(base::File::FILE_OK,
433 file_system_.Copy(URL(kPath0), URL(kPath0Copy))); // Copy the file. 433 file_system_.Copy(URL(kPath0), URL(kPath0Copy))); // Copy the file.
434 EXPECT_EQ(base::PLATFORM_FILE_OK, 434 EXPECT_EQ(base::File::FILE_OK,
435 file_system_.Copy(URL(kPath1), URL(kPath1Copy))); // Copy the dir. 435 file_system_.Copy(URL(kPath1), URL(kPath1Copy))); // Copy the dir.
436 436
437 file_system_.GetChangedURLsInTracker(&urls); 437 file_system_.GetChangedURLsInTracker(&urls);
438 EXPECT_EQ(5U, urls.size()); 438 EXPECT_EQ(5U, urls.size());
439 DropChangesInTracker(); 439 DropChangesInTracker();
440 440
441 // Make sure we have no in-memory changes in the tracker. 441 // Make sure we have no in-memory changes in the tracker.
442 file_system_.GetChangedURLsInTracker(&urls); 442 file_system_.GetChangedURLsInTracker(&urls);
443 ASSERT_EQ(0U, urls.size()); 443 ASSERT_EQ(0U, urls.size());
444 444
(...skipping 14 matching lines...) Expand all
459 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); 459 sync_file_system::SYNC_FILE_TYPE_DIRECTORY));
460 VerifyAndClearChange(URL(kPath3Copy), 460 VerifyAndClearChange(URL(kPath3Copy),
461 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 461 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
462 sync_file_system::SYNC_FILE_TYPE_FILE)); 462 sync_file_system::SYNC_FILE_TYPE_FILE));
463 VerifyAndClearChange(URL(kPath4Copy), 463 VerifyAndClearChange(URL(kPath4Copy),
464 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 464 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
465 sync_file_system::SYNC_FILE_TYPE_FILE)); 465 sync_file_system::SYNC_FILE_TYPE_FILE));
466 } 466 }
467 467
468 TEST_F(LocalFileChangeTrackerTest, RestoreMoveChanges) { 468 TEST_F(LocalFileChangeTrackerTest, RestoreMoveChanges) {
469 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); 469 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
470 470
471 FileSystemURLSet urls; 471 FileSystemURLSet urls;
472 472
473 const char kPath0[] = "file a"; 473 const char kPath0[] = "file a";
474 const char kPath1[] = "dir a"; 474 const char kPath1[] = "dir a";
475 const char kPath2[] = "dir a/file"; 475 const char kPath2[] = "dir a/file";
476 const char kPath3[] = "dir a/dir"; 476 const char kPath3[] = "dir a/dir";
477 const char kPath4[] = "dir a/dir/file"; 477 const char kPath4[] = "dir a/dir/file";
478 478
479 const char kPath5[] = "file b"; // To be moved from kPath0. 479 const char kPath5[] = "file b"; // To be moved from kPath0.
480 const char kPath6[] = "dir b"; // To be moved from kPath1. 480 const char kPath6[] = "dir b"; // To be moved from kPath1.
481 const char kPath7[] = "dir b/file"; // To be moved from kPath2. 481 const char kPath7[] = "dir b/file"; // To be moved from kPath2.
482 const char kPath8[] = "dir b/dir"; // To be moved from kPath3. 482 const char kPath8[] = "dir b/dir"; // To be moved from kPath3.
483 const char kPath9[] = "dir b/dir/file"; // To be moved from kPath4. 483 const char kPath9[] = "dir b/dir/file"; // To be moved from kPath4.
484 484
485 file_system_.GetChangedURLsInTracker(&urls); 485 file_system_.GetChangedURLsInTracker(&urls);
486 ASSERT_EQ(0U, urls.size()); 486 ASSERT_EQ(0U, urls.size());
487 487
488 // Create files and nested directories. 488 // Create files and nested directories.
489 EXPECT_EQ(base::PLATFORM_FILE_OK, 489 EXPECT_EQ(base::File::FILE_OK,
490 file_system_.CreateFile(URL(kPath0))); 490 file_system_.CreateFile(URL(kPath0)));
491 EXPECT_EQ(base::PLATFORM_FILE_OK, 491 EXPECT_EQ(base::File::FILE_OK,
492 file_system_.CreateDirectory(URL(kPath1))); 492 file_system_.CreateDirectory(URL(kPath1)));
493 EXPECT_EQ(base::PLATFORM_FILE_OK, 493 EXPECT_EQ(base::File::FILE_OK,
494 file_system_.CreateFile(URL(kPath2))); 494 file_system_.CreateFile(URL(kPath2)));
495 EXPECT_EQ(base::PLATFORM_FILE_OK, 495 EXPECT_EQ(base::File::FILE_OK,
496 file_system_.CreateDirectory(URL(kPath3))); 496 file_system_.CreateDirectory(URL(kPath3)));
497 EXPECT_EQ(base::PLATFORM_FILE_OK, 497 EXPECT_EQ(base::File::FILE_OK,
498 file_system_.CreateFile(URL(kPath4))); 498 file_system_.CreateFile(URL(kPath4)));
499 499
500 // Verify we have 5 changes for preparation. 500 // Verify we have 5 changes for preparation.
501 file_system_.GetChangedURLsInTracker(&urls); 501 file_system_.GetChangedURLsInTracker(&urls);
502 EXPECT_EQ(5U, urls.size()); 502 EXPECT_EQ(5U, urls.size());
503 change_tracker()->ClearChangesForURL(URL(kPath0)); 503 change_tracker()->ClearChangesForURL(URL(kPath0));
504 change_tracker()->ClearChangesForURL(URL(kPath1)); 504 change_tracker()->ClearChangesForURL(URL(kPath1));
505 change_tracker()->ClearChangesForURL(URL(kPath2)); 505 change_tracker()->ClearChangesForURL(URL(kPath2));
506 change_tracker()->ClearChangesForURL(URL(kPath3)); 506 change_tracker()->ClearChangesForURL(URL(kPath3));
507 change_tracker()->ClearChangesForURL(URL(kPath4)); 507 change_tracker()->ClearChangesForURL(URL(kPath4));
508 508
509 // Make sure we have no changes. 509 // Make sure we have no changes.
510 file_system_.GetChangedURLsInTracker(&urls); 510 file_system_.GetChangedURLsInTracker(&urls);
511 EXPECT_TRUE(urls.empty()); 511 EXPECT_TRUE(urls.empty());
512 512
513 // Move the file and the parent directory. 513 // Move the file and the parent directory.
514 EXPECT_EQ(base::PLATFORM_FILE_OK, 514 EXPECT_EQ(base::File::FILE_OK,
515 file_system_.Move(URL(kPath0), URL(kPath5))); 515 file_system_.Move(URL(kPath0), URL(kPath5)));
516 EXPECT_EQ(base::PLATFORM_FILE_OK, 516 EXPECT_EQ(base::File::FILE_OK,
517 file_system_.Move(URL(kPath1), URL(kPath6))); 517 file_system_.Move(URL(kPath1), URL(kPath6)));
518 518
519 file_system_.GetChangedURLsInTracker(&urls); 519 file_system_.GetChangedURLsInTracker(&urls);
520 EXPECT_EQ(10U, urls.size()); 520 EXPECT_EQ(10U, urls.size());
521 521
522 DropChangesInTracker(); 522 DropChangesInTracker();
523 523
524 // Make sure we have no in-memory changes in the tracker. 524 // Make sure we have no in-memory changes in the tracker.
525 file_system_.GetChangedURLsInTracker(&urls); 525 file_system_.GetChangedURLsInTracker(&urls);
526 ASSERT_EQ(0U, urls.size()); 526 ASSERT_EQ(0U, urls.size());
(...skipping 26 matching lines...) Expand all
553 sync_file_system::SYNC_FILE_TYPE_FILE)); 553 sync_file_system::SYNC_FILE_TYPE_FILE));
554 VerifyAndClearChange(URL(kPath8), 554 VerifyAndClearChange(URL(kPath8),
555 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 555 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
556 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); 556 sync_file_system::SYNC_FILE_TYPE_DIRECTORY));
557 VerifyAndClearChange(URL(kPath9), 557 VerifyAndClearChange(URL(kPath9),
558 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 558 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
559 sync_file_system::SYNC_FILE_TYPE_FILE)); 559 sync_file_system::SYNC_FILE_TYPE_FILE));
560 } 560 }
561 561
562 TEST_F(LocalFileChangeTrackerTest, NextChangedURLsWithRecursiveCopy) { 562 TEST_F(LocalFileChangeTrackerTest, NextChangedURLsWithRecursiveCopy) {
563 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); 563 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
564 564
565 FileSystemURLSet urls; 565 FileSystemURLSet urls;
566 566
567 const char kPath0[] = "dir a"; 567 const char kPath0[] = "dir a";
568 const char kPath1[] = "dir a/file"; 568 const char kPath1[] = "dir a/file";
569 const char kPath2[] = "dir a/dir"; 569 const char kPath2[] = "dir a/dir";
570 570
571 const char kPath0Copy[] = "dir b"; 571 const char kPath0Copy[] = "dir b";
572 const char kPath1Copy[] = "dir b/file"; 572 const char kPath1Copy[] = "dir b/file";
573 const char kPath2Copy[] = "dir b/dir"; 573 const char kPath2Copy[] = "dir b/dir";
574 574
575 // Creates kPath0,1,2 and then copies them all. 575 // Creates kPath0,1,2 and then copies them all.
576 EXPECT_EQ(base::PLATFORM_FILE_OK, 576 EXPECT_EQ(base::File::FILE_OK,
577 file_system_.CreateDirectory(URL(kPath0))); 577 file_system_.CreateDirectory(URL(kPath0)));
578 EXPECT_EQ(base::PLATFORM_FILE_OK, 578 EXPECT_EQ(base::File::FILE_OK,
579 file_system_.CreateFile(URL(kPath1))); 579 file_system_.CreateFile(URL(kPath1)));
580 EXPECT_EQ(base::PLATFORM_FILE_OK, 580 EXPECT_EQ(base::File::FILE_OK,
581 file_system_.CreateDirectory(URL(kPath2))); 581 file_system_.CreateDirectory(URL(kPath2)));
582 EXPECT_EQ(base::PLATFORM_FILE_OK, 582 EXPECT_EQ(base::File::FILE_OK,
583 file_system_.Copy(URL(kPath0), URL(kPath0Copy))); 583 file_system_.Copy(URL(kPath0), URL(kPath0Copy)));
584 584
585 std::deque<FileSystemURL> urls_to_process; 585 std::deque<FileSystemURL> urls_to_process;
586 change_tracker()->GetNextChangedURLs(&urls_to_process, 0); 586 change_tracker()->GetNextChangedURLs(&urls_to_process, 0);
587 ASSERT_EQ(6U, urls_to_process.size()); 587 ASSERT_EQ(6U, urls_to_process.size());
588 588
589 // Creation must have occured first. 589 // Creation must have occured first.
590 EXPECT_EQ(URL(kPath0), urls_to_process[0]); 590 EXPECT_EQ(URL(kPath0), urls_to_process[0]);
591 EXPECT_EQ(URL(kPath1), urls_to_process[1]); 591 EXPECT_EQ(URL(kPath1), urls_to_process[1]);
592 EXPECT_EQ(URL(kPath2), urls_to_process[2]); 592 EXPECT_EQ(URL(kPath2), urls_to_process[2]);
593 593
594 // Then recursive copy took place. The exact order cannot be determined 594 // Then recursive copy took place. The exact order cannot be determined
595 // but the parent directory must have been created first. 595 // but the parent directory must have been created first.
596 EXPECT_EQ(URL(kPath0Copy), urls_to_process[3]); 596 EXPECT_EQ(URL(kPath0Copy), urls_to_process[3]);
597 EXPECT_TRUE(URL(kPath1Copy) == urls_to_process[4] || 597 EXPECT_TRUE(URL(kPath1Copy) == urls_to_process[4] ||
598 URL(kPath2Copy) == urls_to_process[4]); 598 URL(kPath2Copy) == urls_to_process[4]);
599 EXPECT_TRUE(URL(kPath1Copy) == urls_to_process[5] || 599 EXPECT_TRUE(URL(kPath1Copy) == urls_to_process[5] ||
600 URL(kPath2Copy) == urls_to_process[5]); 600 URL(kPath2Copy) == urls_to_process[5]);
601 } 601 }
602 602
603 TEST_F(LocalFileChangeTrackerTest, NextChangedURLsWithRecursiveRemove) { 603 TEST_F(LocalFileChangeTrackerTest, NextChangedURLsWithRecursiveRemove) {
604 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); 604 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
605 605
606 const char kPath0[] = "dir a"; 606 const char kPath0[] = "dir a";
607 const char kPath1[] = "dir a/file1"; 607 const char kPath1[] = "dir a/file1";
608 const char kPath2[] = "dir a/file2"; 608 const char kPath2[] = "dir a/file2";
609 609
610 // Creates kPath0,1,2 and then removes them all. 610 // Creates kPath0,1,2 and then removes them all.
611 EXPECT_EQ(base::PLATFORM_FILE_OK, 611 EXPECT_EQ(base::File::FILE_OK,
612 file_system_.CreateDirectory(URL(kPath0))); 612 file_system_.CreateDirectory(URL(kPath0)));
613 EXPECT_EQ(base::PLATFORM_FILE_OK, 613 EXPECT_EQ(base::File::FILE_OK,
614 file_system_.CreateFile(URL(kPath1))); 614 file_system_.CreateFile(URL(kPath1)));
615 EXPECT_EQ(base::PLATFORM_FILE_OK, 615 EXPECT_EQ(base::File::FILE_OK,
616 file_system_.CreateFile(URL(kPath2))); 616 file_system_.CreateFile(URL(kPath2)));
617 EXPECT_EQ(base::PLATFORM_FILE_OK, 617 EXPECT_EQ(base::File::FILE_OK,
618 file_system_.Remove(URL(kPath0), true /* recursive */)); 618 file_system_.Remove(URL(kPath0), true /* recursive */));
619 619
620 FileSystemURLSet urls; 620 FileSystemURLSet urls;
621 GetAllChangedURLs(&urls); 621 GetAllChangedURLs(&urls);
622 622
623 // This is actually not really desirable, but since the directory 623 // This is actually not really desirable, but since the directory
624 // creation and deletion have been offset now we only have two 624 // creation and deletion have been offset now we only have two
625 // file deletion changes. 625 // file deletion changes.
626 // 626 //
627 // NOTE: This will cause 2 local sync for deleting nonexistent files 627 // NOTE: This will cause 2 local sync for deleting nonexistent files
628 // on the remote side. 628 // on the remote side.
629 // 629 //
630 // TODO(kinuko): For micro optimization we could probably restore the ADD 630 // TODO(kinuko): For micro optimization we could probably restore the ADD
631 // change type (other than ADD_OR_UPDATE) and offset file ADD+DELETE 631 // change type (other than ADD_OR_UPDATE) and offset file ADD+DELETE
632 // changes too. 632 // changes too.
633 ASSERT_EQ(2U, urls.size()); 633 ASSERT_EQ(2U, urls.size());
634 634
635 // The exact order of recursive removal cannot be determined. 635 // The exact order of recursive removal cannot be determined.
636 EXPECT_TRUE(ContainsKey(urls, URL(kPath1))); 636 EXPECT_TRUE(ContainsKey(urls, URL(kPath1)));
637 EXPECT_TRUE(ContainsKey(urls, URL(kPath2))); 637 EXPECT_TRUE(ContainsKey(urls, URL(kPath2)));
638 } 638 }
639 639
640 TEST_F(LocalFileChangeTrackerTest, ResetForFileSystem) { 640 TEST_F(LocalFileChangeTrackerTest, ResetForFileSystem) {
641 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_.OpenFileSystem()); 641 EXPECT_EQ(base::File::FILE_OK, file_system_.OpenFileSystem());
642 642
643 const char kPath0[] = "dir a"; 643 const char kPath0[] = "dir a";
644 const char kPath1[] = "dir a/file"; 644 const char kPath1[] = "dir a/file";
645 const char kPath2[] = "dir a/subdir"; 645 const char kPath2[] = "dir a/subdir";
646 const char kPath3[] = "dir b"; 646 const char kPath3[] = "dir b";
647 647
648 EXPECT_EQ(base::PLATFORM_FILE_OK, 648 EXPECT_EQ(base::File::FILE_OK,
649 file_system_.CreateDirectory(URL(kPath0))); 649 file_system_.CreateDirectory(URL(kPath0)));
650 EXPECT_EQ(base::PLATFORM_FILE_OK, 650 EXPECT_EQ(base::File::FILE_OK,
651 file_system_.CreateFile(URL(kPath1))); 651 file_system_.CreateFile(URL(kPath1)));
652 EXPECT_EQ(base::PLATFORM_FILE_OK, 652 EXPECT_EQ(base::File::FILE_OK,
653 file_system_.CreateDirectory(URL(kPath2))); 653 file_system_.CreateDirectory(URL(kPath2)));
654 EXPECT_EQ(base::PLATFORM_FILE_OK, 654 EXPECT_EQ(base::File::FILE_OK,
655 file_system_.CreateDirectory(URL(kPath3))); 655 file_system_.CreateDirectory(URL(kPath3)));
656 656
657 FileSystemURLSet urls; 657 FileSystemURLSet urls;
658 GetAllChangedURLs(&urls); 658 GetAllChangedURLs(&urls);
659 EXPECT_EQ(4u, urls.size()); 659 EXPECT_EQ(4u, urls.size());
660 EXPECT_TRUE(ContainsKey(urls, URL(kPath0))); 660 EXPECT_TRUE(ContainsKey(urls, URL(kPath0)));
661 EXPECT_TRUE(ContainsKey(urls, URL(kPath1))); 661 EXPECT_TRUE(ContainsKey(urls, URL(kPath1)));
662 EXPECT_TRUE(ContainsKey(urls, URL(kPath2))); 662 EXPECT_TRUE(ContainsKey(urls, URL(kPath2)));
663 EXPECT_TRUE(ContainsKey(urls, URL(kPath3))); 663 EXPECT_TRUE(ContainsKey(urls, URL(kPath3)));
664 664
665 // Reset all changes for the file system. 665 // Reset all changes for the file system.
666 change_tracker()->ResetForFileSystem( 666 change_tracker()->ResetForFileSystem(
667 file_system_.origin(), file_system_.type()); 667 file_system_.origin(), file_system_.type());
668 668
669 GetAllChangedURLs(&urls); 669 GetAllChangedURLs(&urls);
670 EXPECT_TRUE(urls.empty()); 670 EXPECT_TRUE(urls.empty());
671 671
672 // Make sure they're gone from the database too. 672 // Make sure they're gone from the database too.
673 DropChangesInTracker(); 673 DropChangesInTracker();
674 RestoreChangesFromTrackerDB(); 674 RestoreChangesFromTrackerDB();
675 675
676 GetAllChangedURLs(&urls); 676 GetAllChangedURLs(&urls);
677 EXPECT_TRUE(urls.empty()); 677 EXPECT_TRUE(urls.empty());
678 } 678 }
679 679
680 } // namespace sync_file_system 680 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698