OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <set> | 5 #include <set> |
6 #include <utility> | 6 #include <utility> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/predictors/predictor_database.h" | 12 #include "chrome/browser/predictors/predictor_database.h" |
13 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 13 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "content/public/test/test_browser_thread.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
16 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
17 #include "sql/statement.h" | 17 #include "sql/statement.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace predictors { | 20 namespace predictors { |
21 | 21 |
22 class ResourcePrefetchPredictorTablesTest : public testing::Test { | 22 class ResourcePrefetchPredictorTablesTest : public testing::Test { |
23 public: | 23 public: |
24 ResourcePrefetchPredictorTablesTest(); | 24 ResourcePrefetchPredictorTablesTest(); |
25 ~ResourcePrefetchPredictorTablesTest() override; | 25 ~ResourcePrefetchPredictorTablesTest() override; |
26 void SetUp() override; | 26 void SetUp() override; |
27 void TearDown() override; | 27 void TearDown() override; |
28 | 28 |
29 protected: | 29 protected: |
30 void ReopenDatabase(); | 30 void ReopenDatabase(); |
31 void TestGetAllData(); | 31 void TestGetAllData(); |
32 void TestUpdateData(); | 32 void TestUpdateData(); |
33 void TestDeleteData(); | 33 void TestDeleteData(); |
34 void TestDeleteSingleDataPoint(); | 34 void TestDeleteSingleDataPoint(); |
35 void TestDeleteAllData(); | 35 void TestDeleteAllData(); |
36 | 36 |
37 base::MessageLoop loop_; | 37 content::TestBrowserThreadBundle thread_bundle_; |
38 content::TestBrowserThread db_thread_; | |
39 TestingProfile profile_; | 38 TestingProfile profile_; |
40 std::unique_ptr<PredictorDatabase> db_; | 39 std::unique_ptr<PredictorDatabase> db_; |
41 scoped_refptr<ResourcePrefetchPredictorTables> tables_; | 40 scoped_refptr<ResourcePrefetchPredictorTables> tables_; |
42 | 41 |
43 using PrefetchDataMap = ResourcePrefetchPredictorTables::PrefetchDataMap; | 42 using PrefetchDataMap = ResourcePrefetchPredictorTables::PrefetchDataMap; |
44 | 43 |
45 private: | 44 private: |
46 using ResourceRow = ResourcePrefetchPredictorTables::ResourceRow; | 45 using ResourceRow = ResourcePrefetchPredictorTables::ResourceRow; |
47 using ResourceRows = std::vector<ResourceRow>; | 46 using ResourceRows = std::vector<ResourceRow>; |
48 using PrefetchData = ResourcePrefetchPredictorTables::PrefetchData; | 47 using PrefetchData = ResourcePrefetchPredictorTables::PrefetchData; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 void SetUp() override { | 84 void SetUp() override { |
86 // Write data to the table, and then reopen the db. | 85 // Write data to the table, and then reopen the db. |
87 ResourcePrefetchPredictorTablesTest::SetUp(); | 86 ResourcePrefetchPredictorTablesTest::SetUp(); |
88 ResourcePrefetchPredictorTablesTest::TearDown(); | 87 ResourcePrefetchPredictorTablesTest::TearDown(); |
89 | 88 |
90 ReopenDatabase(); | 89 ReopenDatabase(); |
91 } | 90 } |
92 }; | 91 }; |
93 | 92 |
94 ResourcePrefetchPredictorTablesTest::ResourcePrefetchPredictorTablesTest() | 93 ResourcePrefetchPredictorTablesTest::ResourcePrefetchPredictorTablesTest() |
95 : loop_(base::MessageLoop::TYPE_DEFAULT), | 94 : db_(new PredictorDatabase(&profile_)), |
96 db_thread_(content::BrowserThread::DB, &loop_), | |
97 db_(new PredictorDatabase(&profile_)), | |
98 tables_(db_->resource_prefetch_tables()) { | 95 tables_(db_->resource_prefetch_tables()) { |
99 base::RunLoop().RunUntilIdle(); | 96 base::RunLoop().RunUntilIdle(); |
100 } | 97 } |
101 | 98 |
102 ResourcePrefetchPredictorTablesTest::~ResourcePrefetchPredictorTablesTest() { | 99 ResourcePrefetchPredictorTablesTest::~ResourcePrefetchPredictorTablesTest() { |
103 } | 100 } |
104 | 101 |
105 void ResourcePrefetchPredictorTablesTest::SetUp() { | 102 void ResourcePrefetchPredictorTablesTest::SetUp() { |
106 tables_->DeleteAllData(); | 103 tables_->DeleteAllData(); |
107 InitializeSampleData(); | 104 InitializeSampleData(); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 431 |
435 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) { | 432 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) { |
436 TestDeleteSingleDataPoint(); | 433 TestDeleteSingleDataPoint(); |
437 } | 434 } |
438 | 435 |
439 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) { | 436 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) { |
440 TestDeleteAllData(); | 437 TestDeleteAllData(); |
441 } | 438 } |
442 | 439 |
443 } // namespace predictors | 440 } // namespace predictors |
OLD | NEW |