OLD | NEW |
---|---|
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 #include <string> | 5 #include <string> |
5 #include <vector> | 6 #include <vector> |
6 | 7 |
7 #include "base/file_path.h" | 8 #include "base/file_path.h" |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/string16.h" | 13 #include "base/string16.h" |
13 #include "base/time.h" | 14 #include "base/time.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 // Try removing file in already removed subdirectory. | 360 // Try removing file in already removed subdirectory. |
360 EXPECT_FALSE(RemoveFile(file_in_subdir)); | 361 EXPECT_FALSE(RemoveFile(file_in_subdir)); |
361 | 362 |
362 // Try removing non-existing file. | 363 // Try removing non-existing file. |
363 EXPECT_FALSE(RemoveFile(nonexisting_file)); | 364 EXPECT_FALSE(RemoveFile(nonexisting_file)); |
364 | 365 |
365 // Try removing root file element. | 366 // Try removing root file element. |
366 EXPECT_FALSE(RemoveFile(FilePath("gdata"))); | 367 EXPECT_FALSE(RemoveFile(FilePath("gdata"))); |
367 } | 368 } |
368 | 369 |
369 | |
370 TEST_F(GDataFileSystemTest, CreateDirectory) { | 370 TEST_F(GDataFileSystemTest, CreateDirectory) { |
371 LoadRootFeedDocument("root_feed.json"); | 371 LoadRootFeedDocument("root_feed.json"); |
372 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); | 372 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); |
373 | 373 |
374 // Create directory in root. | 374 // Create directory in root. |
375 FilePath dir_path("gdata/New Folder 1"); | 375 FilePath dir_path("gdata/New Folder 1"); |
376 EXPECT_TRUE(FindFile(dir_path) == NULL); | 376 EXPECT_TRUE(FindFile(dir_path) == NULL); |
377 AddDirectoryFromFile(dir_path, "directory_entry_atom.json"); | 377 AddDirectoryFromFile(dir_path, "directory_entry_atom.json"); |
378 EXPECT_TRUE(FindFile(dir_path) != NULL); | 378 EXPECT_TRUE(FindFile(dir_path) != NULL); |
379 | 379 |
380 // Create directory in a sub dirrectory. | 380 // Create directory in a sub dirrectory. |
381 FilePath subdir_path("gdata/New Folder 1/New Folder 2"); | 381 FilePath subdir_path("gdata/New Folder 1/New Folder 2"); |
382 EXPECT_TRUE(FindFile(subdir_path) == NULL); | 382 EXPECT_TRUE(FindFile(subdir_path) == NULL); |
383 AddDirectoryFromFile(subdir_path, "directory_entry_atom.json"); | 383 AddDirectoryFromFile(subdir_path, "directory_entry_atom.json"); |
384 EXPECT_TRUE(FindFile(subdir_path) != NULL); | 384 EXPECT_TRUE(FindFile(subdir_path) != NULL); |
385 } | 385 } |
386 | 386 |
387 TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) { | 387 TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) { |
388 LoadRootFeedDocument("root_feed.json"); | 388 LoadRootFeedDocument("root_feed.json"); |
389 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); | 389 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); |
390 | 390 |
391 GURL last_dir_content_url; | 391 GURL last_dir_content_url; |
392 FilePath first_missing_parent_path; | 392 FilePath first_missing_parent_path; |
393 | 393 |
394 // Create directory in root. | 394 // Create directory in root. |
395 FilePath dir_path("gdata/New Folder 1"); | 395 FilePath dir_path("gdata/New Folder 1"); |
396 EXPECT_EQ( | 396 EXPECT_EQ( |
397 GDataFileSystem::FOUND_MISSING, | |
397 file_system_->FindFirstMissingParentDirectory(dir_path, | 398 file_system_->FindFirstMissingParentDirectory(dir_path, |
398 &last_dir_content_url, | 399 &last_dir_content_url, |
399 &first_missing_parent_path), | 400 &first_missing_parent_path)); |
400 GDataFileSystem::FOUND_MISSING); | 401 EXPECT_EQ(FilePath("gdata/New Folder 1"), first_missing_parent_path); |
satorux1
2012/03/02 21:31:24
nit: FilePath(FILE_PATH_LITERAL(...)) or FilePath:
zel
2012/03/02 21:46:44
Fixed there and on bunch of other places in this f
| |
401 EXPECT_EQ(dir_path, first_missing_parent_path); | |
402 EXPECT_TRUE(last_dir_content_url.is_empty()); // root directory. | 402 EXPECT_TRUE(last_dir_content_url.is_empty()); // root directory. |
403 | 403 |
404 // Missing folders in subdir of an existing folder. | 404 // Missing folders in subdir of an existing folder. |
405 FilePath dir_path2("gdata/Directory 1/New Folder 2"); | 405 FilePath dir_path2("gdata/Directory 1/New Folder 2"); |
406 EXPECT_EQ( | 406 EXPECT_EQ( |
407 GDataFileSystem::FOUND_MISSING, | |
407 file_system_->FindFirstMissingParentDirectory(dir_path2, | 408 file_system_->FindFirstMissingParentDirectory(dir_path2, |
408 &last_dir_content_url, | 409 &last_dir_content_url, |
409 &first_missing_parent_path), | 410 &first_missing_parent_path)); |
410 GDataFileSystem::FOUND_MISSING); | 411 EXPECT_EQ(FilePath("gdata/Directory 1/New Folder 2"), |
411 EXPECT_EQ(dir_path2, first_missing_parent_path); | 412 first_missing_parent_path); |
412 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. | 413 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. |
413 | 414 |
414 // Missing two folders on the path. | 415 // Missing two folders on the path. |
415 FilePath dir_path3 = dir_path2.Append("Another Foder"); | 416 FilePath dir_path3 = dir_path2.Append("Another Foder"); |
416 EXPECT_EQ( | 417 EXPECT_EQ( |
418 GDataFileSystem::FOUND_MISSING, | |
417 file_system_->FindFirstMissingParentDirectory(dir_path3, | 419 file_system_->FindFirstMissingParentDirectory(dir_path3, |
418 &last_dir_content_url, | 420 &last_dir_content_url, |
419 &first_missing_parent_path), | 421 &first_missing_parent_path)); |
420 GDataFileSystem::FOUND_MISSING); | 422 EXPECT_EQ(FilePath("gdata/Directory 1/New Folder 2"), |
421 EXPECT_EQ(dir_path3.DirName(), first_missing_parent_path); | 423 first_missing_parent_path); |
422 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. | 424 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. |
423 | 425 |
424 // Folders on top of an existing file. | 426 // Folders on top of an existing file. |
425 EXPECT_EQ( | 427 EXPECT_EQ( |
428 GDataFileSystem::FOUND_INVALID, | |
426 file_system_->FindFirstMissingParentDirectory( | 429 file_system_->FindFirstMissingParentDirectory( |
427 FilePath("gdata/File 1.txt/BadDir"), | 430 FilePath("gdata/File 1.txt/BadDir"), |
428 &last_dir_content_url, | 431 &last_dir_content_url, |
429 &first_missing_parent_path), | 432 &first_missing_parent_path)); |
430 GDataFileSystem::FOUND_INVALID); | |
431 | 433 |
432 // Existing folder. | 434 // Existing folder. |
433 EXPECT_EQ( | 435 EXPECT_EQ( |
436 GDataFileSystem::DIRECTORY_ALREADY_PRESENT, | |
434 file_system_->FindFirstMissingParentDirectory( | 437 file_system_->FindFirstMissingParentDirectory( |
435 FilePath("gdata/Directory 1"), | 438 FilePath("gdata/Directory 1"), |
436 &last_dir_content_url, | 439 &last_dir_content_url, |
437 &first_missing_parent_path), | 440 &first_missing_parent_path)); |
438 GDataFileSystem::DIRECTORY_ALREADY_PRESENT); | |
439 } | 441 } |
440 | 442 |
441 } // namespace gdata | 443 } // namespace gdata |
OLD | NEW |