OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/physical_web_provider.h" | 5 #include "components/omnibox/browser/physical_web_provider.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 metadata_item.description = "Example description " + item_id; | 129 metadata_item.description = "Example description " + item_id; |
130 } | 130 } |
131 return metadata_list; | 131 return metadata_list; |
132 } | 132 } |
133 | 133 |
134 // Construct an AutocompleteInput to represent tapping the omnibox from the | 134 // Construct an AutocompleteInput to represent tapping the omnibox from the |
135 // new tab page. | 135 // new tab page. |
136 static AutocompleteInput CreateInputForNTP() { | 136 static AutocompleteInput CreateInputForNTP() { |
137 return AutocompleteInput( | 137 return AutocompleteInput( |
138 base::string16(), base::string16::npos, std::string(), GURL(), | 138 base::string16(), base::string16::npos, std::string(), GURL(), |
| 139 base::string16(), |
139 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 140 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
140 false, false, true, true, true, TestSchemeClassifier()); | 141 false, false, true, true, true, TestSchemeClassifier()); |
141 } | 142 } |
142 | 143 |
143 // Construct an AutocompleteInput to represent tapping the omnibox with |url| | 144 // Construct an AutocompleteInput to represent tapping the omnibox with |url| |
144 // as the current web page. | 145 // as the current web page. |
145 static AutocompleteInput CreateInputWithCurrentUrl(const std::string& url) { | 146 static AutocompleteInput CreateInputWithCurrentUrl(const std::string& url) { |
146 return AutocompleteInput(base::UTF8ToUTF16(url), base::string16::npos, | 147 return AutocompleteInput(base::UTF8ToUTF16(url), base::string16::npos, |
147 std::string(), GURL(url), | 148 std::string(), GURL(url), base::string16(), |
148 metrics::OmniboxEventProto::OTHER, false, false, | 149 metrics::OmniboxEventProto::OTHER, false, false, |
149 true, true, true, TestSchemeClassifier()); | 150 true, true, true, TestSchemeClassifier()); |
150 } | 151 } |
151 | 152 |
152 // For a given |match|, check that the destination URL, contents string, | 153 // For a given |match|, check that the destination URL, contents string, |
153 // description string, and default match state agree with the values specified | 154 // description string, and default match state agree with the values specified |
154 // in |url|, |contents|, |description|, and |allowed_to_be_default_match|. | 155 // in |url|, |contents|, |description|, and |allowed_to_be_default_match|. |
155 static void ValidateMatch(const AutocompleteMatch& match, | 156 static void ValidateMatch(const AutocompleteMatch& match, |
156 const std::string& url, | 157 const std::string& url, |
157 const std::string& contents, | 158 const std::string& contents, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 client_->GetFakePhysicalWebDataSource(); | 319 client_->GetFakePhysicalWebDataSource(); |
319 EXPECT_TRUE(data_source); | 320 EXPECT_TRUE(data_source); |
320 | 321 |
321 data_source->SetMetadataList(CreateMetadata(1)); | 322 data_source->SetMetadataList(CreateMetadata(1)); |
322 | 323 |
323 // Construct an AutocompleteInput to simulate user input in the omnibox input | 324 // Construct an AutocompleteInput to simulate user input in the omnibox input |
324 // field. The provider should not generate any matches. | 325 // field. The provider should not generate any matches. |
325 std::string text("user input"); | 326 std::string text("user input"); |
326 const AutocompleteInput input( | 327 const AutocompleteInput input( |
327 base::UTF8ToUTF16(text), text.length(), std::string(), GURL(), | 328 base::UTF8ToUTF16(text), text.length(), std::string(), GURL(), |
| 329 base::string16(), |
328 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 330 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
329 true, false, true, true, false, TestSchemeClassifier()); | 331 true, false, true, true, false, TestSchemeClassifier()); |
330 provider_->Start(input, false); | 332 provider_->Start(input, false); |
331 | 333 |
332 EXPECT_TRUE(provider_->matches().empty()); | 334 EXPECT_TRUE(provider_->matches().empty()); |
333 } | 335 } |
334 | 336 |
335 TEST_F(PhysicalWebProviderTest, TestEmptyInputAfterTyping) { | 337 TEST_F(PhysicalWebProviderTest, TestEmptyInputAfterTyping) { |
336 FakePhysicalWebDataSource* data_source = | 338 FakePhysicalWebDataSource* data_source = |
337 client_->GetFakePhysicalWebDataSource(); | 339 client_->GetFakePhysicalWebDataSource(); |
338 EXPECT_TRUE(data_source); | 340 EXPECT_TRUE(data_source); |
339 | 341 |
340 data_source->SetMetadataList(CreateMetadata(1)); | 342 data_source->SetMetadataList(CreateMetadata(1)); |
341 | 343 |
342 // Construct an AutocompleteInput to simulate a blank input field, as if the | 344 // Construct an AutocompleteInput to simulate a blank input field, as if the |
343 // user typed a query and then deleted it. The provider should generate | 345 // user typed a query and then deleted it. The provider should generate |
344 // suggestions for the zero-suggest case. No default match should be created. | 346 // suggestions for the zero-suggest case. No default match should be created. |
345 const AutocompleteInput input( | 347 const AutocompleteInput input( |
346 base::string16(), 0, std::string(), GURL(), | 348 base::string16(), 0, std::string(), GURL(), base::string16(), |
347 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 349 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
348 true, false, true, true, false, TestSchemeClassifier()); | 350 true, false, true, true, false, TestSchemeClassifier()); |
349 provider_->Start(input, false); | 351 provider_->Start(input, false); |
350 | 352 |
351 size_t metadata_match_count = 0; | 353 size_t metadata_match_count = 0; |
352 size_t default_match_count = 0; | 354 size_t default_match_count = 0; |
353 for (const auto& match : provider_->matches()) { | 355 for (const auto& match : provider_->matches()) { |
354 if (match.type == AutocompleteMatchType::PHYSICAL_WEB) { | 356 if (match.type == AutocompleteMatchType::PHYSICAL_WEB) { |
355 ++metadata_match_count; | 357 ++metadata_match_count; |
356 } else { | 358 } else { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 EXPECT_TRUE(provider_->matches().empty()); | 432 EXPECT_TRUE(provider_->matches().empty()); |
431 } | 433 } |
432 | 434 |
433 TEST_F(PhysicalWebProviderTest, TestNearbyURLCountHistograms) { | 435 TEST_F(PhysicalWebProviderTest, TestNearbyURLCountHistograms) { |
434 FakePhysicalWebDataSource* data_source = | 436 FakePhysicalWebDataSource* data_source = |
435 client_->GetFakePhysicalWebDataSource(); | 437 client_->GetFakePhysicalWebDataSource(); |
436 EXPECT_TRUE(data_source); | 438 EXPECT_TRUE(data_source); |
437 | 439 |
438 AutocompleteInput zero_suggest_input(CreateInputForNTP()); | 440 AutocompleteInput zero_suggest_input(CreateInputForNTP()); |
439 AutocompleteInput after_typing_input( | 441 AutocompleteInput after_typing_input( |
440 base::UTF8ToUTF16("Example"), 7, std::string(), GURL(), | 442 base::UTF8ToUTF16("Example"), 7, std::string(), GURL(), base::string16(), |
441 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 443 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
442 true, false, true, true, false, TestSchemeClassifier()); | 444 true, false, true, true, false, TestSchemeClassifier()); |
443 | 445 |
444 data_source->SetMetadataList(CreateMetadata(3)); | 446 data_source->SetMetadataList(CreateMetadata(3)); |
445 | 447 |
446 { | 448 { |
447 // Simulate the user selecting a suggestion when the omnibox is empty | 449 // Simulate the user selecting a suggestion when the omnibox is empty |
448 // (zero suggest case). Both histograms should record the same counts. | 450 // (zero suggest case). Both histograms should record the same counts. |
449 base::HistogramTester histogram_tester; | 451 base::HistogramTester histogram_tester; |
450 ProvidersInfo provider_info; | 452 ProvidersInfo provider_info; |
(...skipping 29 matching lines...) Expand all Loading... |
480 "Omnibox.PhysicalWebProvider.SuggestionUsedWithoutOmniboxFocus", 0, 1); | 482 "Omnibox.PhysicalWebProvider.SuggestionUsedWithoutOmniboxFocus", 0, 1); |
481 } | 483 } |
482 } | 484 } |
483 | 485 |
484 TEST_F(PhysicalWebProviderTest, TestNearbyURLCountAfterTypingWithoutFocus) { | 486 TEST_F(PhysicalWebProviderTest, TestNearbyURLCountAfterTypingWithoutFocus) { |
485 FakePhysicalWebDataSource* data_source = | 487 FakePhysicalWebDataSource* data_source = |
486 client_->GetFakePhysicalWebDataSource(); | 488 client_->GetFakePhysicalWebDataSource(); |
487 EXPECT_TRUE(data_source); | 489 EXPECT_TRUE(data_source); |
488 | 490 |
489 AutocompleteInput after_typing_input( | 491 AutocompleteInput after_typing_input( |
490 base::UTF8ToUTF16("Example"), 7, std::string(), GURL(), | 492 base::UTF8ToUTF16("Example"), 7, std::string(), GURL(), base::string16(), |
491 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 493 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
492 true, false, true, true, false, TestSchemeClassifier()); | 494 true, false, true, true, false, TestSchemeClassifier()); |
493 | 495 |
494 data_source->SetMetadataList(CreateMetadata(3)); | 496 data_source->SetMetadataList(CreateMetadata(3)); |
495 | 497 |
496 { | 498 { |
497 // Simulate selecting a suggestion without focusing the omnibox first. | 499 // Simulate selecting a suggestion without focusing the omnibox first. |
498 base::HistogramTester histogram_tester; | 500 base::HistogramTester histogram_tester; |
499 ProvidersInfo provider_info; | 501 ProvidersInfo provider_info; |
500 | 502 |
501 provider_->Start(after_typing_input, false); | 503 provider_->Start(after_typing_input, false); |
502 provider_->AddProviderInfo(&provider_info); | 504 provider_->AddProviderInfo(&provider_info); |
503 | 505 |
504 histogram_tester.ExpectUniqueSample( | 506 histogram_tester.ExpectUniqueSample( |
505 "Omnibox.SuggestionUsed.NearbyURLCount.AtMatchCreation", 3, 1); | 507 "Omnibox.SuggestionUsed.NearbyURLCount.AtMatchCreation", 3, 1); |
506 histogram_tester.ExpectTotalCount( | 508 histogram_tester.ExpectTotalCount( |
507 "Omnibox.SuggestionUsed.NearbyURLCount.AtFocus", 0); | 509 "Omnibox.SuggestionUsed.NearbyURLCount.AtFocus", 0); |
508 histogram_tester.ExpectUniqueSample( | 510 histogram_tester.ExpectUniqueSample( |
509 "Omnibox.PhysicalWebProvider.SuggestionUsedWithoutOmniboxFocus", 1, 1); | 511 "Omnibox.PhysicalWebProvider.SuggestionUsedWithoutOmniboxFocus", 1, 1); |
510 } | 512 } |
511 } | 513 } |
OLD | NEW |