Skip to content

Commit

Permalink
welcome tour: Add tests for Step metrics
Browse files Browse the repository at this point in the history
Extends `welcome_tour_metrics` testing to include tests for RecordStep*
utility functions.

Bug: b:296416363
Change-Id: I31d41be846142ac55149d2e0375ae2f1ed5a0600
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4804135
Reviewed-by: David Black <dmblack@google.com>
Commit-Queue: Angus McLean <angusmclean@google.com>
Cr-Commit-Position: refs/heads/main@{#1188612}
  • Loading branch information
Angus L. M. McLean IV authored and Chromium LUCI CQ committed Aug 26, 2023
1 parent d2832d5 commit a02ad8b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 31 deletions.
48 changes: 24 additions & 24 deletions ash/user_education/welcome_tour/welcome_tour_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,6 @@ PrefService* GetLastActiveUserPrefService() {
return Shell::Get()->session_controller()->GetLastActiveUserPrefService();
}

// These strings are persisted to logs. These string values should never be
// changed or reused. Any values added to `Step` must be added here.
std::string ToString(Step step) {
switch (step) {
case Step::kDialog:
return "Dialog";
case Step::kExploreApp:
return "ExploreApp";
case Step::kExploreAppWindow:
return "ExploreAppWindow";
case Step::kHomeButton:
return "HomeButton";
case Step::kSearch:
return "Search";
case Step::kSettingsApp:
return "SettingsApp";
case Step::kShelf:
return "Shelf";
case Step::kStatusArea:
return "StatusArea";
}
NOTREACHED_NORETURN();
}

} // namespace

void RecordInteraction(Interaction interaction) {
Expand Down Expand Up @@ -162,4 +138,28 @@ std::string ToString(Interaction interaction) {
NOTREACHED_NORETURN();
}

// These strings are persisted to logs. These string values should never be
// changed or reused. Any values added to `Step` must be added here.
std::string ToString(Step step) {
switch (step) {
case Step::kDialog:
return "Dialog";
case Step::kExploreApp:
return "ExploreApp";
case Step::kExploreAppWindow:
return "ExploreAppWindow";
case Step::kHomeButton:
return "HomeButton";
case Step::kSearch:
return "Search";
case Step::kSettingsApp:
return "SettingsApp";
case Step::kShelf:
return "Shelf";
case Step::kStatusArea:
return "StatusArea";
}
NOTREACHED_NORETURN();
}

} // namespace ash::welcome_tour_metrics
6 changes: 5 additions & 1 deletion ash/user_education/welcome_tour/welcome_tour_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ static constexpr auto kAllPreventedReasonsSet =
// Enumeration of steps in the Welcome Tour. These values are persisted to logs.
// Entries should not be renumbered and numeric values should never be reused.
enum class Step {
kDialog = 0,
kMinValue = 0,
kDialog = kMinValue,
kExploreApp = 1,
kExploreAppWindow = 2,
kHomeButton = 3,
Expand Down Expand Up @@ -126,6 +127,9 @@ ASH_EXPORT void RecordTourPrevented(PreventedReason reason);
// Returns a string representation of the given `interaction`.
ASH_EXPORT std::string ToString(Interaction interaction);

// Returns a string representation of the given `step`.
ASH_EXPORT std::string ToString(Step step);

} // namespace ash::welcome_tour_metrics

#endif // ASH_USER_EDUCATION_WELCOME_TOUR_WELCOME_TOUR_METRICS_H_
73 changes: 67 additions & 6 deletions ash/user_education/welcome_tour/welcome_tour_metrics_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ void ClearPref(const std::string& pref_name) {

} // namespace

// WelcomeTourMetricsTest ------------------------------------------------------
// WelcomeTourInteractionMetricsTest -------------------------------------------

// Base class for tests that verify metrics are properly submitted.
class WelcomeTourMetricsTest
// Base class for tests that verify Welcome Tour Interaction metrics are
// properly submitted.
class WelcomeTourInteractionMetricsTest
: public UserEducationAshTestBase,
public ::testing::WithParamInterface<absl::optional<PreventedReason>> {
public:
WelcomeTourMetricsTest() {
WelcomeTourInteractionMetricsTest() {
scoped_feature_list.InitAndEnableFeatureWithParameters(
features::kWelcomeTour,
{{"is-counterfactual", IsCounterfactual() ? "true" : "false"}});
Expand Down Expand Up @@ -86,7 +87,7 @@ class WelcomeTourMetricsTest

INSTANTIATE_TEST_SUITE_P(
All,
WelcomeTourMetricsTest,
WelcomeTourInteractionMetricsTest,
::testing::Values(
absl::nullopt,
absl::make_optional(PreventedReason::kCounterfactualExperimentArm),
Expand All @@ -96,7 +97,7 @@ INSTANTIATE_TEST_SUITE_P(

// Verifies that, when an `Interaction` is recorded for the first time, the
// appropriate histogram is submitted.
TEST_P(WelcomeTourMetricsTest, RecordInteraction) {
TEST_P(WelcomeTourInteractionMetricsTest, RecordInteraction) {
SimulateNewUserFirstLogin("user@test");
ClearPref("ash.welcome_tour.prevented.first_reason");
ClearPref("ash.welcome_tour.prevented.first_time");
Expand Down Expand Up @@ -223,4 +224,64 @@ TEST_F(WelcomeTourMetricsEnumTest, AllPreventedReasons) {
}
}

// WelcomeTourMetricsTest ------------------------------------------------------

// Base class for tests that verify Welcome Tour metrics are properly submitted.
class WelcomeTourMetricsTest : public testing::Test {
public:
WelcomeTourMetricsTest() : scoped_feature_list_(features::kWelcomeTour) {}

private:
base::test::ScopedFeatureList scoped_feature_list_;
};

// Tests -----------------------------------------------------------------------

TEST_F(WelcomeTourMetricsTest, RecordStepAborted) {
static constexpr char kStepAbortedMetricName[] =
"Ash.WelcomeTour.Step.Aborted";

for (auto step :
base::EnumSet<Step, Step::kMinValue, Step::kMaxValue>::All()) {
base::HistogramTester histogram_tester;

histogram_tester.ExpectTotalCount(kStepAbortedMetricName, 0);
RecordStepAborted(step);
histogram_tester.ExpectBucketCount(kStepAbortedMetricName, step, 1);
histogram_tester.ExpectTotalCount(kStepAbortedMetricName, 1);
}
}

TEST_F(WelcomeTourMetricsTest, RecordStepDuration) {
base::HistogramTester histogram_tester;
for (auto step :
base::EnumSet<Step, Step::kMinValue, Step::kMaxValue>::All()) {
const auto step_duration_metric_name =
base::StrCat({"Ash.WelcomeTour.Step.Duration.", ToString(step)});

const auto test_step_length = base::Seconds(10);
histogram_tester.ExpectTotalCount(step_duration_metric_name, 0);
histogram_tester.ExpectTimeBucketCount(step_duration_metric_name,
test_step_length, 0);
RecordStepDuration(step, test_step_length);
histogram_tester.ExpectTotalCount(step_duration_metric_name, 1);
histogram_tester.ExpectTimeBucketCount(step_duration_metric_name,
test_step_length, 1);
}
}

TEST_F(WelcomeTourMetricsTest, RecordStepShown) {
static constexpr char kStepShownMetricName[] = "Ash.WelcomeTour.Step.Shown";

for (auto step :
base::EnumSet<Step, Step::kMinValue, Step::kMaxValue>::All()) {
base::HistogramTester histogram_tester;

histogram_tester.ExpectTotalCount(kStepShownMetricName, 0);
RecordStepShown(step);
histogram_tester.ExpectBucketCount(kStepShownMetricName, step, 1);
histogram_tester.ExpectTotalCount(kStepShownMetricName, 1);
}
}

} // namespace ash::welcome_tour_metrics

0 comments on commit a02ad8b

Please sign in to comment.