Commit e11d4028 authored by Michael Giuffrida's avatar Michael Giuffrida Committed by Commit Bot

Add WasRecentlyAudible to TabMetrics

Check whether the tab was recently audible (last 2 seconds) when logging
the TabManager.TabMetrics UKM.

Bug: 784639
Change-Id: I755305fecf1c13668219e972ad41312da91ca568
Reviewed-on: https://chromium-review.googlesource.com/795175
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarBryan McQuade <bmcquade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520835}
parent 45c7a335
......@@ -56,6 +56,7 @@ const UkmMetricMap kBasicMetricValues({
{TabManager_TabMetrics::kMouseEventCountName, 0},
{TabManager_TabMetrics::kSiteEngagementScoreName, 0},
{TabManager_TabMetrics::kTouchEventCountName, 0},
{TabManager_TabMetrics::kWasRecentlyAudibleName, 0},
});
// Helper class to respond to WebContents lifecycle events we can't
......@@ -247,9 +248,7 @@ TEST_F(TabActivityWatcherTest, TabEvents) {
tab_strip_model->SetTabPinned(0, true);
EXPECT_FALSE(WasNewEntryRecorded());
LOG(ERROR) << "this is 247";
// Pinning and unpinning the background tab triggers logging.
LOG(ERROR) << "this is 249";
tab_strip_model->SetTabPinned(1, true);
UkmMetricMap expected_metrics(kBasicMetricValues);
expected_metrics[TabManager_TabMetrics::kIsPinnedName] = 1;
......@@ -303,6 +302,9 @@ TEST_F(TabActivityWatcherTest, TabMetrics) {
SiteEngagementService::Get(profile())->ResetBaseScoreForURL(kTestUrls[1], 45);
expected_metrics[TabManager_TabMetrics::kSiteEngagementScoreName] = 40;
WebContentsTester::For(test_contents_2)->SetWasRecentlyAudible(true);
expected_metrics[TabManager_TabMetrics::kWasRecentlyAudibleName] = 1;
// Pin the background tab to log an event. (This moves it to index 0.)
tab_strip_model->SetTabPinned(1, true);
expected_metrics[TabManager_TabMetrics::kIsPinnedName] = 1;
......@@ -311,11 +313,14 @@ TEST_F(TabActivityWatcherTest, TabMetrics) {
ExpectNewEntry(kTestUrls[1], expected_metrics);
}
// Navigate the background tab to a new domain.
// Unset WasRecentlyAudible and navigate the background tab to a new domain.
// Site engagement score for the new domain is 0.
WebContentsTester::For(test_contents_2)->SetWasRecentlyAudible(false);
expected_metrics[TabManager_TabMetrics::kWasRecentlyAudibleName] = 0;
WebContentsTester::For(test_contents_2)->NavigateAndCommit(kTestUrls[2]);
WebContentsTester::For(test_contents_2)->TestSetIsLoading(false);
expected_metrics[TabManager_TabMetrics::kSiteEngagementScoreName] = 0;
WebContentsTester::For(test_contents_2)->TestSetIsLoading(false);
{
SCOPED_TRACE("");
ExpectNewEntry(kTestUrls[2], expected_metrics);
......
......@@ -100,6 +100,10 @@ void TabMetricsLoggerImpl::LogBackgroundTab(ukm::SourceId ukm_source_id,
// TODO(michaelpg): Add PluginType field if mime type matches "application/*"
// using PluginUMAReporter.
// This checks if the tab was audible within the past two seconds, same as the
// audio indicator in the tab strip.
entry.SetWasRecentlyAudible(web_contents->WasRecentlyAudible());
entry.SetIsPinned(tab_strip_model->IsTabPinned(index))
.SetHasFormEntry(
web_contents->GetPageImportanceSignals().had_form_interaction)
......
......@@ -2093,6 +2093,12 @@ be describing additional metrics about the same event.
Number of touch events that were sent to the page.
</summary>
</metric>
<metric name="WasRecentlyAudible">
<summary>
Boolean value indicating whether the tab has played audio within the last
two seconds.
</summary>
</metric>
</event>
</ukm-configuration>
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