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

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

Issue 18878007: Omnibox: Make the Controller Reorder Matches for Inlining (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Lacks -> has Created 7 years, 4 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 | Annotate | Revision Log
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/autocomplete_provider.h" 5 #include "chrome/browser/autocomplete/autocomplete_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
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"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 void TestProvider::AddResultsWithSearchTermsArgs( 121 void TestProvider::AddResultsWithSearchTermsArgs(
122 int start_at, 122 int start_at,
123 int num, 123 int num,
124 AutocompleteMatch::Type type, 124 AutocompleteMatch::Type type,
125 const TemplateURLRef::SearchTermsArgs& search_terms_args) { 125 const TemplateURLRef::SearchTermsArgs& search_terms_args) {
126 for (int i = start_at; i < num; i++) { 126 for (int i = start_at; i < num; i++) {
127 AutocompleteMatch match(this, relevance_ - i, false, type); 127 AutocompleteMatch match(this, relevance_ - i, false, type);
128 128
129 match.fill_into_edit = prefix_ + UTF8ToUTF16(base::IntToString(i)); 129 match.fill_into_edit = prefix_ + UTF8ToUTF16(base::IntToString(i));
130 match.destination_url = GURL(UTF16ToUTF8(match.fill_into_edit)); 130 match.destination_url = GURL(UTF16ToUTF8(match.fill_into_edit));
131 match.allowed_to_be_default_match = true;
131 132
132 match.contents = match.fill_into_edit; 133 match.contents = match.fill_into_edit;
133 match.contents_class.push_back( 134 match.contents_class.push_back(
134 ACMatchClassification(0, ACMatchClassification::NONE)); 135 ACMatchClassification(0, ACMatchClassification::NONE));
135 match.description = match.fill_into_edit; 136 match.description = match.fill_into_edit;
136 match.description_class.push_back( 137 match.description_class.push_back(
137 ACMatchClassification(0, ACMatchClassification::NONE)); 138 ACMatchClassification(0, ACMatchClassification::NONE));
138 match.search_terms_args.reset( 139 match.search_terms_args.reset(
139 new TemplateURLRef::SearchTermsArgs(search_terms_args)); 140 new TemplateURLRef::SearchTermsArgs(search_terms_args));
140 if (!match_keyword_.empty()) { 141 if (!match_keyword_.empty()) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 void AutocompleteProviderTest::RunTest() { 339 void AutocompleteProviderTest::RunTest() {
339 RunQuery(ASCIIToUTF16("a")); 340 RunQuery(ASCIIToUTF16("a"));
340 } 341 }
341 342
342 void AutocompleteProviderTest::RunRedundantKeywordTest( 343 void AutocompleteProviderTest::RunRedundantKeywordTest(
343 const KeywordTestData* match_data, 344 const KeywordTestData* match_data,
344 size_t size) { 345 size_t size) {
345 ACMatches matches; 346 ACMatches matches;
346 for (size_t i = 0; i < size; ++i) { 347 for (size_t i = 0; i < size; ++i) {
347 AutocompleteMatch match; 348 AutocompleteMatch match;
349 match.relevance = 1000;
msw 2013/08/07 20:09:21 where does 1000 come from? why is it needed?
Mark P 2013/08/07 22:13:05 It needs to be set to something because nowadays A
350 match.allowed_to_be_default_match = true;
348 match.fill_into_edit = match_data[i].fill_into_edit; 351 match.fill_into_edit = match_data[i].fill_into_edit;
349 match.transition = content::PAGE_TRANSITION_KEYWORD; 352 match.transition = content::PAGE_TRANSITION_KEYWORD;
350 match.keyword = match_data[i].keyword; 353 match.keyword = match_data[i].keyword;
351 matches.push_back(match); 354 matches.push_back(match);
352 } 355 }
353 356
354 AutocompleteResult result; 357 AutocompleteResult result;
355 result.AppendMatches(matches); 358 result.AppendMatches(matches);
356 controller_->UpdateAssociatedKeywords(&result); 359 controller_->UpdateAssociatedKeywords(&result);
357 360
358 for (size_t j = 0; j < result.size(); ++j) { 361 for (size_t j = 0; j < result.size(); ++j) {
359 EXPECT_EQ(match_data[j].expected_keyword_result, 362 EXPECT_EQ(match_data[j].expected_keyword_result,
360 result.match_at(j)->associated_keyword.get() != NULL); 363 result.match_at(j)->associated_keyword.get() != NULL);
361 } 364 }
362 } 365 }
363 366
364 void AutocompleteProviderTest::RunAssistedQueryStatsTest( 367 void AutocompleteProviderTest::RunAssistedQueryStatsTest(
365 const AssistedQueryStatsTestData* aqs_test_data, 368 const AssistedQueryStatsTestData* aqs_test_data,
366 size_t size) { 369 size_t size) {
367 // Prepare input. 370 // Prepare input.
368 const size_t kMaxRelevance = 1000; 371 const size_t kMaxRelevance = 1000;
369 ACMatches matches; 372 ACMatches matches;
370 for (size_t i = 0; i < size; ++i) { 373 for (size_t i = 0; i < size; ++i) {
371 AutocompleteMatch match(NULL, kMaxRelevance - i, false, 374 AutocompleteMatch match(NULL, kMaxRelevance - i, false,
372 aqs_test_data[i].match_type); 375 aqs_test_data[i].match_type);
376 match.allowed_to_be_default_match = true;
373 match.keyword = ASCIIToUTF16(kTestTemplateURLKeyword); 377 match.keyword = ASCIIToUTF16(kTestTemplateURLKeyword);
374 match.search_terms_args.reset( 378 match.search_terms_args.reset(
375 new TemplateURLRef::SearchTermsArgs(string16())); 379 new TemplateURLRef::SearchTermsArgs(string16()));
376 matches.push_back(match); 380 matches.push_back(match);
377 } 381 }
378 result_.Reset(); 382 result_.Reset();
379 result_.AppendMatches(matches); 383 result_.AppendMatches(matches);
380 384
381 // Update AQS. 385 // Update AQS.
382 controller_->UpdateAssistedQueryStats(&result_); 386 controller_->UpdateAssistedQueryStats(&result_);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 EXPECT_EQ("http://keyword/test", 506 EXPECT_EQ("http://keyword/test",
503 result_.match_at(0)->destination_url.possibly_invalid_spec()); 507 result_.match_at(0)->destination_url.possibly_invalid_spec());
504 EXPECT_EQ("http://defaultturl/k%20test?a=b", 508 EXPECT_EQ("http://defaultturl/k%20test?a=b",
505 result_.match_at(1)->destination_url.possibly_invalid_spec()); 509 result_.match_at(1)->destination_url.possibly_invalid_spec());
506 } 510 }
507 511
508 // Test that redundant associated keywords are removed. 512 // Test that redundant associated keywords are removed.
509 TEST_F(AutocompleteProviderTest, RedundantKeywordsIgnoredInResult) { 513 TEST_F(AutocompleteProviderTest, RedundantKeywordsIgnoredInResult) {
510 ResetControllerWithKeywordProvider(); 514 ResetControllerWithKeywordProvider();
511 515
512 // Get the controller's internal members in the correct state.
msw 2013/08/07 20:09:21 why is this no longer needed?
Mark P 2013/08/07 22:13:05 It apparently was never needed (or at least not ne
513 RunQuery(ASCIIToUTF16("fo"));
514
515 { 516 {
516 KeywordTestData duplicate_url[] = { 517 KeywordTestData duplicate_url[] = {
517 { ASCIIToUTF16("fo"), string16(), false }, 518 { ASCIIToUTF16("fo"), string16(), false },
518 { ASCIIToUTF16("foo.com"), string16(), true }, 519 { ASCIIToUTF16("foo.com"), string16(), true },
519 { ASCIIToUTF16("foo.com"), string16(), false } 520 { ASCIIToUTF16("foo.com"), string16(), false }
520 }; 521 };
521 522
522 SCOPED_TRACE("Duplicate url"); 523 SCOPED_TRACE("Duplicate url");
523 RunRedundantKeywordTest(duplicate_url, ARRAYSIZE_UNSAFE(duplicate_url)); 524 RunRedundantKeywordTest(duplicate_url, ARRAYSIZE_UNSAFE(duplicate_url));
524 } 525 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0&", url.path()); 632 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0&", url.path());
632 633
633 // Test field trial triggered bit set. 634 // Test field trial triggered bit set.
634 controller_->search_provider_->field_trial_triggered_in_session_ = true; 635 controller_->search_provider_->field_trial_triggered_in_session_ = true;
635 EXPECT_TRUE( 636 EXPECT_TRUE(
636 controller_->search_provider_->field_trial_triggered_in_session()); 637 controller_->search_provider_->field_trial_triggered_in_session());
637 url = controller_->GetDestinationURL(match, 638 url = controller_->GetDestinationURL(match,
638 base::TimeDelta::FromMilliseconds(2456)); 639 base::TimeDelta::FromMilliseconds(2456));
639 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1&", url.path()); 640 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1&", url.path());
640 } 641 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698