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 |
5 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 entries.reset(); | 513 entries.reset(); |
514 directory_service.ReadDirectoryByPath( | 514 directory_service.ReadDirectoryByPath( |
515 FilePath::FromUTF8Unsafe("drive/dir1/file4"), | 515 FilePath::FromUTF8Unsafe("drive/dir1/file4"), |
516 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, | 516 base::Bind(&test_util::CopyResultsFromReadDirectoryCallback, |
517 &error, &entries)); | 517 &error, &entries)); |
518 test_util::RunBlockingPoolTask(); | 518 test_util::RunBlockingPoolTask(); |
519 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, error); | 519 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, error); |
520 EXPECT_FALSE(entries.get()); | 520 EXPECT_FALSE(entries.get()); |
521 } | 521 } |
522 | 522 |
| 523 TEST(GDataDirectoryServiceTest, GetEntryInfoPairByPaths) { |
| 524 MessageLoopForUI message_loop; |
| 525 content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
| 526 &message_loop); |
| 527 GDataDirectoryService directory_service; |
| 528 InitDirectoryService(&directory_service); |
| 529 |
| 530 // Confirm that existing two files are found. |
| 531 scoped_ptr<EntryInfoPairResult> pair_result; |
| 532 directory_service.GetEntryInfoPairByPaths( |
| 533 FilePath::FromUTF8Unsafe("drive/dir1/file4"), |
| 534 FilePath::FromUTF8Unsafe("drive/dir1/file5"), |
| 535 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback, |
| 536 &pair_result)); |
| 537 test_util::RunBlockingPoolTask(); |
| 538 // The first entry should be found. |
| 539 EXPECT_EQ(GDATA_FILE_OK, pair_result->first.error); |
| 540 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), |
| 541 pair_result->first.path); |
| 542 ASSERT_TRUE(pair_result->first.proto.get()); |
| 543 EXPECT_EQ("file4", pair_result->first.proto->base_name()); |
| 544 // The second entry should be found. |
| 545 EXPECT_EQ(GDATA_FILE_OK, pair_result->second.error); |
| 546 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file5"), |
| 547 pair_result->second.path); |
| 548 ASSERT_TRUE(pair_result->second.proto.get()); |
| 549 EXPECT_EQ("file5", pair_result->second.proto->base_name()); |
| 550 |
| 551 // Confirm that the first non existent file is not found. |
| 552 pair_result.reset(); |
| 553 directory_service.GetEntryInfoPairByPaths( |
| 554 FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), |
| 555 FilePath::FromUTF8Unsafe("drive/dir1/file5"), |
| 556 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback, |
| 557 &pair_result)); |
| 558 test_util::RunBlockingPoolTask(); |
| 559 // The first entry should not be found. |
| 560 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, pair_result->first.error); |
| 561 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), |
| 562 pair_result->first.path); |
| 563 ASSERT_FALSE(pair_result->first.proto.get()); |
| 564 // The second entry should not be found, because the first one failed. |
| 565 EXPECT_EQ(GDATA_FILE_ERROR_FAILED, pair_result->second.error); |
| 566 EXPECT_EQ(FilePath(), pair_result->second.path); |
| 567 ASSERT_FALSE(pair_result->second.proto.get()); |
| 568 |
| 569 // Confirm that the second non existent file is not found. |
| 570 pair_result.reset(); |
| 571 directory_service.GetEntryInfoPairByPaths( |
| 572 FilePath::FromUTF8Unsafe("drive/dir1/file4"), |
| 573 FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), |
| 574 base::Bind(&test_util::CopyResultsFromGetEntryInfoPairCallback, |
| 575 &pair_result)); |
| 576 test_util::RunBlockingPoolTask(); |
| 577 // The first entry should be found. |
| 578 EXPECT_EQ(GDATA_FILE_OK, pair_result->first.error); |
| 579 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/file4"), |
| 580 pair_result->first.path); |
| 581 ASSERT_TRUE(pair_result->first.proto.get()); |
| 582 EXPECT_EQ("file4", pair_result->first.proto->base_name()); |
| 583 // The second entry should not be found. |
| 584 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, pair_result->second.error); |
| 585 EXPECT_EQ(FilePath::FromUTF8Unsafe("drive/dir1/non_existent"), |
| 586 pair_result->second.path); |
| 587 ASSERT_FALSE(pair_result->second.proto.get()); |
| 588 } |
| 589 |
523 TEST(GDataDirectoryServiceTest, DBTest) { | 590 TEST(GDataDirectoryServiceTest, DBTest) { |
524 MessageLoopForUI message_loop; | 591 MessageLoopForUI message_loop; |
525 content::TestBrowserThread ui_thread(content::BrowserThread::UI, | 592 content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
526 &message_loop); | 593 &message_loop); |
527 | 594 |
528 scoped_ptr<TestingProfile> profile(new TestingProfile); | 595 scoped_ptr<TestingProfile> profile(new TestingProfile); |
529 scoped_refptr<base::SequencedWorkerPool> pool = | 596 scoped_refptr<base::SequencedWorkerPool> pool = |
530 content::BrowserThread::GetBlockingPool(); | 597 content::BrowserThread::GetBlockingPool(); |
531 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = | 598 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = |
532 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); | 599 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); |
(...skipping 15 matching lines...) Expand all Loading... |
548 GDataDirectoryService directory_service2; | 615 GDataDirectoryService directory_service2; |
549 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. | 616 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. |
550 directory_service2.InitFromDB(db_path, blocking_task_runner, | 617 directory_service2.InitFromDB(db_path, blocking_task_runner, |
551 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); | 618 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); |
552 test_util::RunBlockingPoolTask(); | 619 test_util::RunBlockingPoolTask(); |
553 | 620 |
554 VerifyDirectoryService(&directory_service2); | 621 VerifyDirectoryService(&directory_service2); |
555 } | 622 } |
556 | 623 |
557 } // namespace gdata | 624 } // namespace gdata |
OLD | NEW |