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

Side by Side Diff: chrome/browser/autocomplete/history_url_provider_unittest.cc

Issue 1185723002: Prepare HistoryProvider for componentization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 6 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/autocomplete/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
15 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 16 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
16 #include "chrome/browser/autocomplete/history_quick_provider.h" 17 #include "chrome/browser/autocomplete/history_quick_provider.h"
17 #include "chrome/browser/history/history_service_factory.h" 18 #include "chrome/browser/history/history_service_factory.h"
18 #include "chrome/browser/search_engines/chrome_template_url_service_client.h" 19 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
19 #include "chrome/browser/search_engines/template_url_service_factory.h" 20 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "components/history/core/browser/history_service.h" 24 #include "components/history/core/browser/history_service.h"
24 #include "components/history/core/browser/url_database.h" 25 #include "components/history/core/browser/url_database.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 const UrlAndLegalDefault* expected_urls, 212 const UrlAndLegalDefault* expected_urls,
212 size_t num_results) { 213 size_t num_results) {
213 metrics::OmniboxInputType::Type type; 214 metrics::OmniboxInputType::Type type;
214 return RunTest(text, desired_tld, prevent_inline_autocomplete, 215 return RunTest(text, desired_tld, prevent_inline_autocomplete,
215 expected_urls, num_results, &type); 216 expected_urls, num_results, &type);
216 } 217 }
217 218
218 content::TestBrowserThreadBundle thread_bundle_; 219 content::TestBrowserThreadBundle thread_bundle_;
219 ACMatches matches_; 220 ACMatches matches_;
220 scoped_ptr<TestingProfile> profile_; 221 scoped_ptr<TestingProfile> profile_;
222 scoped_ptr<ChromeAutocompleteProviderClient> client_;
221 history::HistoryService* history_service_; 223 history::HistoryService* history_service_;
222 scoped_refptr<HistoryURLProvider> autocomplete_; 224 scoped_refptr<HistoryURLProvider> autocomplete_;
223 // Should the matches be sorted and duplicates removed? 225 // Should the matches be sorted and duplicates removed?
224 bool sort_matches_; 226 bool sort_matches_;
225 }; 227 };
226 228
227 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { 229 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest {
228 protected: 230 protected:
229 void SetUp() override { 231 void SetUp() override {
230 ASSERT_TRUE(SetUpImpl(true)); 232 ASSERT_TRUE(SetUpImpl(true));
(...skipping 13 matching lines...) Expand all
244 } 246 }
245 }; 247 };
246 248
247 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { 249 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) {
248 if (autocomplete_->done()) 250 if (autocomplete_->done())
249 base::MessageLoop::current()->Quit(); 251 base::MessageLoop::current()->Quit();
250 } 252 }
251 253
252 bool HistoryURLProviderTest::SetUpImpl(bool no_db) { 254 bool HistoryURLProviderTest::SetUpImpl(bool no_db) {
253 profile_.reset(new TestingProfile()); 255 profile_.reset(new TestingProfile());
256 client_.reset(new ChromeAutocompleteProviderClient(profile_.get()));
254 if (!(profile_->CreateHistoryService(true, no_db))) 257 if (!(profile_->CreateHistoryService(true, no_db)))
255 return false; 258 return false;
256 if (!no_db) { 259 if (!no_db) {
257 profile_->BlockUntilHistoryProcessesPendingRequests(); 260 profile_->BlockUntilHistoryProcessesPendingRequests();
258 profile_->BlockUntilHistoryIndexIsRefreshed(); 261 profile_->BlockUntilHistoryIndexIsRefreshed();
259 } 262 }
260 profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "en-US,en,ko"); 263 profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "en-US,en,ko");
261 history_service_ = HistoryServiceFactory::GetForProfile( 264 history_service_ = HistoryServiceFactory::GetForProfile(
262 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS); 265 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS);
263 266
264 autocomplete_ = new HistoryURLProvider(this, profile_.get()); 267 autocomplete_ = new HistoryURLProvider(client_.get(), this, profile_.get());
265 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 268 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
266 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService); 269 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService);
267 FillData(); 270 FillData();
268 return true; 271 return true;
269 } 272 }
270 273
271 void HistoryURLProviderTest::TearDown() { 274 void HistoryURLProviderTest::TearDown() {
272 autocomplete_ = NULL; 275 autocomplete_ = NULL;
273 } 276 }
274 277
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 // Test the experiment (scoring enabled). 1063 // Test the experiment (scoring enabled).
1061 autocomplete_->scoring_params_.experimental_scoring_enabled = true; 1064 autocomplete_->scoring_params_.experimental_scoring_enabled = true;
1062 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), 1065 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input),
1063 std::string(), false, output, max_matches)); 1066 std::string(), false, output, max_matches));
1064 for (int j = 0; j < max_matches; ++j) { 1067 for (int j = 0; j < max_matches; ++j) {
1065 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, 1068 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance,
1066 matches_[j].relevance); 1069 matches_[j].relevance);
1067 } 1070 }
1068 } 1071 }
1069 } 1072 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698