OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/precache/core/precache_database.h" | 5 #include "components/precache/core/precache_database.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/metrics/histogram_base.h" | 18 #include "base/metrics/histogram_base.h" |
19 #include "base/test/histogram_tester.h" | 19 #include "base/test/histogram_tester.h" |
20 #include "base/test/scoped_task_environment.h" | |
20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
21 #include "components/history/core/browser/history_constants.h" | 22 #include "components/history/core/browser/history_constants.h" |
22 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
23 #include "net/http/http_response_info.h" | 24 #include "net/http/http_response_info.h" |
24 #include "net/http/http_util.h" | 25 #include "net/http/http_util.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 namespace { | 30 namespace { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 << "Error parsing the test headers: " << header; | 83 << "Error parsing the test headers: " << header; |
83 return result; | 84 return result; |
84 } | 85 } |
85 | 86 |
86 } // namespace | 87 } // namespace |
87 | 88 |
88 namespace precache { | 89 namespace precache { |
89 | 90 |
90 class PrecacheDatabaseTest : public testing::Test { | 91 class PrecacheDatabaseTest : public testing::Test { |
91 public: | 92 public: |
92 PrecacheDatabaseTest() {} | 93 PrecacheDatabaseTest() |
94 : scoped_task_environment_( | |
95 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} | |
93 ~PrecacheDatabaseTest() override {} | 96 ~PrecacheDatabaseTest() override {} |
94 | 97 |
95 protected: | 98 protected: |
96 void SetUp() override { | 99 void SetUp() override { |
97 precache_database_.reset(new PrecacheDatabase()); | 100 precache_database_.reset(new PrecacheDatabase()); |
98 | 101 |
99 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 102 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
100 base::FilePath db_path = scoped_temp_dir_.GetPath().Append( | 103 base::FilePath db_path = scoped_temp_dir_.GetPath().Append( |
101 base::FilePath(FILE_PATH_LITERAL("precache_database"))); | 104 base::FilePath(FILE_PATH_LITERAL("precache_database"))); |
102 ASSERT_TRUE(precache_database_->Init(db_path)); | 105 ASSERT_TRUE(precache_database_->Init(db_path)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 void RecordFetchFromCache(const GURL& url, | 143 void RecordFetchFromCache(const GURL& url, |
141 const base::Time& fetch_time, | 144 const base::Time& fetch_time, |
142 int64_t size); | 145 int64_t size); |
143 void RecordFetchFromCacheCellular(const GURL& url, | 146 void RecordFetchFromCacheCellular(const GURL& url, |
144 const base::Time& fetch_time, | 147 const base::Time& fetch_time, |
145 int64_t size); | 148 int64_t size); |
146 | 149 |
147 // Must be declared first so that it is destroyed last. | 150 // Must be declared first so that it is destroyed last. |
148 base::ScopedTempDir scoped_temp_dir_; | 151 base::ScopedTempDir scoped_temp_dir_; |
149 | 152 |
150 // Having this MessageLoop member variable causes base::MessageLoop::current() | 153 // Having this member causes base::MessageLoop::current() to be set properly. |
gab
2017/04/28 01:43:00
This test doesn't use MessageLoop::current() nor d
fdoray
2017/05/01 17:16:51
There are good chances that a MessageLoop::current
| |
151 // to be set properly. | 154 base::test::ScopedTaskEnvironment scoped_task_environment_; |
152 base::MessageLoopForUI loop_; | |
153 | 155 |
154 std::unique_ptr<PrecacheDatabase> precache_database_; | 156 std::unique_ptr<PrecacheDatabase> precache_database_; |
155 base::HistogramTester histograms_; | 157 base::HistogramTester histograms_; |
156 base::HistogramTester::CountsMap expected_histogram_counts_; | 158 base::HistogramTester::CountsMap expected_histogram_counts_; |
157 | 159 |
158 void ExpectNewSample(const std::string& histogram_name, | 160 void ExpectNewSample(const std::string& histogram_name, |
159 base::HistogramBase::Sample sample) { | 161 base::HistogramBase::Sample sample) { |
160 histograms_.ExpectUniqueSample(histogram_name, sample, 1); | 162 histograms_.ExpectUniqueSample(histogram_name, sample, 1); |
161 expected_histogram_counts_[histogram_name]++; | 163 expected_histogram_counts_[histogram_name]++; |
162 } | 164 } |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 EXPECT_NE(PrecacheReferrerHostEntry::kInvalidId, referrer_id); | 677 EXPECT_NE(PrecacheReferrerHostEntry::kInvalidId, referrer_id); |
676 precache_database_->GetURLListForReferrerHost(referrer_id, &_, | 678 precache_database_->GetURLListForReferrerHost(referrer_id, &_, |
677 &actual_downloaded_urls); | 679 &actual_downloaded_urls); |
678 EXPECT_THAT(actual_downloaded_urls, | 680 EXPECT_THAT(actual_downloaded_urls, |
679 ElementsAre(GURL(already_reported_but_refetch))); | 681 ElementsAre(GURL(already_reported_but_refetch))); |
680 } | 682 } |
681 | 683 |
682 } // namespace | 684 } // namespace |
683 | 685 |
684 } // namespace precache | 686 } // namespace precache |
OLD | NEW |