Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: content/browser/media/audio_stream_monitor_unittest.cc

Issue 1591453005: Add metrics regarding concurrent audible tabs in Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: user action and tick Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/media/audio_stream_monitor_unittest.cc
diff --git a/content/browser/media/audio_stream_monitor_unittest.cc b/content/browser/media/audio_stream_monitor_unittest.cc
index d9999bf9db3948ef6259f7559fac2974f56719ce..b90e6d7361c99f25d4ed8801b9915955d664719f 100644
--- a/content/browser/media/audio_stream_monitor_unittest.cc
+++ b/content/browser/media/audio_stream_monitor_unittest.cc
@@ -93,16 +93,37 @@ class AudioStreamMonitorTest : public RenderViewHostTestHarness {
monitor_->off_timer_.IsRunning());
}
- void ExpectWebContentsWillBeNotifiedOnce(bool should_be_audible) {
+ void ExpectIsCurrentlyAudible() const {
+ EXPECT_TRUE(monitor_->IsCurrentlyAudible());
+ }
+
+ void ExpectNotCurrentlyAudible() const {
+ EXPECT_FALSE(monitor_->IsCurrentlyAudible());
+ }
+
+ void ExpectRecentlyAudbileChangeNotification(bool new_recently_audible) {
DaleCurtis 2016/01/19 19:32:57 Audible
mlamouri (slow - plz ping) 2016/01/19 19:55:10 Done.
+ EXPECT_CALL(
+ mock_web_contents_delegate_,
+ NavigationStateChanged(RenderViewHostTestHarness::web_contents(),
+ INVALIDATE_TYPE_TAB))
+ .WillOnce(InvokeWithoutArgs(
+ this,
+ new_recently_audible
+ ? &AudioStreamMonitorTest::ExpectWasRecentlyAudible
+ : &AudioStreamMonitorTest::ExpectNotRecentlyAudible))
+ .RetiresOnSaturation();
+ }
+
+ void ExpectCurrentlyAudbileChangeNotification(bool new_audible) {
DaleCurtis 2016/01/19 19:32:57 Audible
mlamouri (slow - plz ping) 2016/01/19 19:55:10 Done.
EXPECT_CALL(
mock_web_contents_delegate_,
NavigationStateChanged(RenderViewHostTestHarness::web_contents(),
INVALIDATE_TYPE_TAB))
.WillOnce(InvokeWithoutArgs(
this,
- should_be_audible
- ? &AudioStreamMonitorTest::ExpectIsNotifyingForToggleOn
- : &AudioStreamMonitorTest::ExpectIsNotifyingForToggleOff))
+ new_audible
+ ? &AudioStreamMonitorTest::ExpectIsCurrentlyAudible
+ : &AudioStreamMonitorTest::ExpectNotCurrentlyAudible))
.RetiresOnSaturation();
}
@@ -136,11 +157,11 @@ class AudioStreamMonitorTest : public RenderViewHostTestHarness {
return std::make_pair(current_power_[stream_id], false);
}
- void ExpectIsNotifyingForToggleOn() {
+ void ExpectWasRecentlyAudible() const {
EXPECT_TRUE(monitor_->WasRecentlyAudible());
}
- void ExpectIsNotifyingForToggleOff() {
+ void ExpectNotRecentlyAudible() const {
EXPECT_FALSE(monitor_->WasRecentlyAudible());
}
@@ -155,14 +176,17 @@ class AudioStreamMonitorTest : public RenderViewHostTestHarness {
// ReadPowerAndClipCallback, and is not polling at other times.
TEST_F(AudioStreamMonitorTest, PollsWhenProvidedACallback) {
EXPECT_FALSE(monitor_->WasRecentlyAudible());
+ ExpectNotCurrentlyAudible();
ExpectIsPolling(kRenderProcessId, kStreamId, false);
StartMonitoring(kRenderProcessId, kStreamId, CreatePollCallback(kStreamId));
EXPECT_FALSE(monitor_->WasRecentlyAudible());
+ ExpectNotCurrentlyAudible();
ExpectIsPolling(kRenderProcessId, kStreamId, true);
StopMonitoring(kRenderProcessId, kStreamId);
EXPECT_FALSE(monitor_->WasRecentlyAudible());
+ ExpectNotCurrentlyAudible();
ExpectIsPolling(kRenderProcessId, kStreamId, false);
}
@@ -175,13 +199,16 @@ TEST_F(AudioStreamMonitorTest,
// Expect WebContents will get one call form AudioStreamMonitor to toggle the
// indicator on upon the very first poll.
- ExpectWebContentsWillBeNotifiedOnce(true);
+ ExpectRecentlyAudbileChangeNotification(true);
// Loop, each time testing a slightly longer period of polled silence. The
- // indicator should remain on throughout.
- int num_silence_polls = 0;
+ // recently audible state should not change while the currently audible one
+ // should.
+ int num_silence_polls = 1;
base::TimeTicks last_blurt_time;
do {
+ ExpectCurrentlyAudbileChangeNotification(true);
+
// Poll an audible signal, and expect tab indicator state is on.
SetStreamPower(kStreamId, media::AudioPowerMonitor::max_power());
last_blurt_time = GetTestClockTime();
@@ -189,6 +216,8 @@ TEST_F(AudioStreamMonitorTest,
ExpectTabWasRecentlyAudible(true, last_blurt_time);
AdvanceClock(one_polling_interval());
+ ExpectCurrentlyAudbileChangeNotification(false);
+
// Poll a silent signal repeatedly, ensuring that the indicator is being
// held on during the holding period.
SetStreamPower(kStreamId, media::AudioPowerMonitor::zero_power());
@@ -207,7 +236,7 @@ TEST_F(AudioStreamMonitorTest,
// At this point, the clock has just advanced to beyond the holding period, so
// the next firing of the off timer should turn off the tab indicator. Also,
// make sure it stays off for several cycles thereafter.
- ExpectWebContentsWillBeNotifiedOnce(false);
+ ExpectRecentlyAudbileChangeNotification(false);
for (int i = 0; i < 10; ++i) {
SimulateOffTimerFired();
ExpectTabWasRecentlyAudible(false, last_blurt_time);
@@ -224,15 +253,19 @@ TEST_F(AudioStreamMonitorTest, HandlesMultipleStreamsBlurting) {
base::TimeTicks last_blurt_time;
ExpectTabWasRecentlyAudible(false, last_blurt_time);
+ ExpectNotCurrentlyAudible();
// Measure audible sound from the first stream and silence from the second.
- // The indicator turns on (i.e., tab was recently audible).
- ExpectWebContentsWillBeNotifiedOnce(true);
+ // The tab becomes audible.
+ ExpectRecentlyAudbileChangeNotification(true);
+ ExpectCurrentlyAudbileChangeNotification(true);
+
SetStreamPower(kStreamId, media::AudioPowerMonitor::max_power());
SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::zero_power());
last_blurt_time = GetTestClockTime();
SimulatePollTimerFired();
ExpectTabWasRecentlyAudible(true, last_blurt_time);
+ ExpectIsCurrentlyAudible();
// Halfway through the holding period, the second stream joins in. The
// indicator stays on.
@@ -242,39 +275,52 @@ TEST_F(AudioStreamMonitorTest, HandlesMultipleStreamsBlurting) {
last_blurt_time = GetTestClockTime();
SimulatePollTimerFired(); // Restarts holding period.
ExpectTabWasRecentlyAudible(true, last_blurt_time);
+ ExpectIsCurrentlyAudible();
// Now, measure silence from both streams. After an entire holding period
- // has passed (since the second stream joined in), the indicator should turn
- // off.
- ExpectWebContentsWillBeNotifiedOnce(false);
+ // has passed (since the second stream joined in), the tab will no longer
+ // become audible nor recently audible.
+ ExpectCurrentlyAudbileChangeNotification(false);
+ ExpectRecentlyAudbileChangeNotification(false);
+
AdvanceClock(holding_period());
SimulateOffTimerFired();
SetStreamPower(kStreamId, media::AudioPowerMonitor::zero_power());
SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::zero_power());
SimulatePollTimerFired();
ExpectTabWasRecentlyAudible(false, last_blurt_time);
+ ExpectNotCurrentlyAudible();
// Now, measure silence from the first stream and audible sound from the
- // second. The indicator turns back on.
- ExpectWebContentsWillBeNotifiedOnce(true);
+ // second. The tab becomes audible again.
+ ExpectRecentlyAudbileChangeNotification(true);
+ ExpectCurrentlyAudbileChangeNotification(true);
+
SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::max_power());
last_blurt_time = GetTestClockTime();
SimulatePollTimerFired();
ExpectTabWasRecentlyAudible(true, last_blurt_time);
+ ExpectIsCurrentlyAudible();
// From here onwards, both streams are silent. Halfway through the holding
- // period, the indicator should not have changed.
+ // period, the tab is no longer audible but stays as recently audible.
+ ExpectCurrentlyAudbileChangeNotification(false);
+
SetStreamPower(kAnotherStreamId, media::AudioPowerMonitor::zero_power());
AdvanceClock(holding_period() / 2);
SimulatePollTimerFired();
SimulateOffTimerFired();
ExpectTabWasRecentlyAudible(true, last_blurt_time);
+ ExpectNotCurrentlyAudible();
+
+ // Just past the holding period, the tab is no longer marked as recently
+ // audible.
+ ExpectRecentlyAudbileChangeNotification(false);
- // Just past the holding period, the indicator should be turned off.
- ExpectWebContentsWillBeNotifiedOnce(false);
AdvanceClock(holding_period() - (GetTestClockTime() - last_blurt_time));
SimulateOffTimerFired();
ExpectTabWasRecentlyAudible(false, last_blurt_time);
+ ExpectNotCurrentlyAudible();
// Polling should not turn the indicator back while both streams are remaining
// silent.
@@ -282,6 +328,7 @@ TEST_F(AudioStreamMonitorTest, HandlesMultipleStreamsBlurting) {
AdvanceClock(one_polling_interval());
SimulatePollTimerFired();
ExpectTabWasRecentlyAudible(false, last_blurt_time);
+ ExpectNotCurrentlyAudible();
}
}

Powered by Google App Engine
This is Rietveld 408576698