| 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" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/histogram_tester.h" |
| 14 #include "components/metrics/proto/omnibox_event.pb.h" | 15 #include "components/metrics/proto/omnibox_event.pb.h" |
| 15 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" | 16 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
| 16 #include "components/omnibox/browser/omnibox_field_trial.h" | 17 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 17 #include "components/omnibox/browser/test_scheme_classifier.h" | 18 #include "components/omnibox/browser/test_scheme_classifier.h" |
| 18 #include "components/physical_web/data_source/fake_physical_web_data_source.h" | 19 #include "components/physical_web/data_source/fake_physical_web_data_source.h" |
| 19 #include "components/physical_web/data_source/physical_web_data_source.h" | 20 #include "components/physical_web/data_source/physical_web_data_source.h" |
| 20 #include "components/physical_web/data_source/physical_web_listener.h" | 21 #include "components/physical_web/data_source/physical_web_listener.h" |
| 21 #include "components/variations/entropy_provider.h" | 22 #include "components/variations/entropy_provider.h" |
| 22 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
| 23 #include "grit/components_strings.h" | 24 #include "grit/components_strings.h" |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 422 |
| 422 FakePhysicalWebDataSource* data_source = | 423 FakePhysicalWebDataSource* data_source = |
| 423 client_->GetFakePhysicalWebDataSource(); | 424 client_->GetFakePhysicalWebDataSource(); |
| 424 EXPECT_TRUE(data_source); | 425 EXPECT_TRUE(data_source); |
| 425 | 426 |
| 426 data_source->SetMetadataList(CreateMetadata(1)); | 427 data_source->SetMetadataList(CreateMetadata(1)); |
| 427 provider_->Start(CreateInputForNTP(), false); | 428 provider_->Start(CreateInputForNTP(), false); |
| 428 | 429 |
| 429 EXPECT_TRUE(provider_->matches().empty()); | 430 EXPECT_TRUE(provider_->matches().empty()); |
| 430 } | 431 } |
| 432 |
| 433 TEST_F(PhysicalWebProviderTest, TestNearbyURLCountHistograms) { |
| 434 FakePhysicalWebDataSource* data_source = |
| 435 client_->GetFakePhysicalWebDataSource(); |
| 436 EXPECT_TRUE(data_source); |
| 437 |
| 438 AutocompleteInput zero_suggest_input(CreateInputForNTP()); |
| 439 AutocompleteInput after_typing_input( |
| 440 base::UTF8ToUTF16("Example"), 7, std::string(), GURL(), |
| 441 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
| 442 true, false, true, true, false, TestSchemeClassifier()); |
| 443 |
| 444 data_source->SetMetadataList(CreateMetadata(3)); |
| 445 |
| 446 { |
| 447 // Simulate the user selecting a suggestion when the omnibox is empty |
| 448 // (zero suggest case). Both histograms should record the same counts. |
| 449 base::HistogramTester histogram_tester; |
| 450 ProvidersInfo provider_info; |
| 451 |
| 452 provider_->Start(zero_suggest_input, false); |
| 453 provider_->AddProviderInfo(&provider_info); |
| 454 |
| 455 histogram_tester.ExpectUniqueSample( |
| 456 "Omnibox.SuggestionUsed.NearbyURLCount.AtMatchCreation", 3, 1); |
| 457 histogram_tester.ExpectUniqueSample( |
| 458 "Omnibox.SuggestionUsed.NearbyURLCount.AtFocus", 3, 1); |
| 459 histogram_tester.ExpectUniqueSample( |
| 460 "Omnibox.PhysicalWebProvider.SuggestionUsedWithoutOmniboxFocus", 0, 1); |
| 461 } |
| 462 |
| 463 { |
| 464 // Simulate the user selecting a suggestion after typing a query (after |
| 465 // typing case). Some additional URLs are discovered between focusing the |
| 466 // omnibox and typing a query, so the counts should differ. |
| 467 base::HistogramTester histogram_tester; |
| 468 ProvidersInfo provider_info; |
| 469 |
| 470 provider_->Start(zero_suggest_input, false); |
| 471 data_source->SetMetadataList(CreateMetadata(6)); |
| 472 provider_->Start(after_typing_input, false); |
| 473 provider_->AddProviderInfo(&provider_info); |
| 474 |
| 475 histogram_tester.ExpectUniqueSample( |
| 476 "Omnibox.SuggestionUsed.NearbyURLCount.AtMatchCreation", 6, 1); |
| 477 histogram_tester.ExpectUniqueSample( |
| 478 "Omnibox.SuggestionUsed.NearbyURLCount.AtFocus", 3, 1); |
| 479 histogram_tester.ExpectUniqueSample( |
| 480 "Omnibox.PhysicalWebProvider.SuggestionUsedWithoutOmniboxFocus", 0, 1); |
| 481 } |
| 482 } |
| 483 |
| 484 TEST_F(PhysicalWebProviderTest, TestNearbyURLCountAfterTypingWithoutFocus) { |
| 485 FakePhysicalWebDataSource* data_source = |
| 486 client_->GetFakePhysicalWebDataSource(); |
| 487 EXPECT_TRUE(data_source); |
| 488 |
| 489 AutocompleteInput after_typing_input( |
| 490 base::UTF8ToUTF16("Example"), 7, std::string(), GURL(), |
| 491 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
| 492 true, false, true, true, false, TestSchemeClassifier()); |
| 493 |
| 494 data_source->SetMetadataList(CreateMetadata(3)); |
| 495 |
| 496 { |
| 497 // Simulate selecting a suggestion without focusing the omnibox first. |
| 498 base::HistogramTester histogram_tester; |
| 499 ProvidersInfo provider_info; |
| 500 |
| 501 provider_->Start(after_typing_input, false); |
| 502 provider_->AddProviderInfo(&provider_info); |
| 503 |
| 504 histogram_tester.ExpectUniqueSample( |
| 505 "Omnibox.SuggestionUsed.NearbyURLCount.AtMatchCreation", 3, 1); |
| 506 histogram_tester.ExpectTotalCount( |
| 507 "Omnibox.SuggestionUsed.NearbyURLCount.AtFocus", 0); |
| 508 histogram_tester.ExpectUniqueSample( |
| 509 "Omnibox.PhysicalWebProvider.SuggestionUsedWithoutOmniboxFocus", 1, 1); |
| 510 } |
| 511 } |
| OLD | NEW |