Commit 68e6b656 authored by sauski's avatar sauski Committed by Commit Bot

HaTS Next: Record UMA entry for survey rejected by HaTS Service

Added UMA logging to record when the client has successfully contacted
the HaTS Next service, but the service has declined to provide a survey
for display.

Bug: 1110888
Change-Id: I0d376c1612efc664ca52646b17ea4f68ae69d266
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463618
Commit-Queue: Theodore Olsauskas-Warren <sauski@google.com>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817013}
parent 5adb9589
......@@ -124,7 +124,8 @@ class HatsService : public KeyedService {
kNoSurveyOverCapacity = 13,
kNoSurveyAlreadyInProgress = 14,
kNoAnyLastSurveyTooRecent = 15,
kMaxValue = kNoAnyLastSurveyTooRecent,
kNoRejectedByHatsService = 16,
kMaxValue = kNoRejectedByHatsService,
};
~HatsService() override;
......
......@@ -284,6 +284,7 @@ IN_PROC_BROWSER_TEST_F(HatsNextWebDialogBrowserTest, SurveyLoaded) {
// indicates the survey window should be closed.
IN_PROC_BROWSER_TEST_F(HatsNextWebDialogBrowserTest, SurveyClosed) {
ASSERT_TRUE(embedded_test_server()->Start());
base::HistogramTester histogram_tester;
EXPECT_CALL(*hats_service(), HatsNextDialogClosed);
auto* dialog = new MockHatsNextWebDialog(
......@@ -294,6 +295,30 @@ IN_PROC_BROWSER_TEST_F(HatsNextWebDialogBrowserTest, SurveyClosed) {
// The hats_next_mock.html will provide a state update to the dialog to
// indicate that the survey window should be closed.
dialog->WaitForClose();
// Because no loaded state was provided, only a rejection should be recorded.
histogram_tester.ExpectUniqueSample(
kHatsShouldShowSurveyReasonHistogram,
HatsService::ShouldShowSurveyReasons::kNoRejectedByHatsService, 1);
}
// Test that a survey which first reports as loaded, then reports closure, only
// logs that the survey was shown.
IN_PROC_BROWSER_TEST_F(HatsNextWebDialogBrowserTest, SurveyLoadedThenClosed) {
ASSERT_TRUE(embedded_test_server()->Start());
base::HistogramTester histogram_tester;
EXPECT_CALL(*hats_service(), HatsNextDialogClosed);
auto* dialog = new MockHatsNextWebDialog(
browser(), kHatsNextSurveyTriggerIDTesting,
embedded_test_server()->GetURL("/hats/hats_next_mock.html"),
base::TimeDelta::FromSeconds(100));
dialog->WaitForClose();
// The only recorded sample should indicate that the survey was shown.
histogram_tester.ExpectUniqueSample(
kHatsShouldShowSurveyReasonHistogram,
HatsService::ShouldShowSurveyReasons::kYes, 1);
}
// Test that if the survey does not indicate it is ready for display before the
......
......@@ -248,8 +248,18 @@ void HatsNextWebDialog::OnSurveyStateUpdateReceived(std::string state) {
HatsServiceFactory::GetForProfile(browser_->profile(), false);
DCHECK(service);
service->RecordSurveyAsShown(trigger_id_);
received_survey_loaded_ = true;
ShowWidget();
} else if (state == "close") {
if (!received_survey_loaded_) {
// Receiving a close state prior to a loaded state indicates that contact
// was made with the HaTS Next service, but the HaTS service declined the
// survey request. This is likely because of a survey misconfiguration,
// such as a survey still being in test mode, or an invalid survey ID.
base::UmaHistogramEnumeration(
kHatsShouldShowSurveyReasonHistogram,
HatsService::ShouldShowSurveyReasons::kNoRejectedByHatsService);
}
CloseWidget();
} else {
LOG(ERROR) << "Unknown state provided in URL fragment by HaTS survey:"
......
......@@ -109,6 +109,9 @@ class HatsNextWebDialog : public ui::WebDialogDelegate,
// The HaTS Next survey trigger ID that is provided to the HaTS webpage.
const std::string trigger_id_;
// Whether the web contents has communicated a loaded state.
bool received_survey_loaded_ = false;
// The size of the dialog. Desired dimensions are provided by the site loaded
// in the web contents. Initialised to arbitrary non-zero value as creation
// of 0 sized windows is disallowed on OSX.
......
......@@ -8,6 +8,7 @@
// side in hats_service.cc.
if (params.get('trigger_id') == 'zishSVViB0kPN8UwQ150VGjBKuBP') {
history.pushState('', '', '#loaded');
history.pushState('', '', '#close');
}
if (params.get('trigger_id') == "close_for_testing") {
......
......@@ -35521,6 +35521,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
</int>
<int value="14" label="A survey is already in progress"/>
<int value="15" label="Last instance of any survey too recent"/>
<int value="16" label="HaTS Service rejected request to load survey"/>
</enum>
<enum name="HardwareVerifierQualificationStatus">
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