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

Side by Side Diff: components/omnibox/browser/history_url_provider_unittest.cc

Issue 1610283002: Componentizes history_url_provider_unittest.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 11 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 "components/omnibox/browser/history_url_provider.h" 5 #include "components/omnibox/browser/history_url_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/files/scoped_temp_dir.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" 19 #include "components/history/core/browser/history_database_params.h"
19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
20 #include "chrome/browser/history/history_service_factory.h"
21 #include "chrome/browser/search_engines/chrome_template_url_service_client.h"
22 #include "chrome/browser/search_engines/template_url_service_factory.h"
23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h"
26 #include "components/history/core/browser/history_service.h" 20 #include "components/history/core/browser/history_service.h"
27 #include "components/history/core/browser/url_database.h" 21 #include "components/history/core/browser/url_database.h"
22 #include "components/history/core/test/test_history_database.h"
28 #include "components/metrics/proto/omnibox_event.pb.h" 23 #include "components/metrics/proto/omnibox_event.pb.h"
29 #include "components/metrics/proto/omnibox_input_type.pb.h" 24 #include "components/metrics/proto/omnibox_input_type.pb.h"
30 #include "components/omnibox/browser/autocomplete_match.h" 25 #include "components/omnibox/browser/autocomplete_match.h"
31 #include "components/omnibox/browser/autocomplete_provider.h" 26 #include "components/omnibox/browser/autocomplete_provider.h"
32 #include "components/omnibox/browser/autocomplete_provider_listener.h" 27 #include "components/omnibox/browser/autocomplete_provider_listener.h"
33 #include "components/omnibox/browser/autocomplete_result.h" 28 #include "components/omnibox/browser/autocomplete_result.h"
34 #include "components/omnibox/browser/history_quick_provider.h" 29 #include "components/omnibox/browser/history_quick_provider.h"
30 #include "components/omnibox/browser/mock_autocomplete_provider_client.h"
31 #include "components/omnibox/browser/test_scheme_classifier.h"
35 #include "components/search_engines/default_search_manager.h" 32 #include "components/search_engines/default_search_manager.h"
36 #include "components/search_engines/search_terms_data.h" 33 #include "components/search_engines/search_terms_data.h"
37 #include "components/search_engines/template_url.h" 34 #include "components/search_engines/template_url.h"
38 #include "components/search_engines/template_url_service.h" 35 #include "components/search_engines/template_url_service.h"
39 #include "components/url_formatter/url_fixer.h" 36 #include "components/url_formatter/url_fixer.h"
40 #include "content/public/test/test_browser_thread_bundle.h"
41 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
42 38
43 using base::ASCIIToUTF16; 39 using base::ASCIIToUTF16;
44 using base::Time; 40 using base::Time;
45 using base::TimeDelta; 41 using base::TimeDelta;
46 42
47 using content::TestBrowserThreadBundle; 43 namespace {
48 44
49 struct TestURLInfo { 45 struct TestURLInfo {
50 const char* url; 46 const char* url;
51 const char* title; 47 const char* title;
52 int visit_count; 48 int visit_count;
53 int typed_count; 49 int typed_count;
54 int age_in_days; 50 int age_in_days;
55 } test_db[] = { 51 } test_db[] = {
56 {"http://www.google.com/", "Google", 3, 3, 80}, 52 {"http://www.google.com/", "Google", 3, 3, 80},
57 53
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // For experimental HUP scoring test. 146 // For experimental HUP scoring test.
151 {"http://7.com/1a", "One", 8, 4, 4}, 147 {"http://7.com/1a", "One", 8, 4, 4},
152 {"http://7.com/2a", "Two A", 4, 2, 8}, 148 {"http://7.com/2a", "Two A", 4, 2, 8},
153 {"http://7.com/2b", "Two B", 4, 1, 8}, 149 {"http://7.com/2b", "Two B", 4, 1, 8},
154 {"http://7.com/3a", "Three", 2, 1, 16}, 150 {"http://7.com/3a", "Three", 2, 1, 16},
155 {"http://7.com/4a", "Four A", 1, 1, 32}, 151 {"http://7.com/4a", "Four A", 1, 1, 32},
156 {"http://7.com/4b", "Four B", 1, 1, 64}, 152 {"http://7.com/4b", "Four B", 1, 1, 64},
157 {"http://7.com/5a", "Five A", 8, 0, 64}, // never typed. 153 {"http://7.com/5a", "Five A", 8, 0, 64}, // never typed.
158 }; 154 };
159 155
156 class QuittingHistoryDBTask : public history::HistoryDBTask {
Peter Kasting 2016/01/21 11:08:40 Nit: QuitTask? "Quitting" in particular reads wei
rohitrao (ping after 24h) 2016/01/21 13:10:55 Renamed to QuitTask.
157 public:
158 QuittingHistoryDBTask() {}
159
160 bool RunOnDBThread(history::HistoryBackend* backend,
161 history::HistoryDatabase* db) override {
162 return true;
163 }
164
165 void DoneRunOnMainThread() override {
166 base::MessageLoop::current()->QuitWhenIdle();
167 }
168
169 private:
170 ~QuittingHistoryDBTask() override {}
171
172 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
173 };
174
175 class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient {
176 public:
177 FakeAutocompleteProviderClient() {
178 set_template_url_service(
179 make_scoped_ptr(new TemplateURLService(nullptr, 0)));
180 }
181
182 const AutocompleteSchemeClassifier& GetSchemeClassifier() const override {
183 return scheme_classifier_;
184 }
185
186 const SearchTermsData& GetSearchTermsData() const override {
187 return search_terms_data_;
188 }
189
190 history::HistoryService* GetHistoryService() override {
191 return &history_service_;
192 }
193
194 private:
195 TestSchemeClassifier scheme_classifier_;
196 SearchTermsData search_terms_data_;
197 history::HistoryService history_service_;
198
199 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient);
200 };
201
202 } // namespace
203
160 class HistoryURLProviderTest : public testing::Test, 204 class HistoryURLProviderTest : public testing::Test,
161 public AutocompleteProviderListener { 205 public AutocompleteProviderListener {
162 public: 206 public:
163 struct UrlAndLegalDefault { 207 struct UrlAndLegalDefault {
164 std::string url; 208 std::string url;
165 bool allowed_to_be_default_match; 209 bool allowed_to_be_default_match;
166 }; 210 };
167 211
168 HistoryURLProviderTest() 212 HistoryURLProviderTest()
169 : sort_matches_(false) { 213 : sort_matches_(false) {
170 HistoryQuickProvider::set_disabled(true); 214 HistoryQuickProvider::set_disabled(true);
171 } 215 }
172 216
173 ~HistoryURLProviderTest() override { 217 ~HistoryURLProviderTest() override {
174 HistoryQuickProvider::set_disabled(false); 218 HistoryQuickProvider::set_disabled(false);
175 } 219 }
176 220
177 // AutocompleteProviderListener: 221 // AutocompleteProviderListener:
178 void OnProviderUpdate(bool updated_matches) override; 222 void OnProviderUpdate(bool updated_matches) override;
179 223
180 protected: 224 protected:
181 static scoped_ptr<KeyedService> CreateTemplateURLService(
182 content::BrowserContext* context) {
183 Profile* profile = static_cast<Profile*>(context);
184 return make_scoped_ptr(new TemplateURLService(
185 profile->GetPrefs(), make_scoped_ptr(new SearchTermsData), NULL,
186 scoped_ptr<TemplateURLServiceClient>(new ChromeTemplateURLServiceClient(
187 HistoryServiceFactory::GetForProfile(
188 profile, ServiceAccessType::EXPLICIT_ACCESS))),
189 NULL, NULL, base::Closure()));
190 }
191
192 // testing::Test 225 // testing::Test
193 void SetUp() override { 226 void SetUp() override {
194 ASSERT_TRUE(SetUpImpl(false)); 227 ASSERT_TRUE(SetUpImpl(false));
195 } 228 }
196 void TearDown() override; 229 void TearDown() override;
197 230
198 // Does the real setup. 231 // Does the real setup.
199 bool SetUpImpl(bool no_db) WARN_UNUSED_RESULT; 232 bool SetUpImpl(bool no_db) WARN_UNUSED_RESULT;
200 233
201 // Fills test data into the history system. 234 // Fills test data into the history system.
(...skipping 13 matching lines...) Expand all
215 void RunTest(const base::string16& text, 248 void RunTest(const base::string16& text,
216 const std::string& desired_tld, 249 const std::string& desired_tld,
217 bool prevent_inline_autocomplete, 250 bool prevent_inline_autocomplete,
218 const UrlAndLegalDefault* expected_urls, 251 const UrlAndLegalDefault* expected_urls,
219 size_t num_results) { 252 size_t num_results) {
220 metrics::OmniboxInputType::Type type; 253 metrics::OmniboxInputType::Type type;
221 return RunTest(text, desired_tld, prevent_inline_autocomplete, 254 return RunTest(text, desired_tld, prevent_inline_autocomplete,
222 expected_urls, num_results, &type); 255 expected_urls, num_results, &type);
223 } 256 }
224 257
225 content::TestBrowserThreadBundle thread_bundle_; 258 // Helper functions to initialize the HistoryService.
259 bool InitializeHistoryService(
260 bool delete_file, bool no_db) WARN_UNUSED_RESULT;
Peter Kasting 2016/01/21 11:08:40 Nit: Prefer to wrap like: bool InitializeHistor
rohitrao (ping after 24h) 2016/01/21 13:10:55 Removed WARN_UNUSED_RESULT.
261 void BlockUntilHistoryProcessesPendingRequests();
262
263 base::MessageLoop message_loop_;
264 base::ScopedTempDir history_dir_;
226 ACMatches matches_; 265 ACMatches matches_;
227 scoped_ptr<TestingProfile> profile_; 266 scoped_ptr<FakeAutocompleteProviderClient> client_;
228 scoped_ptr<ChromeAutocompleteProviderClient> client_;
229 history::HistoryService* history_service_; 267 history::HistoryService* history_service_;
230 scoped_refptr<HistoryURLProvider> autocomplete_; 268 scoped_refptr<HistoryURLProvider> autocomplete_;
231 // Should the matches be sorted and duplicates removed? 269 // Should the matches be sorted and duplicates removed?
232 bool sort_matches_; 270 bool sort_matches_;
271
233 }; 272 };
Peter Kasting 2016/01/21 11:08:40 If you're going to touch this anyway, add DISALLOW
rohitrao (ping after 24h) 2016/01/21 13:10:55 Done.
234 273
235 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { 274 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest {
236 protected: 275 protected:
237 void SetUp() override { 276 void SetUp() override {
238 ASSERT_TRUE(SetUpImpl(true)); 277 ASSERT_TRUE(SetUpImpl(true));
239 } 278 }
240 }; 279 };
241 280
242 class HistoryURLProviderTestNoSearchProvider : public HistoryURLProviderTest { 281 class HistoryURLProviderTestNoSearchProvider : public HistoryURLProviderTest {
243 protected: 282 protected:
244 void SetUp() override { 283 void SetUp() override {
245 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true); 284 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true);
246 HistoryURLProviderTest::SetUp(); 285 HistoryURLProviderTest::SetUp();
247 } 286 }
248 287
249 void TearDown() override { 288 void TearDown() override {
250 HistoryURLProviderTest::TearDown(); 289 HistoryURLProviderTest::TearDown();
251 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false); 290 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false);
252 } 291 }
253 }; 292 };
254 293
255 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { 294 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) {
256 if (autocomplete_->done()) 295 if (autocomplete_->done())
257 base::MessageLoop::current()->QuitWhenIdle(); 296 base::MessageLoop::current()->QuitWhenIdle();
258 } 297 }
259 298
299 bool HistoryURLProviderTest::InitializeHistoryService(
300 bool delete_file, bool no_db) {
301 if (!history_dir_.CreateUniqueTempDir()) {
Peter Kasting 2016/01/21 11:08:40 Nit: No {} on any of the conditionals in this func
rohitrao (ping after 24h) 2016/01/21 13:10:55 Done.
302 return false;
303 }
304
305 history_service_ = client_->GetHistoryService();
306 if (!history_service_->Init(
307 no_db,
308 std::string(),
309 history::TestHistoryDatabaseParamsForPath(history_dir_.path()))) {
310 return false;
311 }
312
313 if (!no_db) {
Peter Kasting 2016/01/21 11:08:40 Nit: Ugh, double-negative. Makes me think we shou
rohitrao (ping after 24h) 2016/01/21 13:10:55 Leaving this for now. I think that if we make a c
314 BlockUntilHistoryProcessesPendingRequests();
315 }
316
317 return true;
318 }
319
320 void HistoryURLProviderTest::BlockUntilHistoryProcessesPendingRequests() {
321 base::CancelableTaskTracker tracker;
322 client_->GetHistoryService()->ScheduleDBTask(
323 scoped_ptr<history::HistoryDBTask>(
Peter Kasting 2016/01/21 11:08:40 Nit: make_scoped_ptr?
rohitrao (ping after 24h) 2016/01/21 13:10:54 This makes scoped_ptr unhappy, due to the private
324 new QuittingHistoryDBTask()),
325 &tracker);
326 base::MessageLoop::current()->Run();
327 }
328
260 bool HistoryURLProviderTest::SetUpImpl(bool no_db) { 329 bool HistoryURLProviderTest::SetUpImpl(bool no_db) {
261 profile_.reset(new TestingProfile()); 330 client_.reset(new FakeAutocompleteProviderClient());
262 client_.reset(new ChromeAutocompleteProviderClient(profile_.get())); 331
263 if (!(profile_->CreateHistoryService(true, no_db))) 332 if (!InitializeHistoryService(true, no_db))
264 return false; 333 return false;
265 if (!no_db) { 334 EXPECT_CALL(*client_, GetAcceptLanguages())
266 profile_->BlockUntilHistoryProcessesPendingRequests(); 335 .WillRepeatedly(testing::Return("en-US,en,ko"));
267 profile_->BlockUntilHistoryIndexIsRefreshed();
268 }
269 profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "en-US,en,ko");
270 history_service_ = HistoryServiceFactory::GetForProfile(
271 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS);
272 336
273 autocomplete_ = new HistoryURLProvider(client_.get(), this); 337 autocomplete_ = new HistoryURLProvider(client_.get(), this);
274 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
275 profile_.get(), &HistoryURLProviderTest::CreateTemplateURLService);
276 FillData(); 338 FillData();
277 return true; 339 return true;
278 } 340 }
279 341
280 void HistoryURLProviderTest::TearDown() { 342 void HistoryURLProviderTest::TearDown() {
281 autocomplete_ = NULL; 343 autocomplete_ = NULL;
282 } 344 }
283 345
284 void HistoryURLProviderTest::FillData() { 346 void HistoryURLProviderTest::FillData() {
285 // Most visits are a long time ago (some tests require this since we do some 347 // Most visits are a long time ago (some tests require this since we do some
(...skipping 24 matching lines...) Expand all
310 void HistoryURLProviderTest::RunTest( 372 void HistoryURLProviderTest::RunTest(
311 const base::string16& text, 373 const base::string16& text,
312 const std::string& desired_tld, 374 const std::string& desired_tld,
313 bool prevent_inline_autocomplete, 375 bool prevent_inline_autocomplete,
314 const UrlAndLegalDefault* expected_urls, 376 const UrlAndLegalDefault* expected_urls,
315 size_t num_results, 377 size_t num_results,
316 metrics::OmniboxInputType::Type* identified_input_type) { 378 metrics::OmniboxInputType::Type* identified_input_type) {
317 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(), 379 AutocompleteInput input(text, base::string16::npos, desired_tld, GURL(),
318 metrics::OmniboxEventProto::INVALID_SPEC, 380 metrics::OmniboxEventProto::INVALID_SPEC,
319 prevent_inline_autocomplete, false, true, true, false, 381 prevent_inline_autocomplete, false, true, true, false,
320 ChromeAutocompleteSchemeClassifier(profile_.get())); 382 TestSchemeClassifier());
321 *identified_input_type = input.type(); 383 *identified_input_type = input.type();
322 autocomplete_->Start(input, false); 384 autocomplete_->Start(input, false);
323 if (!autocomplete_->done()) 385 if (!autocomplete_->done())
324 base::MessageLoop::current()->Run(); 386 base::MessageLoop::current()->Run();
325 387
326 matches_ = autocomplete_->matches(); 388 matches_ = autocomplete_->matches();
327 if (sort_matches_) { 389 if (sort_matches_) {
328 TemplateURLService* service = 390 TemplateURLService* service = client_->GetTemplateURLService();
329 TemplateURLServiceFactory::GetForProfile(profile_.get());
330 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { 391 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) {
331 i->ComputeStrippedDestinationURL( 392 i->ComputeStrippedDestinationURL(
332 input, client_->GetAcceptLanguages(), service); 393 input, client_->GetAcceptLanguages(), service);
333 } 394 }
334 AutocompleteResult::DedupMatchesByDestination( 395 AutocompleteResult::DedupMatchesByDestination(
335 input.current_page_classification(), false, &matches_); 396 input.current_page_classification(), false, &matches_);
336 std::sort(matches_.begin(), matches_.end(), 397 std::sort(matches_.begin(), matches_.end(),
337 &AutocompleteMatch::MoreRelevant); 398 &AutocompleteMatch::MoreRelevant);
338 } 399 }
339 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text 400 ASSERT_EQ(num_results, matches_.size()) << "Input text: " << text
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 { "http://www.17173.com/", true } 695 { "http://www.17173.com/", true }
635 }; 696 };
636 RunTest(ASCIIToUTF16("17173"), std::string(), false, fixup_5, 697 RunTest(ASCIIToUTF16("17173"), std::string(), false, fixup_5,
637 arraysize(fixup_5)); 698 arraysize(fixup_5));
638 } 699 }
639 700
640 // Make sure the results for the input 'p' don't change between the first and 701 // Make sure the results for the input 'p' don't change between the first and
641 // second passes. 702 // second passes.
642 TEST_F(HistoryURLProviderTest, EmptyVisits) { 703 TEST_F(HistoryURLProviderTest, EmptyVisits) {
643 // Wait for history to create the in memory DB. 704 // Wait for history to create the in memory DB.
644 profile_->BlockUntilHistoryProcessesPendingRequests(); 705 BlockUntilHistoryProcessesPendingRequests();
645 706
646 AutocompleteInput input( 707 AutocompleteInput input(
647 ASCIIToUTF16("pa"), base::string16::npos, std::string(), GURL(), 708 ASCIIToUTF16("pa"), base::string16::npos, std::string(), GURL(),
648 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, 709 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false,
649 ChromeAutocompleteSchemeClassifier(profile_.get())); 710 TestSchemeClassifier());
650 autocomplete_->Start(input, false); 711 autocomplete_->Start(input, false);
651 // HistoryURLProvider shouldn't be done (waiting on async results). 712 // HistoryURLProvider shouldn't be done (waiting on async results).
652 EXPECT_FALSE(autocomplete_->done()); 713 EXPECT_FALSE(autocomplete_->done());
653 714
654 // We should get back an entry for pandora. 715 // We should get back an entry for pandora.
655 matches_ = autocomplete_->matches(); 716 matches_ = autocomplete_->matches();
656 ASSERT_GT(matches_.size(), 0u); 717 ASSERT_GT(matches_.size(), 0u);
657 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url); 718 EXPECT_EQ(GURL("http://pandora.com/"), matches_[0].destination_url);
658 int pandora_relevance = matches_[0].relevance; 719 int pandora_relevance = matches_[0].relevance;
659 720
(...skipping 21 matching lines...) Expand all
681 RunTest(ASCIIToUTF16("slash"), std::string(), false, navigation_2, 742 RunTest(ASCIIToUTF16("slash"), std::string(), false, navigation_2,
682 arraysize(navigation_2)); 743 arraysize(navigation_2));
683 744
684 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0); 745 RunTest(ASCIIToUTF16("this is a query"), std::string(), false, NULL, 0);
685 } 746 }
686 747
687 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) { 748 TEST_F(HistoryURLProviderTest, DontAutocompleteOnTrailingWhitespace) {
688 AutocompleteInput input( 749 AutocompleteInput input(
689 ASCIIToUTF16("slash "), base::string16::npos, std::string(), GURL(), 750 ASCIIToUTF16("slash "), base::string16::npos, std::string(), GURL(),
690 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, 751 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false,
691 ChromeAutocompleteSchemeClassifier(profile_.get())); 752 TestSchemeClassifier());
692 autocomplete_->Start(input, false); 753 autocomplete_->Start(input, false);
693 if (!autocomplete_->done()) 754 if (!autocomplete_->done())
694 base::MessageLoop::current()->Run(); 755 base::MessageLoop::current()->Run();
695 756
696 // None of the matches should attempt to autocomplete. 757 // None of the matches should attempt to autocomplete.
697 matches_ = autocomplete_->matches(); 758 matches_ = autocomplete_->matches();
698 for (size_t i = 0; i < matches_.size(); ++i) { 759 for (size_t i = 0; i < matches_.size(); ++i) {
699 EXPECT_TRUE(matches_[i].inline_autocompletion.empty()); 760 EXPECT_TRUE(matches_[i].inline_autocompletion.empty());
700 EXPECT_FALSE(matches_[i].allowed_to_be_default_match); 761 EXPECT_FALSE(matches_[i].allowed_to_be_default_match);
701 } 762 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 // This test passes if we don't crash. The results don't matter. 880 // This test passes if we don't crash. The results don't matter.
820 const char* const test_cases[] = { 881 const char* const test_cases[] = {
821 "//c", 882 "//c",
822 "\\@st", 883 "\\@st",
823 "view-source:x", 884 "view-source:x",
824 }; 885 };
825 for (size_t i = 0; i < arraysize(test_cases); ++i) { 886 for (size_t i = 0; i < arraysize(test_cases); ++i) {
826 AutocompleteInput input( 887 AutocompleteInput input(
827 ASCIIToUTF16(test_cases[i]), base::string16::npos, std::string(), 888 ASCIIToUTF16(test_cases[i]), base::string16::npos, std::string(),
828 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, 889 GURL(), metrics::OmniboxEventProto::INVALID_SPEC, false, false, true,
829 true, false, ChromeAutocompleteSchemeClassifier(profile_.get())); 890 true, false, TestSchemeClassifier());
830 autocomplete_->Start(input, false); 891 autocomplete_->Start(input, false);
831 if (!autocomplete_->done()) 892 if (!autocomplete_->done())
832 base::MessageLoop::current()->Run(); 893 base::MessageLoop::current()->Run();
833 } 894 }
834 } 895 }
835 896
836 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) { 897 TEST_F(HistoryURLProviderTest, DoesNotProvideMatchesOnFocus) {
837 AutocompleteInput input( 898 AutocompleteInput input(
838 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(), 899 ASCIIToUTF16("foo"), base::string16::npos, std::string(), GURL(),
839 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true, 900 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, true,
840 ChromeAutocompleteSchemeClassifier(profile_.get())); 901 TestSchemeClassifier());
841 autocomplete_->Start(input, false); 902 autocomplete_->Start(input, false);
842 EXPECT_TRUE(autocomplete_->matches().empty()); 903 EXPECT_TRUE(autocomplete_->matches().empty());
843 } 904 }
844 905
845 TEST_F(HistoryURLProviderTest, DoesNotInlinePunycodeMatches) { 906 TEST_F(HistoryURLProviderTest, DoesNotInlinePunycodeMatches) {
846 // A URL that matches due to a match in the punycode URL are allowed to be the 907 // A URL that matches due to a match in the punycode URL are allowed to be the
847 // default match if the URL doesn't get rendered as international characters 908 // default match if the URL doesn't get rendered as international characters
848 // in the given locale. 909 // in the given locale.
849 const UrlAndLegalDefault expected_true[] = { 910 const UrlAndLegalDefault expected_true[] = {
850 { "http://puny.xn--1lq90ic7f1rc.cn/", true }, 911 { "http://puny.xn--1lq90ic7f1rc.cn/", true },
(...skipping 14 matching lines...) Expand all
865 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_true, 926 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_true,
866 arraysize(expected_true)); 927 arraysize(expected_true));
867 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false, 928 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false,
868 expected_true, arraysize(expected_true)); 929 expected_true, arraysize(expected_true));
869 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false, 930 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false,
870 expected_true, arraysize(expected_true)); 931 expected_true, arraysize(expected_true));
871 // Set the language so the punycode part of the URL is rendered as 932 // Set the language so the punycode part of the URL is rendered as
872 // international characters. Then this match should not be allowed to be 933 // international characters. Then this match should not be allowed to be
873 // the default match if the inline autocomplete text starts in the middle 934 // the default match if the inline autocomplete text starts in the middle
874 // of the international characters. 935 // of the international characters.
875 profile_->GetPrefs()->SetString(prefs::kAcceptLanguages, "zh-CN"); 936 EXPECT_CALL(*client_, GetAcceptLanguages())
937 .WillRepeatedly(testing::Return("zh-CN"));
876 RunTest(ASCIIToUTF16("pun"), std::string(), false, expected_true, 938 RunTest(ASCIIToUTF16("pun"), std::string(), false, expected_true,
877 arraysize(expected_true)); 939 arraysize(expected_true));
878 RunTest(ASCIIToUTF16("puny."), std::string(), false, expected_true, 940 RunTest(ASCIIToUTF16("puny."), std::string(), false, expected_true,
879 arraysize(expected_true)); 941 arraysize(expected_true));
880 RunTest(ASCIIToUTF16("puny.x"), std::string(), false, expected_false, 942 RunTest(ASCIIToUTF16("puny.x"), std::string(), false, expected_false,
881 arraysize(expected_false)); 943 arraysize(expected_false));
882 RunTest(ASCIIToUTF16("puny.xn"), std::string(), false, expected_false, 944 RunTest(ASCIIToUTF16("puny.xn"), std::string(), false, expected_false,
883 arraysize(expected_false)); 945 arraysize(expected_false));
884 RunTest(ASCIIToUTF16("puny.xn--"), std::string(), false, expected_false, 946 RunTest(ASCIIToUTF16("puny.xn--"), std::string(), false, expected_false,
885 arraysize(expected_false)); 947 arraysize(expected_false));
886 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_false, 948 RunTest(ASCIIToUTF16("puny.xn--1l"), std::string(), false, expected_false,
887 arraysize(expected_false)); 949 arraysize(expected_false));
888 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false, 950 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc"), std::string(), false,
889 expected_true, arraysize(expected_true)); 951 expected_true, arraysize(expected_true));
890 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false, 952 RunTest(ASCIIToUTF16("puny.xn--1lq90ic7f1rc."), std::string(), false,
891 expected_true, arraysize(expected_true)); 953 expected_true, arraysize(expected_true));
892 } 954 }
893 955
894 TEST_F(HistoryURLProviderTest, CullSearchResults) { 956 TEST_F(HistoryURLProviderTest, CullSearchResults) {
895 // Set up a default search engine. 957 // Set up a default search engine.
896 TemplateURLData data; 958 TemplateURLData data;
897 data.SetShortName(ASCIIToUTF16("TestEngine")); 959 data.SetShortName(ASCIIToUTF16("TestEngine"));
898 data.SetKeyword(ASCIIToUTF16("TestEngine")); 960 data.SetKeyword(ASCIIToUTF16("TestEngine"));
899 data.SetURL("http://testsearch.com/?q={searchTerms}"); 961 data.SetURL("http://testsearch.com/?q={searchTerms}");
900 TemplateURLService* template_url_service = 962 TemplateURLService* template_url_service = client_->GetTemplateURLService();
901 TemplateURLServiceFactory::GetForProfile(profile_.get());
902 TemplateURL* template_url = new TemplateURL(data); 963 TemplateURL* template_url = new TemplateURL(data);
903 template_url_service->Add(template_url); 964 template_url_service->Add(template_url);
904 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 965 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
905 template_url_service->Load(); 966 template_url_service->Load();
906 967
907 // URLs we will be using, plus the visit counts they will initially get 968 // URLs we will be using, plus the visit counts they will initially get
908 // (the redirect set below will also increment the visit counts). We want 969 // (the redirect set below will also increment the visit counts). We want
909 // the results to be in A,B,C order. Note also that our visit counts are 970 // the results to be in A,B,C order. Note also that our visit counts are
910 // all high enough so that domain synthesizing won't get triggered. 971 // all high enough so that domain synthesizing won't get triggered.
911 struct TestCase { 972 struct TestCase {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 }; 1057 };
997 for (size_t i = 0; i < arraysize(test_cases); ++i) { 1058 for (size_t i = 0; i < arraysize(test_cases); ++i) {
998 SCOPED_TRACE(testing::Message() << "Index " << i << " input: " 1059 SCOPED_TRACE(testing::Message() << "Index " << i << " input: "
999 << test_cases[i].input << ", trim_http: " 1060 << test_cases[i].input << ", trim_http: "
1000 << test_cases[i].trim_http); 1061 << test_cases[i].trim_http);
1001 1062
1002 AutocompleteInput input( 1063 AutocompleteInput input(
1003 ASCIIToUTF16(test_cases[i].input), base::string16::npos, std::string(), 1064 ASCIIToUTF16(test_cases[i].input), base::string16::npos, std::string(),
1004 GURL("about:blank"), metrics::OmniboxEventProto::INVALID_SPEC, false, 1065 GURL("about:blank"), metrics::OmniboxEventProto::INVALID_SPEC, false,
1005 false, true, true, false, 1066 false, true, true, false,
1006 ChromeAutocompleteSchemeClassifier(profile_.get())); 1067 TestSchemeClassifier());
1007 AutocompleteMatch match(autocomplete_->SuggestExactInput( 1068 AutocompleteMatch match(autocomplete_->SuggestExactInput(
1008 input, input.canonicalized_url(), test_cases[i].trim_http)); 1069 input, input.canonicalized_url(), test_cases[i].trim_http));
1009 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents); 1070 EXPECT_EQ(ASCIIToUTF16(test_cases[i].contents), match.contents);
1010 for (size_t match_index = 0; match_index < match.contents_class.size(); 1071 for (size_t match_index = 0; match_index < match.contents_class.size();
1011 ++match_index) { 1072 ++match_index) {
1012 EXPECT_EQ(test_cases[i].offsets[match_index], 1073 EXPECT_EQ(test_cases[i].offsets[match_index],
1013 match.contents_class[match_index].offset); 1074 match.contents_class[match_index].offset);
1014 EXPECT_EQ(ACMatchClassification::URL | 1075 EXPECT_EQ(ACMatchClassification::URL |
1015 (match_index == test_cases[i].match_classification_index ? 1076 (match_index == test_cases[i].match_classification_index ?
1016 ACMatchClassification::MATCH : 0), 1077 ACMatchClassification::MATCH : 0),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 // the default experimental scoring. 1170 // the default experimental scoring.
1110 autocomplete_->scoring_params_.experimental_scoring_enabled = true; 1171 autocomplete_->scoring_params_.experimental_scoring_enabled = true;
1111 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), 1172 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input),
1112 std::string(), false, output, max_matches)); 1173 std::string(), false, output, max_matches));
1113 for (int j = 0; j < max_matches; ++j) { 1174 for (int j = 0; j < max_matches; ++j) {
1114 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, 1175 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance,
1115 matches_[j].relevance); 1176 matches_[j].relevance);
1116 } 1177 }
1117 } 1178 }
1118 } 1179 }
OLDNEW
« components/omnibox/browser/DEPS ('K') | « components/omnibox/browser/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698