Chromium Code Reviews| Index: components/offline_pages/archive_manager_unittest.cc |
| diff --git a/components/offline_pages/archive_manager_unittest.cc b/components/offline_pages/archive_manager_unittest.cc |
| index 4252dcb80e16c22852b942ef73c1206f74f24a3c..dad4a45f9b08c44fc925a9cb4bad671079ac65cc 100644 |
| --- a/components/offline_pages/archive_manager_unittest.cc |
| +++ b/components/offline_pages/archive_manager_unittest.cc |
| @@ -5,6 +5,7 @@ |
| #include "components/offline_pages/archive_manager.h" |
| #include <memory> |
| +#include <set> |
| #include "base/bind.h" |
| #include "base/files/file_path.h" |
| @@ -37,10 +38,14 @@ class ArchiveManagerTest : public testing::Test { |
| void ResetManager(const base::FilePath& file_path); |
| void Callback(bool result); |
| + void GetAllArchivesCallback(const std::set<base::FilePath>& archive_paths); |
| ArchiveManager* manager() { return manager_.get(); } |
| const base::FilePath& temp_path() const { return temp_dir_.path(); } |
| CallbackStatus callback_status() const { return callback_status_; } |
| + const std::set<base::FilePath>& last_archvie_paths() const { |
| + return last_archvie_paths_; |
| + } |
| private: |
| scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| @@ -49,6 +54,7 @@ class ArchiveManagerTest : public testing::Test { |
| std::unique_ptr<ArchiveManager> manager_; |
| CallbackStatus callback_status_; |
| + std::set<base::FilePath> last_archvie_paths_; |
| }; |
| ArchiveManagerTest::ArchiveManagerTest() |
| @@ -67,6 +73,7 @@ void ArchiveManagerTest::PumpLoop() { |
| void ArchiveManagerTest::ResetResults() { |
| callback_status_ = CallbackStatus::NOT_CALLED; |
| + last_archvie_paths_.clear(); |
| } |
| void ArchiveManagerTest::ResetManager(const base::FilePath& file_path) { |
| @@ -79,6 +86,11 @@ void ArchiveManagerTest::Callback(bool result) { |
| result ? CallbackStatus::CALLED_TRUE : CallbackStatus::CALLED_FALSE; |
| } |
| +void ArchiveManagerTest::GetAllArchivesCallback( |
| + const std::set<base::FilePath>& archive_paths) { |
| + last_archvie_paths_ = archive_paths; |
| +} |
| + |
| TEST_F(ArchiveManagerTest, EnsureArchivesDirCreated) { |
| base::FilePath archive_dir = |
| temp_path().Append(FILE_PATH_LITERAL("test_path")); |
| @@ -206,4 +218,22 @@ TEST_F(ArchiveManagerTest, DeleteArchiveThatDoesNotExist) { |
| EXPECT_FALSE(base::PathExists(archive_path)); |
| } |
| +TEST_F(ArchiveManagerTest, GetAllArchives) { |
| + base::FilePath archive_path_1; |
| + EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_path(), &archive_path_1)); |
| + base::FilePath archive_path_2; |
| + EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_path(), &archive_path_2)); |
| + base::FilePath archive_path_3; |
| + EXPECT_TRUE(base::CreateTemporaryFileInDir(temp_path(), &archive_path_3)); |
| + |
| + manager()->GetAllArchives( |
| + base::Bind(&ArchiveManagerTest::GetAllArchivesCallback, |
| + base::Unretained(this))); |
| + PumpLoop(); |
| + EXPECT_EQ(3UL, last_archvie_paths().size()); |
|
jianli
2016/05/17 21:48:13
nit: ASSERT_EQ
fgorski
2016/05/17 22:50:29
Done.
|
| + EXPECT_EQ(1UL, last_archvie_paths().count(archive_path_1)); |
| + EXPECT_EQ(1UL, last_archvie_paths().count(archive_path_2)); |
| + EXPECT_EQ(1UL, last_archvie_paths().count(archive_path_3)); |
| +} |
| + |
| } // namespace offline_pages |