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

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

Issue 343523003: Remove AutocompleteInput Type and PageClassification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 | 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/autocomplete/autocomplete_match.h" 8 #include "chrome/browser/autocomplete/autocomplete_match.h"
9 #include "chrome/browser/autocomplete/keyword_provider.h" 9 #include "chrome/browser/autocomplete/keyword_provider.h"
10 #include "chrome/browser/search_engines/template_url.h" 10 #include "chrome/browser/search_engines/template_url.h"
11 #include "chrome/browser/search_engines/template_url_service.h" 11 #include "chrome/browser/search_engines/template_url_service.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/testing_browser_process.h" 13 #include "chrome/test/base/testing_browser_process.h"
14 #include "components/metrics/proto/omnibox_event.pb.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 using base::ASCIIToUTF16; 18 using base::ASCIIToUTF16;
18 19
19 class KeywordProviderTest : public testing::Test { 20 class KeywordProviderTest : public testing::Test {
20 protected: 21 protected:
21 template<class ResultType> 22 template<class ResultType>
22 struct MatchType { 23 struct MatchType {
23 const ResultType member; 24 const ResultType member;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 template<class ResultType> 75 template<class ResultType>
75 void KeywordProviderTest::RunTest( 76 void KeywordProviderTest::RunTest(
76 TestData<ResultType>* keyword_cases, 77 TestData<ResultType>* keyword_cases,
77 int num_cases, 78 int num_cases,
78 ResultType AutocompleteMatch::* member) { 79 ResultType AutocompleteMatch::* member) {
79 ACMatches matches; 80 ACMatches matches;
80 for (int i = 0; i < num_cases; ++i) { 81 for (int i = 0; i < num_cases; ++i) {
81 SCOPED_TRACE(keyword_cases[i].input); 82 SCOPED_TRACE(keyword_cases[i].input);
82 AutocompleteInput input(keyword_cases[i].input, base::string16::npos, 83 AutocompleteInput input(keyword_cases[i].input, base::string16::npos,
83 base::string16(), GURL(), 84 base::string16(), GURL(),
84 AutocompleteInput::INVALID_SPEC, true, 85 metrics::OmniboxEventProto::INVALID_SPEC, true,
85 false, true, true); 86 false, true, true);
86 kw_provider_->Start(input, false); 87 kw_provider_->Start(input, false);
87 EXPECT_TRUE(kw_provider_->done()); 88 EXPECT_TRUE(kw_provider_->done());
88 matches = kw_provider_->matches(); 89 matches = kw_provider_->matches();
89 ASSERT_EQ(keyword_cases[i].num_results, matches.size()); 90 ASSERT_EQ(keyword_cases[i].num_results, matches.size());
90 for (size_t j = 0; j < matches.size(); ++j) { 91 for (size_t j = 0; j < matches.size(); ++j) {
91 EXPECT_EQ(keyword_cases[i].output[j].member, matches[j].*member); 92 EXPECT_EQ(keyword_cases[i].output[j].member, matches[j].*member);
92 EXPECT_EQ(keyword_cases[i].output[j].allowed_to_be_default_match, 93 EXPECT_EQ(keyword_cases[i].output[j].allowed_to_be_default_match,
93 matches[j].allowed_to_be_default_match); 94 matches[j].allowed_to_be_default_match);
94 } 95 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // Extra space after keyword, no trailing space, cursor in the middle. 317 // Extra space after keyword, no trailing space, cursor in the middle.
317 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u }, 318 { "aa foo", 5u, true, "aa.com?foo={searchTerms}", "foo", 1u },
318 319
319 // Disallow exact keyword match. 320 // Disallow exact keyword match.
320 { "aa foo", base::string16::npos, false, "", "aa foo", 321 { "aa foo", base::string16::npos, false, "", "aa foo",
321 base::string16::npos }, 322 base::string16::npos },
322 }; 323 };
323 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { 324 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
324 AutocompleteInput input(ASCIIToUTF16(cases[i].text), 325 AutocompleteInput input(ASCIIToUTF16(cases[i].text),
325 cases[i].cursor_position, base::string16(), GURL(), 326 cases[i].cursor_position, base::string16(), GURL(),
326 AutocompleteInput::INVALID_SPEC, false, false, 327 metrics::OmniboxEventProto::INVALID_SPEC, false,
327 cases[i].allow_exact_keyword_match, true); 328 false, cases[i].allow_exact_keyword_match, true);
328 const TemplateURL* url = 329 const TemplateURL* url =
329 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(), 330 KeywordProvider::GetSubstitutingTemplateURLForInput(model_.get(),
330 &input); 331 &input);
331 if (cases[i].expected_url.empty()) 332 if (cases[i].expected_url.empty())
332 EXPECT_FALSE(url); 333 EXPECT_FALSE(url);
333 else 334 else
334 EXPECT_EQ(cases[i].expected_url, url->url()); 335 EXPECT_EQ(cases[i].expected_url, url->url());
335 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text()); 336 EXPECT_EQ(ASCIIToUTF16(cases[i].updated_text), input.text());
336 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position()); 337 EXPECT_EQ(cases[i].updated_cursor_position, input.cursor_position());
337 } 338 }
338 } 339 }
339 340
340 // If extra query params are specified on the command line, they should be 341 // If extra query params are specified on the command line, they should be
341 // reflected (only) in the default search provider's destination URL. 342 // reflected (only) in the default search provider's destination URL.
342 TEST_F(KeywordProviderTest, ExtraQueryParams) { 343 TEST_F(KeywordProviderTest, ExtraQueryParams) {
343 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 344 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
344 switches::kExtraSearchQueryParams, "a=b"); 345 switches::kExtraSearchQueryParams, "a=b");
345 346
346 TestData<GURL> url_cases[] = { 347 TestData<GURL> url_cases[] = {
347 { ASCIIToUTF16("a 1 2 3"), 3, 348 { ASCIIToUTF16("a 1 2 3"), 3,
348 { { GURL("aa.com?a=b&foo=1+2+3"), false }, 349 { { GURL("aa.com?a=b&foo=1+2+3"), false },
349 { GURL("bogus URL 1+2+3"), false }, 350 { GURL("bogus URL 1+2+3"), false },
350 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } }, 351 { GURL("http://aaaa/?aaaa=1&b=1+2+3&c"), false } } },
351 }; 352 };
352 353
353 RunTest<GURL>(url_cases, arraysize(url_cases), 354 RunTest<GURL>(url_cases, arraysize(url_cases),
354 &AutocompleteMatch::destination_url); 355 &AutocompleteMatch::destination_url);
355 } 356 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider_unittest.cc ('k') | chrome/browser/autocomplete/search_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698