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

Side by Side Diff: components/precache/core/precache_database_unittest.cc

Issue 2846723005: Use ScopedTaskEnvironment instead of MessageLoopForUI in components tests. (Closed)
Patch Set: fix-test-errors Created 3 years, 7 months 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 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
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
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 base::test::ScopedTaskEnvironment scoped_task_environment_;
151 // to be set properly.
152 base::MessageLoopForUI loop_;
153 154
154 std::unique_ptr<PrecacheDatabase> precache_database_; 155 std::unique_ptr<PrecacheDatabase> precache_database_;
155 base::HistogramTester histograms_; 156 base::HistogramTester histograms_;
156 base::HistogramTester::CountsMap expected_histogram_counts_; 157 base::HistogramTester::CountsMap expected_histogram_counts_;
157 158
158 void ExpectNewSample(const std::string& histogram_name, 159 void ExpectNewSample(const std::string& histogram_name,
159 base::HistogramBase::Sample sample) { 160 base::HistogramBase::Sample sample) {
160 histograms_.ExpectUniqueSample(histogram_name, sample, 1); 161 histograms_.ExpectUniqueSample(histogram_name, sample, 1);
161 expected_histogram_counts_[histogram_name]++; 162 expected_histogram_counts_[histogram_name]++;
162 } 163 }
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 EXPECT_NE(PrecacheReferrerHostEntry::kInvalidId, referrer_id); 676 EXPECT_NE(PrecacheReferrerHostEntry::kInvalidId, referrer_id);
676 precache_database_->GetURLListForReferrerHost(referrer_id, &_, 677 precache_database_->GetURLListForReferrerHost(referrer_id, &_,
677 &actual_downloaded_urls); 678 &actual_downloaded_urls);
678 EXPECT_THAT(actual_downloaded_urls, 679 EXPECT_THAT(actual_downloaded_urls,
679 ElementsAre(GURL(already_reported_but_refetch))); 680 ElementsAre(GURL(already_reported_but_refetch)));
680 } 681 }
681 682
682 } // namespace 683 } // namespace
683 684
684 } // namespace precache 685 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698