Commit 1ffe5f17 authored by Tommy Nyquist's avatar Tommy Nyquist Committed by Commit Bot

Add overall histogram for triggering in-product help.

Up until now, each in-product help feature has recorded their own
histogram for how often they are triggered. However, this makes it
hard to inspect the overall data for how often in-product help is
triggered in general.

This CL therefore adds a new histogram that is triggered regardless of
which feature invoked it: InProductHelp.ShouldTriggerHelpUI. That name
is also the base name for the suffix-based feature specific histograms.

In addition, tests are added to ensure these histograms behave as
expected.

BUG=733799

Change-Id: I9c99494dc64f9c20fc2e811d7596ff0d7a7f72c2
Reviewed-on: https://chromium-review.googlesource.com/569259
Commit-Queue: Tommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarAlexei Svitkine (slow) <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486942}
parent cec28999
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/test/histogram_tester.h"
#include "base/test/user_action_tester.h" #include "base/test/user_action_tester.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/feature_engagement_tracker/internal/availability_model_impl.h" #include "components/feature_engagement_tracker/internal/availability_model_impl.h"
...@@ -195,6 +196,54 @@ class FeatureEngagementTrackerImplTest : public ::testing::Test { ...@@ -195,6 +196,54 @@ class FeatureEngagementTrackerImplTest : public ::testing::Test {
EXPECT_EQ(count, trigger_event.events(0).count()); EXPECT_EQ(count, trigger_event.events(0).count());
} }
void VerifyHistogramsForFeature(const std::string& histogram_name,
bool check,
int expected_success_count,
int expected_failure_count) {
if (!check)
return;
histogram_tester_.ExpectBucketCount(
histogram_name, static_cast<int>(stats::TriggerHelpUIResult::SUCCESS),
expected_success_count);
histogram_tester_.ExpectBucketCount(
histogram_name, static_cast<int>(stats::TriggerHelpUIResult::FAILURE),
expected_failure_count);
}
// Histogram values are checked only if their respective |check_...| is true,
// since inspecting a bucket count for a histogram that has not been recorded
// yet leads to an error.
void VerifyHistograms(bool check_foo,
int expected_foo_success_count,
int expected_foo_failure_count,
bool check_bar,
int expected_bar_success_count,
int expected_bar_failure_count,
bool check_qux,
int expected_qux_success_count,
int expected_qux_failure_count) {
VerifyHistogramsForFeature("InProductHelp.ShouldTriggerHelpUI.test_foo",
check_foo, expected_foo_success_count,
expected_foo_failure_count);
VerifyHistogramsForFeature("InProductHelp.ShouldTriggerHelpUI.test_bar",
check_bar, expected_bar_success_count,
expected_bar_failure_count);
VerifyHistogramsForFeature("InProductHelp.ShouldTriggerHelpUI.test_qux",
check_qux, expected_qux_success_count,
expected_qux_failure_count);
int expected_total_successes = expected_foo_success_count +
expected_bar_success_count +
expected_qux_success_count;
int expected_total_failures = expected_foo_failure_count +
expected_bar_failure_count +
expected_qux_failure_count;
VerifyHistogramsForFeature("InProductHelp.ShouldTriggerHelpUI", true,
expected_total_successes,
expected_total_failures);
}
void VerifyUserActionsTriggerChecks( void VerifyUserActionsTriggerChecks(
const base::UserActionTester& user_action_tester, const base::UserActionTester& user_action_tester,
int expected_foo_count, int expected_foo_count,
...@@ -269,6 +318,7 @@ class FeatureEngagementTrackerImplTest : public ::testing::Test { ...@@ -269,6 +318,7 @@ class FeatureEngagementTrackerImplTest : public ::testing::Test {
TestInMemoryStore* store_; TestInMemoryStore* store_;
TestAvailabilityModel* availability_model_; TestAvailabilityModel* availability_model_;
Configuration* configuration_; Configuration* configuration_;
base::HistogramTester histogram_tester_;
private: private:
DISALLOW_COPY_AND_ASSIGN(FeatureEngagementTrackerImplTest); DISALLOW_COPY_AND_ASSIGN(FeatureEngagementTrackerImplTest);
...@@ -473,6 +523,7 @@ TEST_F(FeatureEngagementTrackerImplTest, TestTriggering) { ...@@ -473,6 +523,7 @@ TEST_F(FeatureEngagementTrackerImplTest, TestTriggering) {
VerifyUserActionsTriggered(user_action_tester, 1, 0, 0); VerifyUserActionsTriggered(user_action_tester, 1, 0, 0);
VerifyUserActionsNotTriggered(user_action_tester, 1, 0, 1); VerifyUserActionsNotTriggered(user_action_tester, 1, 0, 1);
VerifyUserActionsDismissed(user_action_tester, 0); VerifyUserActionsDismissed(user_action_tester, 0);
VerifyHistograms(true, 1, 1, false, 0, 0, true, 0, 1);
// While in-product help is currently showing, no other features should be // While in-product help is currently showing, no other features should be
// shown. // shown.
...@@ -484,6 +535,7 @@ TEST_F(FeatureEngagementTrackerImplTest, TestTriggering) { ...@@ -484,6 +535,7 @@ TEST_F(FeatureEngagementTrackerImplTest, TestTriggering) {
VerifyUserActionsTriggered(user_action_tester, 1, 0, 0); VerifyUserActionsTriggered(user_action_tester, 1, 0, 0);
VerifyUserActionsNotTriggered(user_action_tester, 1, 1, 2); VerifyUserActionsNotTriggered(user_action_tester, 1, 1, 2);
VerifyUserActionsDismissed(user_action_tester, 0); VerifyUserActionsDismissed(user_action_tester, 0);
VerifyHistograms(true, 1, 1, true, 0, 1, true, 0, 2);
// After dismissing the current in-product help, that feature can not be shown // After dismissing the current in-product help, that feature can not be shown
// again, but a different feature should. // again, but a different feature should.
...@@ -498,6 +550,7 @@ TEST_F(FeatureEngagementTrackerImplTest, TestTriggering) { ...@@ -498,6 +550,7 @@ TEST_F(FeatureEngagementTrackerImplTest, TestTriggering) {
VerifyUserActionsTriggered(user_action_tester, 1, 1, 0); VerifyUserActionsTriggered(user_action_tester, 1, 1, 0);
VerifyUserActionsNotTriggered(user_action_tester, 2, 1, 3); VerifyUserActionsNotTriggered(user_action_tester, 2, 1, 3);
VerifyUserActionsDismissed(user_action_tester, 1); VerifyUserActionsDismissed(user_action_tester, 1);
VerifyHistograms(true, 1, 2, true, 1, 1, true, 0, 3);
// After dismissing the second registered feature, no more in-product help // After dismissing the second registered feature, no more in-product help
// should be shown, since kTestFeatureQux is invalid. // should be shown, since kTestFeatureQux is invalid.
...@@ -512,6 +565,7 @@ TEST_F(FeatureEngagementTrackerImplTest, TestTriggering) { ...@@ -512,6 +565,7 @@ TEST_F(FeatureEngagementTrackerImplTest, TestTriggering) {
VerifyUserActionsTriggered(user_action_tester, 1, 1, 0); VerifyUserActionsTriggered(user_action_tester, 1, 1, 0);
VerifyUserActionsNotTriggered(user_action_tester, 3, 2, 4); VerifyUserActionsNotTriggered(user_action_tester, 3, 2, 4);
VerifyUserActionsDismissed(user_action_tester, 2); VerifyUserActionsDismissed(user_action_tester, 2);
VerifyHistograms(true, 1, 3, true, 1, 2, true, 0, 4);
} }
TEST_F(FeatureEngagementTrackerImplTest, TestNotifyEvent) { TEST_F(FeatureEngagementTrackerImplTest, TestNotifyEvent) {
......
...@@ -20,11 +20,19 @@ namespace { ...@@ -20,11 +20,19 @@ namespace {
const char kEventStoreSuffix[] = "EventStore"; const char kEventStoreSuffix[] = "EventStore";
const char kAvailabilityStoreSuffix[] = "AvailabilityStore"; const char kAvailabilityStoreSuffix[] = "AvailabilityStore";
// A shadow histogram across all features. Also the base name for the suffix
// based feature specific histograms; for example for IPH_MyFun, it would be:
// InProductHelp.ShouldTriggerHelpUI.IPH_MyFun.
const char kShouldTriggerHelpUIHistogram[] =
"InProductHelp.ShouldTriggerHelpUI";
// Helper function to log a TriggerHelpUIResult. // Helper function to log a TriggerHelpUIResult.
void LogTriggerHelpUIResult(const std::string& name, void LogTriggerHelpUIResult(const std::string& name,
TriggerHelpUIResult result) { TriggerHelpUIResult result) {
// Must not use histograms macros here because we pass in the histogram name. // Must not use histograms macros here because we pass in the histogram name.
base::UmaHistogramEnumeration(name, result, TriggerHelpUIResult::COUNT); base::UmaHistogramEnumeration(name, result, TriggerHelpUIResult::COUNT);
base::UmaHistogramEnumeration(kShouldTriggerHelpUIHistogram, result,
TriggerHelpUIResult::COUNT);
} }
} // namespace } // namespace
...@@ -93,8 +101,9 @@ void RecordNotifyEvent(const std::string& event_name, ...@@ -93,8 +101,9 @@ void RecordNotifyEvent(const std::string& event_name,
void RecordShouldTriggerHelpUI(const base::Feature& feature, void RecordShouldTriggerHelpUI(const base::Feature& feature,
const ConditionValidator::Result& result) { const ConditionValidator::Result& result) {
// Records the user action. // Records the user action.
std::string name = "InProductHelp.ShouldTriggerHelpUI."; std::string name = std::string(kShouldTriggerHelpUIHistogram)
name.append(feature.name); .append(".")
.append(feature.name);
base::RecordComputedAction(name); base::RecordComputedAction(name);
// Total count histogram, used to compute the percentage of each failure type, // Total count histogram, used to compute the percentage of each failure type,
......
...@@ -25844,15 +25844,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -25844,15 +25844,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram base="true" name="InProductHelp.ShouldTriggerHelpUI" <histogram name="InProductHelp.ShouldTriggerHelpUI" enum="TriggerHelpUIResult">
enum="TriggerHelpUIResult">
<owner>nyquist@chromium.org</owner> <owner>nyquist@chromium.org</owner>
<owner>xingliu@chromium.org</owner> <owner>xingliu@chromium.org</owner>
<!-- Name completed by histogram_suffixes name="IPHFeatures" --> <!-- Name completed by histogram_suffixes name="IPHFeatures" -->
<summary> <summary>
Records if in-product help is shown to the user, and the failure reasons if Records if in-product help is shown to the user, and the failure reasons if
in-product help is not shown. in-product help is not shown. Recorded on its own across all in-product help
features, in addition to being a base name for feature-specific histograms.
</summary> </summary>
</histogram> </histogram>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment