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

Side by Side Diff: components/offline_pages/offline_page_metadata_store_impl_unittest.cc

Issue 1511483004: [Offline pages] Remove references to MessageLoop from components/offline_pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@test-refactoring
Patch Set: Fixing missing dependency Created 5 years 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
OLDNEW
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 {
40 // Wait for all the pieces of the store to delete itself properly.
41 PumpLoop();
42 }
40 43
41 scoped_ptr<OfflinePageMetadataStoreImpl> BuildStore(); 44 scoped_ptr<OfflinePageMetadataStoreImpl> BuildStore();
42 void PumpLoop(); 45 void PumpLoop();
43 46
44 void LoadCallback(OfflinePageMetadataStore::LoadStatus load_status, 47 void LoadCallback(OfflinePageMetadataStore::LoadStatus load_status,
45 const std::vector<OfflinePageItem>& offline_pages); 48 const std::vector<OfflinePageItem>& offline_pages);
46 void UpdateCallback(CalledCallback called_callback, bool success); 49 void UpdateCallback(CalledCallback called_callback, bool success);
47 50
48 void ClearResults(); 51 void ClearResults();
49 52
50 protected: 53 protected:
51 CalledCallback last_called_callback_; 54 CalledCallback last_called_callback_;
52 Status last_status_; 55 Status last_status_;
53 std::vector<OfflinePageItem> offline_pages_; 56 std::vector<OfflinePageItem> offline_pages_;
54 57
55 base::ScopedTempDir temp_directory_; 58 base::ScopedTempDir temp_directory_;
56 base::MessageLoop message_loop_; 59 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
57 scoped_ptr<base::RunLoop> run_loop_; 60 base::ThreadTaskRunnerHandle task_runner_handle_;
58 }; 61 };
59 62
60 OfflinePageMetadataStoreImplTest::OfflinePageMetadataStoreImplTest() 63 OfflinePageMetadataStoreImplTest::OfflinePageMetadataStoreImplTest()
61 : last_called_callback_(NONE), last_status_(STATUS_NONE) { 64 : last_called_callback_(NONE),
65 last_status_(STATUS_NONE),
66 task_runner_(new base::TestSimpleTaskRunner),
67 task_runner_handle_(task_runner_) {
62 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); 68 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir());
63 } 69 }
64 70
65 OfflinePageMetadataStoreImplTest::~OfflinePageMetadataStoreImplTest() { 71 OfflinePageMetadataStoreImplTest::~OfflinePageMetadataStoreImplTest() {
66 } 72 }
67 73
68 void OfflinePageMetadataStoreImplTest::PumpLoop() { 74 void OfflinePageMetadataStoreImplTest::PumpLoop() {
69 base::RunLoop().RunUntilIdle(); 75 task_runner_->RunUntilIdle();
70 } 76 }
71 77
72 scoped_ptr<OfflinePageMetadataStoreImpl> 78 scoped_ptr<OfflinePageMetadataStoreImpl>
73 OfflinePageMetadataStoreImplTest::BuildStore() { 79 OfflinePageMetadataStoreImplTest::BuildStore() {
74 scoped_ptr<OfflinePageMetadataStoreImpl> store( 80 scoped_ptr<OfflinePageMetadataStoreImpl> store(
75 new OfflinePageMetadataStoreImpl(message_loop_.task_runner(), 81 new OfflinePageMetadataStoreImpl(base::ThreadTaskRunnerHandle::Get(),
76 temp_directory_.path())); 82 temp_directory_.path()));
77 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, 83 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback,
78 base::Unretained(this))); 84 base::Unretained(this)));
79 PumpLoop(); 85 PumpLoop();
80 return store.Pass(); 86 return store.Pass();
81 } 87 }
82 88
83 void OfflinePageMetadataStoreImplTest::LoadCallback( 89 void OfflinePageMetadataStoreImplTest::LoadCallback(
84 OfflinePageMetadataStore::LoadStatus load_status, 90 OfflinePageMetadataStore::LoadStatus load_status,
85 const std::vector<OfflinePageItem>& offline_pages) { 91 const std::vector<OfflinePageItem>& offline_pages) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); 339 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path);
334 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); 340 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size);
335 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); 341 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); 342 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); 343 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count);
338 } 344 }
339 345
340 } // namespace 346 } // namespace
341 347
342 } // namespace offline_pages 348 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/offline_page_metadata_store_impl.cc ('k') | components/offline_pages/offline_page_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698