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

Unified Diff: media/blink/watch_time_reporter_unittest.cc

Issue 2780533004: Start recording background video watch time. (Closed)
Patch Set: Add moar tests. Created 3 years, 9 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: media/blink/watch_time_reporter_unittest.cc
diff --git a/media/blink/watch_time_reporter_unittest.cc b/media/blink/watch_time_reporter_unittest.cc
index 85e9b70976a6ad2171c1eeb16afb4e23b0d49833..9721bf673259572f606c07e32f565f098fdc74d8 100644
--- a/media/blink/watch_time_reporter_unittest.cc
+++ b/media/blink/watch_time_reporter_unittest.cc
@@ -27,6 +27,15 @@ constexpr gfx::Size kSizeJustRight = gfx::Size(201, 201);
.RetiresOnSaturation(); \
} while (0)
+#define EXPECT_BACKGROUND_WATCH_TIME(key, value) \
+ do { \
+ DCHECK(has_video_); \
+ EXPECT_CALL(*media_log_, \
+ OnWatchTimeUpdate( \
+ MediaLog::kWatchTimeAudioVideoBackground##key, value)) \
+ .RetiresOnSaturation(); \
+ } while (0)
+
#define EXPECT_WATCH_TIME_FINALIZED() \
EXPECT_CALL(*media_log_, OnWatchTimeFinalized()).RetiresOnSaturation();
@@ -140,6 +149,9 @@ class WatchTimeReporterTest : public testing::TestWithParam<bool> {
void RunHysteresisTest(HysteresisTestCallback test_callback_func) {
Initialize(true, false, false, kSizeJustRight);
+ // Disable background reporting for the hysteresis tests.
+ wtr_->background_reporter_.reset();
+
// Setup all current time expectations first since they need to use the
// InSequence macro for ease of use, but we don't want the watch time
// expectations to be in sequence (or expectations would depend on sorted
@@ -317,20 +329,30 @@ TEST_P(WatchTimeReporterTest, WatchTimeReporterBasic) {
// Tests that basic reporting for the all category works.
TEST_P(WatchTimeReporterTest, WatchTimeReporterShownHidden) {
constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(8);
- constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10);
+ constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(25);
EXPECT_CALL(*this, GetCurrentMediaTime())
.WillOnce(testing::Return(base::TimeDelta()))
.WillOnce(testing::Return(kWatchTimeEarly))
+ .WillOnce(testing::Return(kWatchTimeEarly))
.WillRepeatedly(testing::Return(kWatchTimeLate));
Initialize(true, true, true, kSizeJustRight);
wtr_->OnPlaying();
EXPECT_TRUE(IsMonitoring());
// If we have video, this will halt watch time collection, if only audio it
- // will do nothing. Consume the expectation if audio only.
+ // will do nothing. Consume the expectations if audio only.
wtr_->OnHidden();
- if (!has_video_)
+ if (!has_video_) {
+ GetCurrentMediaTime();
GetCurrentMediaTime();
+ } else {
+ const base::TimeDelta kExpectedWatchTime = kWatchTimeLate - kWatchTimeEarly;
+ EXPECT_BACKGROUND_WATCH_TIME(Ac, kExpectedWatchTime);
+ EXPECT_BACKGROUND_WATCH_TIME(All, kExpectedWatchTime);
+ EXPECT_BACKGROUND_WATCH_TIME(Eme, kExpectedWatchTime);
+ EXPECT_BACKGROUND_WATCH_TIME(Mse, kExpectedWatchTime);
+ EXPECT_WATCH_TIME_FINALIZED();
+ }
const base::TimeDelta kExpectedWatchTime =
has_video_ ? kWatchTimeEarly : kWatchTimeLate;

Powered by Google App Engine
This is Rietveld 408576698