Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/offline_pages/offline_page_metadata_store_impl.h" | 5 #include "components/offline_pages/offline_page_metadata_store_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "base/run_loop.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/test_simple_task_runner.h" | |
| 13 #include "base/thread_task_runner_handle.h" | |
| 14 #include "components/leveldb_proto/proto_database_impl.h" | 14 #include "components/leveldb_proto/proto_database_impl.h" |
| 15 #include "components/offline_pages/offline_page_item.h" | 15 #include "components/offline_pages/offline_page_item.h" |
| 16 #include "components/offline_pages/proto/offline_pages.pb.h" | 16 #include "components/offline_pages/proto/offline_pages.pb.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using leveldb_proto::ProtoDatabaseImpl; | 19 using leveldb_proto::ProtoDatabaseImpl; |
| 20 | 20 |
| 21 namespace offline_pages { | 21 namespace offline_pages { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kTestURL[] = "https://example.com"; | 25 const char kTestURL[] = "https://example.com"; |
| 26 const int64 kTestBookmarkId = 1234LL; | 26 const int64 kTestBookmarkId = 1234LL; |
| 27 const base::FilePath::CharType kFilePath[] = | 27 const base::FilePath::CharType kFilePath[] = |
| 28 FILE_PATH_LITERAL("/offline_pages/example_com.mhtml"); | 28 FILE_PATH_LITERAL("/offline_pages/example_com.mhtml"); |
| 29 int64 kFileSize = 234567; | 29 int64 kFileSize = 234567; |
| 30 | 30 |
| 31 class OfflinePageMetadataStoreImplTest : public testing::Test { | 31 class OfflinePageMetadataStoreImplTest : public testing::Test { |
| 32 public: | 32 public: |
| 33 enum CalledCallback { NONE, LOAD, ADD, REMOVE, DESTROY }; | 33 enum CalledCallback { NONE, LOAD, ADD, REMOVE, DESTROY }; |
| 34 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE }; | 34 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE }; |
| 35 | 35 |
| 36 OfflinePageMetadataStoreImplTest(); | 36 OfflinePageMetadataStoreImplTest(); |
| 37 ~OfflinePageMetadataStoreImplTest() override; | 37 ~OfflinePageMetadataStoreImplTest() override; |
| 38 | 38 |
| 39 void TearDown() override { message_loop_.RunUntilIdle(); } | 39 void TearDown() override { task_runner_->RunUntilIdle(); } |
|
jianli
2015/12/08 23:25:25
Is this needed now? If yes, call PumpLoop instead.
fgorski
2015/12/08 23:39:14
Done. This is needed for the lsan tests. We have t
| |
| 40 | 40 |
| 41 scoped_ptr<OfflinePageMetadataStoreImpl> BuildStore(); | 41 scoped_ptr<OfflinePageMetadataStoreImpl> BuildStore(); |
| 42 void PumpLoop(); | 42 void PumpLoop(); |
| 43 | 43 |
| 44 void LoadCallback(OfflinePageMetadataStore::LoadStatus load_status, | 44 void LoadCallback(OfflinePageMetadataStore::LoadStatus load_status, |
| 45 const std::vector<OfflinePageItem>& offline_pages); | 45 const std::vector<OfflinePageItem>& offline_pages); |
| 46 void UpdateCallback(CalledCallback called_callback, bool success); | 46 void UpdateCallback(CalledCallback called_callback, bool success); |
| 47 | 47 |
| 48 void ClearResults(); | 48 void ClearResults(); |
| 49 | 49 |
| 50 protected: | 50 protected: |
| 51 CalledCallback last_called_callback_; | 51 CalledCallback last_called_callback_; |
| 52 Status last_status_; | 52 Status last_status_; |
| 53 std::vector<OfflinePageItem> offline_pages_; | 53 std::vector<OfflinePageItem> offline_pages_; |
| 54 | 54 |
| 55 base::ScopedTempDir temp_directory_; | 55 base::ScopedTempDir temp_directory_; |
| 56 base::MessageLoop message_loop_; | 56 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 57 scoped_ptr<base::RunLoop> run_loop_; | 57 base::ThreadTaskRunnerHandle task_runner_handle_; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 OfflinePageMetadataStoreImplTest::OfflinePageMetadataStoreImplTest() | 60 OfflinePageMetadataStoreImplTest::OfflinePageMetadataStoreImplTest() |
| 61 : last_called_callback_(NONE), last_status_(STATUS_NONE) { | 61 : last_called_callback_(NONE), |
| 62 last_status_(STATUS_NONE), | |
| 63 task_runner_(new base::TestSimpleTaskRunner), | |
| 64 task_runner_handle_(task_runner_) { | |
| 62 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); | 65 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); |
| 63 } | 66 } |
| 64 | 67 |
| 65 OfflinePageMetadataStoreImplTest::~OfflinePageMetadataStoreImplTest() { | 68 OfflinePageMetadataStoreImplTest::~OfflinePageMetadataStoreImplTest() { |
| 66 } | 69 } |
| 67 | 70 |
| 68 void OfflinePageMetadataStoreImplTest::PumpLoop() { | 71 void OfflinePageMetadataStoreImplTest::PumpLoop() { |
| 69 base::RunLoop().RunUntilIdle(); | 72 task_runner_->RunUntilIdle(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 scoped_ptr<OfflinePageMetadataStoreImpl> | 75 scoped_ptr<OfflinePageMetadataStoreImpl> |
| 73 OfflinePageMetadataStoreImplTest::BuildStore() { | 76 OfflinePageMetadataStoreImplTest::BuildStore() { |
| 74 scoped_ptr<OfflinePageMetadataStoreImpl> store( | 77 scoped_ptr<OfflinePageMetadataStoreImpl> store( |
| 75 new OfflinePageMetadataStoreImpl(message_loop_.task_runner(), | 78 new OfflinePageMetadataStoreImpl(base::ThreadTaskRunnerHandle::Get(), |
| 76 temp_directory_.path())); | 79 temp_directory_.path())); |
| 77 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, | 80 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, |
| 78 base::Unretained(this))); | 81 base::Unretained(this))); |
| 79 PumpLoop(); | 82 PumpLoop(); |
| 80 return store.Pass(); | 83 return store.Pass(); |
| 81 } | 84 } |
| 82 | 85 |
| 83 void OfflinePageMetadataStoreImplTest::LoadCallback( | 86 void OfflinePageMetadataStoreImplTest::LoadCallback( |
| 84 OfflinePageMetadataStore::LoadStatus load_status, | 87 OfflinePageMetadataStore::LoadStatus load_status, |
| 85 const std::vector<OfflinePageItem>& offline_pages) { | 88 const std::vector<OfflinePageItem>& offline_pages) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); | 336 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); |
| 334 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); | 337 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); |
| 335 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); | 338 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); |
| 336 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); | 339 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); |
| 337 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); | 340 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); |
| 338 } | 341 } |
| 339 | 342 |
| 340 } // namespace | 343 } // namespace |
| 341 | 344 |
| 342 } // namespace offline_pages | 345 } // namespace offline_pages |
| OLD | NEW |