1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "omnibox_triggered_feature_service.h"
#include "base/test/metrics/histogram_tester.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
class OmniboxTriggeredFeatureServiceTest : public testing::Test {
public:
OmniboxTriggeredFeatureServiceTest() = default;
~OmniboxTriggeredFeatureServiceTest() override = default;
void RecordAndExpectFeatures(
OmniboxTriggeredFeatureService::Features features) {
RecordAndExpectFeatures(features, features);
}
void RecordAndExpectFeatures(
OmniboxTriggeredFeatureService::Features features,
OmniboxTriggeredFeatureService::Features features_triggered_in_session) {
service_.RecordToLogs(&feature_triggered_, &feature_triggered_in_session_);
EXPECT_THAT(feature_triggered_, testing::ElementsAreArray(features));
EXPECT_THAT(feature_triggered_in_session_,
testing::ElementsAreArray(features_triggered_in_session));
}
OmniboxTriggeredFeatureService service_;
OmniboxTriggeredFeatureService::Features feature_triggered_;
OmniboxTriggeredFeatureService::Features feature_triggered_in_session_;
base::HistogramTester histogram_;
};
TEST_F(OmniboxTriggeredFeatureServiceTest, NoFeaturesTriggered) {
RecordAndExpectFeatures({});
histogram_.ExpectTotalCount("Omnibox.RichAutocompletion.Triggered", 0);
histogram_.ExpectUniqueSample("Omnibox.RichAutocompletion.Triggered.Any",
false, 1);
}
TEST_F(OmniboxTriggeredFeatureServiceTest, TwoFeaturesTriggered) {
service_.FeatureTriggered(
metrics::OmniboxEventProto_Feature_REMOTE_SEARCH_FEATURE);
service_.FeatureTriggered(
metrics::
OmniboxEventProto_Feature_SHORT_BOOKMARK_SUGGESTIONS_BY_TOTAL_INPUT_LENGTH);
RecordAndExpectFeatures(
{metrics::OmniboxEventProto_Feature_REMOTE_SEARCH_FEATURE,
metrics::
OmniboxEventProto_Feature_SHORT_BOOKMARK_SUGGESTIONS_BY_TOTAL_INPUT_LENGTH});
histogram_.ExpectTotalCount("Omnibox.RichAutocompletion.Triggered", 0);
histogram_.ExpectUniqueSample("Omnibox.RichAutocompletion.Triggered.Any",
false, 1);
service_.ResetSession();
RecordAndExpectFeatures({});
}
TEST_F(OmniboxTriggeredFeatureServiceTest, TriggerRichAutocompletionType_kNo) {
// Simulate 2 updates in the session, neither of which had rich
// autocompletion.
service_.RichAutocompletionTypeTriggered(
AutocompleteMatch::RichAutocompletionType::kNone);
service_.RichAutocompletionTypeTriggered(
AutocompleteMatch::RichAutocompletionType::kNone);
RecordAndExpectFeatures({});
histogram_.ExpectUniqueSample(
"Omnibox.RichAutocompletion.Triggered",
AutocompleteMatch::RichAutocompletionType::kNone, 1);
histogram_.ExpectUniqueSample("Omnibox.RichAutocompletion.Triggered.Any",
false, 1);
{
SCOPED_TRACE("Reset session");
base::HistogramTester histogram;
service_.ResetSession();
RecordAndExpectFeatures({});
histogram.ExpectTotalCount("Omnibox.RichAutocompletion.Triggered", 0);
histogram.ExpectUniqueSample("Omnibox.RichAutocompletion.Triggered.Any",
false, 1);
}
}
TEST_F(OmniboxTriggeredFeatureServiceTest, RichAutocompletionTypeTriggered) {
// Simulate 4 updates in the session, 3 of which had rich
// autocompletion, of 2 different types.
service_.FeatureTriggered(
metrics::OmniboxEventProto_Feature_RICH_AUTOCOMPLETION);
service_.RichAutocompletionTypeTriggered(
AutocompleteMatch::RichAutocompletionType::kShortcutTextPrefix);
service_.RichAutocompletionTypeTriggered(
AutocompleteMatch::RichAutocompletionType::kTitlePrefix);
service_.RichAutocompletionTypeTriggered(
AutocompleteMatch::RichAutocompletionType::kTitlePrefix);
service_.RichAutocompletionTypeTriggered(
AutocompleteMatch::RichAutocompletionType::kNone);
RecordAndExpectFeatures(
{metrics::OmniboxEventProto_Feature_RICH_AUTOCOMPLETION});
histogram_.ExpectTotalCount("Omnibox.RichAutocompletion.Triggered", 3);
histogram_.ExpectBucketCount(
"Omnibox.RichAutocompletion.Triggered",
AutocompleteMatch::RichAutocompletionType::kShortcutTextPrefix, 1);
histogram_.ExpectBucketCount(
"Omnibox.RichAutocompletion.Triggered",
AutocompleteMatch::RichAutocompletionType::kTitlePrefix, 1);
histogram_.ExpectBucketCount("Omnibox.RichAutocompletion.Triggered",
AutocompleteMatch::RichAutocompletionType::kNone,
1);
histogram_.ExpectUniqueSample("Omnibox.RichAutocompletion.Triggered.Any",
true, 1);
{
SCOPED_TRACE("Reset session");
base::HistogramTester histogram;
service_.ResetSession();
RecordAndExpectFeatures({});
histogram.ExpectTotalCount("Omnibox.RichAutocompletion.Triggered", 0);
histogram.ExpectUniqueSample("Omnibox.RichAutocompletion.Triggered.Any",
false, 1);
}
}
TEST_F(OmniboxTriggeredFeatureServiceTest, ResetInput) {
service_.FeatureTriggered(
metrics::OmniboxEventProto_Feature_REMOTE_SEARCH_FEATURE);
service_.ResetInput();
service_.FeatureTriggered(
metrics::
OmniboxEventProto_Feature_SHORT_BOOKMARK_SUGGESTIONS_BY_TOTAL_INPUT_LENGTH);
RecordAndExpectFeatures(
{metrics::
OmniboxEventProto_Feature_SHORT_BOOKMARK_SUGGESTIONS_BY_TOTAL_INPUT_LENGTH},
{metrics::OmniboxEventProto_Feature_REMOTE_SEARCH_FEATURE,
metrics::
OmniboxEventProto_Feature_SHORT_BOOKMARK_SUGGESTIONS_BY_TOTAL_INPUT_LENGTH});
}
|