OLD | NEW |
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/builtin_provider.h" | 5 #include "components/omnibox/browser/builtin_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 void TearDown() override { provider_ = NULL; } | 96 void TearDown() override { provider_ = NULL; } |
97 | 97 |
98 void RunTest(const TestData cases[], size_t num_cases) { | 98 void RunTest(const TestData cases[], size_t num_cases) { |
99 ACMatches matches; | 99 ACMatches matches; |
100 for (size_t i = 0; i < num_cases; ++i) { | 100 for (size_t i = 0; i < num_cases; ++i) { |
101 SCOPED_TRACE(base::StringPrintf( | 101 SCOPED_TRACE(base::StringPrintf( |
102 "case %" PRIuS ": %s", i, base::UTF16ToUTF8(cases[i].input).c_str())); | 102 "case %" PRIuS ": %s", i, base::UTF16ToUTF8(cases[i].input).c_str())); |
103 const AutocompleteInput input( | 103 const AutocompleteInput input( |
104 cases[i].input, base::string16::npos, std::string(), GURL(), | 104 cases[i].input, base::string16::npos, std::string(), GURL(), |
105 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, | 105 base::string16(), metrics::OmniboxEventProto::INVALID_SPEC, true, |
106 false, TestSchemeClassifier()); | 106 false, true, true, false, TestSchemeClassifier()); |
107 provider_->Start(input, false); | 107 provider_->Start(input, false); |
108 EXPECT_TRUE(provider_->done()); | 108 EXPECT_TRUE(provider_->done()); |
109 matches = provider_->matches(); | 109 matches = provider_->matches(); |
110 EXPECT_EQ(cases[i].num_results, matches.size()); | 110 EXPECT_EQ(cases[i].num_results, matches.size()); |
111 if (matches.size() == cases[i].num_results) { | 111 if (matches.size() == cases[i].num_results) { |
112 for (size_t j = 0; j < cases[i].num_results; ++j) { | 112 for (size_t j = 0; j < cases[i].num_results; ++j) { |
113 EXPECT_EQ(cases[i].output[j], matches[j].destination_url); | 113 EXPECT_EQ(cases[i].output[j], matches[j].destination_url); |
114 EXPECT_FALSE(matches[j].allowed_to_be_default_match); | 114 EXPECT_FALSE(matches[j].allowed_to_be_default_match); |
115 } | 115 } |
116 } | 116 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("?q"), 0, {}}, | 290 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("?q"), 0, {}}, |
291 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("#r"), 0, {}}, | 291 {kAboutBlank.substr(0, 9) + ASCIIToUTF16("#r"), 0, {}}, |
292 }; | 292 }; |
293 | 293 |
294 RunTest(about_blank_cases, arraysize(about_blank_cases)); | 294 RunTest(about_blank_cases, arraysize(about_blank_cases)); |
295 } | 295 } |
296 | 296 |
297 TEST_F(BuiltinProviderTest, DoesNotSupportMatchesOnFocus) { | 297 TEST_F(BuiltinProviderTest, DoesNotSupportMatchesOnFocus) { |
298 const AutocompleteInput input( | 298 const AutocompleteInput input( |
299 ASCIIToUTF16("chrome://m"), base::string16::npos, std::string(), GURL(), | 299 ASCIIToUTF16("chrome://m"), base::string16::npos, std::string(), GURL(), |
300 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, true, | 300 base::string16(), metrics::OmniboxEventProto::INVALID_SPEC, true, false, |
301 TestSchemeClassifier()); | 301 true, true, true, TestSchemeClassifier()); |
302 provider_->Start(input, false); | 302 provider_->Start(input, false); |
303 EXPECT_TRUE(provider_->matches().empty()); | 303 EXPECT_TRUE(provider_->matches().empty()); |
304 } | 304 } |
305 | 305 |
306 TEST_F(BuiltinProviderTest, Subpages) { | 306 TEST_F(BuiltinProviderTest, Subpages) { |
307 const base::string16 kSubpage = ASCIIToUTF16(kSubpageURL); | 307 const base::string16 kSubpage = ASCIIToUTF16(kSubpageURL); |
308 const base::string16 kPageOne = ASCIIToUTF16(kSubpageOne); | 308 const base::string16 kPageOne = ASCIIToUTF16(kSubpageOne); |
309 const base::string16 kPageTwo = ASCIIToUTF16(kSubpageTwo); | 309 const base::string16 kPageTwo = ASCIIToUTF16(kSubpageTwo); |
310 const base::string16 kPageThree = ASCIIToUTF16(kSubpageThree); | 310 const base::string16 kPageThree = ASCIIToUTF16(kSubpageThree); |
311 const GURL kURLOne(kSubpage + kPageOne); | 311 const GURL kURLOne(kSubpage + kPageOne); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 {kAbout + kSep + kHostB.substr(0, 2) + ASCIIToUTF16("a"), base::string16()}, | 377 {kAbout + kSep + kHostB.substr(0, 2) + ASCIIToUTF16("a"), base::string16()}, |
378 {kAbout + kSep + kHostB.substr(0, 2) + ASCIIToUTF16("+"), base::string16()}, | 378 {kAbout + kSep + kHostB.substr(0, 2) + ASCIIToUTF16("+"), base::string16()}, |
379 }; | 379 }; |
380 | 380 |
381 ACMatches matches; | 381 ACMatches matches; |
382 for (size_t i = 0; i < arraysize(cases); ++i) { | 382 for (size_t i = 0; i < arraysize(cases); ++i) { |
383 SCOPED_TRACE(base::StringPrintf( | 383 SCOPED_TRACE(base::StringPrintf( |
384 "case %" PRIuS ": %s", i, base::UTF16ToUTF8(cases[i].input).c_str())); | 384 "case %" PRIuS ": %s", i, base::UTF16ToUTF8(cases[i].input).c_str())); |
385 const AutocompleteInput input( | 385 const AutocompleteInput input( |
386 cases[i].input, base::string16::npos, std::string(), GURL(), | 386 cases[i].input, base::string16::npos, std::string(), GURL(), |
387 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, | 387 base::string16(), metrics::OmniboxEventProto::INVALID_SPEC, false, |
388 false, TestSchemeClassifier()); | 388 false, true, true, false, TestSchemeClassifier()); |
389 provider_->Start(input, false); | 389 provider_->Start(input, false); |
390 EXPECT_TRUE(provider_->done()); | 390 EXPECT_TRUE(provider_->done()); |
391 matches = provider_->matches(); | 391 matches = provider_->matches(); |
392 if (cases[i].expected_inline_autocompletion.empty()) { | 392 if (cases[i].expected_inline_autocompletion.empty()) { |
393 // If we're not expecting an inline autocompletion, make sure that no | 393 // If we're not expecting an inline autocompletion, make sure that no |
394 // matches are allowed_to_be_default. | 394 // matches are allowed_to_be_default. |
395 for (size_t j = 0; j < matches.size(); ++j) | 395 for (size_t j = 0; j < matches.size(); ++j) |
396 EXPECT_FALSE(matches[j].allowed_to_be_default_match); | 396 EXPECT_FALSE(matches[j].allowed_to_be_default_match); |
397 } else { | 397 } else { |
398 ASSERT_FALSE(matches.empty()); | 398 ASSERT_FALSE(matches.empty()); |
399 EXPECT_TRUE(matches[0].allowed_to_be_default_match); | 399 EXPECT_TRUE(matches[0].allowed_to_be_default_match); |
400 EXPECT_EQ(cases[i].expected_inline_autocompletion, | 400 EXPECT_EQ(cases[i].expected_inline_autocompletion, |
401 matches[0].inline_autocompletion); | 401 matches[0].inline_autocompletion); |
402 } | 402 } |
403 } | 403 } |
404 } | 404 } |
OLD | NEW |