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

Side by Side Diff: chrome/browser/predictors/autocomplete_action_predictor_unittest.cc

Issue 2799883003: Switch from TestBrowserThread to TestBrowserThreadBundle in chrome. (Closed)
Patch Set: fix-string 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/predictors/autocomplete_action_predictor.h" 5 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 14 #include "base/run_loop.h"
16 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 17 #include "base/time/time.h"
19 #include "chrome/browser/history/history_service_factory.h" 18 #include "chrome/browser/history/history_service_factory.h"
20 #include "chrome/browser/prerender/prerender_field_trial.h" 19 #include "chrome/browser/prerender/prerender_field_trial.h"
21 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
23 #include "components/history/core/browser/history_service.h" 22 #include "components/history/core/browser/history_service.h"
24 #include "components/history/core/browser/in_memory_database.h" 23 #include "components/history/core/browser/in_memory_database.h"
25 #include "components/history/core/browser/url_database.h" 24 #include "components/history/core/browser/url_database.h"
26 #include "components/omnibox/browser/autocomplete_match.h" 25 #include "components/omnibox/browser/autocomplete_match.h"
27 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
28 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
29 28
30 using base::ASCIIToUTF16; 29 using base::ASCIIToUTF16;
31 using content::BrowserThread;
32 using predictors::AutocompleteActionPredictor; 30 using predictors::AutocompleteActionPredictor;
33 31
34 namespace { 32 namespace {
35 33
36 struct TestUrlInfo { 34 struct TestUrlInfo {
37 GURL url; 35 GURL url;
38 base::string16 title; 36 base::string16 title;
39 int days_from_now; 37 int days_from_now;
40 base::string16 user_text; 38 base::string16 user_text;
41 int number_of_hits; 39 int number_of_hits;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 AutocompleteActionPredictor::ACTION_NONE } 78 AutocompleteActionPredictor::ACTION_NONE }
81 }; 79 };
82 80
83 } // end namespace 81 } // end namespace
84 82
85 namespace predictors { 83 namespace predictors {
86 84
87 class AutocompleteActionPredictorTest : public testing::Test { 85 class AutocompleteActionPredictorTest : public testing::Test {
88 public: 86 public:
89 AutocompleteActionPredictorTest() 87 AutocompleteActionPredictorTest()
90 : ui_thread_(BrowserThread::UI, &loop_), 88 : profile_(new TestingProfile()), predictor_(nullptr) {}
91 db_thread_(BrowserThread::DB, &loop_),
92 file_thread_(BrowserThread::FILE, &loop_),
93 profile_(new TestingProfile()),
94 predictor_(nullptr) {
95 }
96 89
97 ~AutocompleteActionPredictorTest() override { 90 ~AutocompleteActionPredictorTest() override {
98 predictor_.reset(NULL); 91 predictor_.reset(NULL);
99 profile_.reset(NULL); 92 profile_.reset(NULL);
100 base::RunLoop().RunUntilIdle(); 93 base::RunLoop().RunUntilIdle();
101 } 94 }
102 95
103 void SetUp() override { 96 void SetUp() override {
104 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 97 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
105 switches::kPrerenderFromOmnibox, 98 switches::kPrerenderFromOmnibox,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 AutocompleteActionPredictor* predictor() { return predictor_.get(); } 204 AutocompleteActionPredictor* predictor() { return predictor_.get(); }
212 205
213 DBCacheMap* db_cache() { return &predictor_->db_cache_; } 206 DBCacheMap* db_cache() { return &predictor_->db_cache_; }
214 DBIdCacheMap* db_id_cache() { return &predictor_->db_id_cache_; } 207 DBIdCacheMap* db_id_cache() { return &predictor_->db_id_cache_; }
215 208
216 static int maximum_days_to_keep_entry() { 209 static int maximum_days_to_keep_entry() {
217 return AutocompleteActionPredictor::kMaximumDaysToKeepEntry; 210 return AutocompleteActionPredictor::kMaximumDaysToKeepEntry;
218 } 211 }
219 212
220 private: 213 private:
221 base::MessageLoop loop_; 214 content::TestBrowserThreadBundle test_browser_thread_bundle_;
222 content::TestBrowserThread ui_thread_;
223 content::TestBrowserThread db_thread_;
224 content::TestBrowserThread file_thread_;
225 std::unique_ptr<TestingProfile> profile_; 215 std::unique_ptr<TestingProfile> profile_;
226 std::unique_ptr<AutocompleteActionPredictor> predictor_; 216 std::unique_ptr<AutocompleteActionPredictor> predictor_;
227 }; 217 };
228 218
229 219
230 TEST_F(AutocompleteActionPredictorTest, AddRow) { 220 TEST_F(AutocompleteActionPredictorTest, AddRow) {
231 // Add a test entry to the predictor. 221 // Add a test entry to the predictor.
232 std::string guid = AddRow(test_url_db[0]); 222 std::string guid = AddRow(test_url_db[0]);
233 223
234 // Get the data back out of the cache. 224 // Get the data back out of the cache.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 AutocompleteActionPredictor::ACTION_PRERENDER) ? 371 AutocompleteActionPredictor::ACTION_PRERENDER) ?
382 AutocompleteActionPredictor::ACTION_PRECONNECT : 372 AutocompleteActionPredictor::ACTION_PRECONNECT :
383 test_url_db[i].expected_action; 373 test_url_db[i].expected_action;
384 EXPECT_EQ(expected_action, 374 EXPECT_EQ(expected_action,
385 predictor()->RecommendAction(test_url_db[i].user_text, match)) 375 predictor()->RecommendAction(test_url_db[i].user_text, match))
386 << "Unexpected action for " << match.destination_url; 376 << "Unexpected action for " << match.destination_url;
387 } 377 }
388 } 378 }
389 379
390 } // namespace predictors 380 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698