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

Side by Side Diff: media/blink/watch_time_reporter_unittest.cc

Issue 2498113004: Add audio only watch time metrics. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_message_loop.h" 10 #include "base/test/test_message_loop.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 // Tests that watch time reporting is appropriately enabled or disabled. 240 // Tests that watch time reporting is appropriately enabled or disabled.
241 TEST_F(WatchTimeReporterTest, WatchTimeReporter) { 241 TEST_F(WatchTimeReporterTest, WatchTimeReporter) {
242 EXPECT_CALL(*this, GetCurrentMediaTime()) 242 EXPECT_CALL(*this, GetCurrentMediaTime())
243 .WillRepeatedly(testing::Return(base::TimeDelta())); 243 .WillRepeatedly(testing::Return(base::TimeDelta()));
244 244
245 Initialize(false, true, true, true, kSizeJustRight); 245 Initialize(false, true, true, true, kSizeJustRight);
246 wtr_->OnPlaying(); 246 wtr_->OnPlaying();
247 EXPECT_FALSE(IsMonitoring()); 247 EXPECT_FALSE(IsMonitoring());
248 248
249 Initialize(true, false, true, true, kSizeJustRight); 249 Initialize(true, false, true, true, gfx::Size());
250 wtr_->OnPlaying(); 250 wtr_->OnPlaying();
251 EXPECT_FALSE(IsMonitoring()); 251 EXPECT_TRUE(IsMonitoring());
252 252
253 constexpr gfx::Size kSizeTooSmall = gfx::Size(100, 100); 253 constexpr gfx::Size kSizeTooSmall = gfx::Size(100, 100);
254 Initialize(true, true, true, true, kSizeTooSmall); 254 Initialize(true, true, true, true, kSizeTooSmall);
255 wtr_->OnPlaying(); 255 wtr_->OnPlaying();
256 EXPECT_FALSE(IsMonitoring()); 256 EXPECT_FALSE(IsMonitoring());
257 257
258 Initialize(true, true, true, true, kSizeJustRight); 258 Initialize(true, true, true, true, kSizeJustRight);
259 wtr_->OnPlaying(); 259 wtr_->OnPlaying();
260 EXPECT_TRUE(IsMonitoring()); 260 EXPECT_TRUE(IsMonitoring());
261 261
262 Initialize(true, true, false, false, kSizeJustRight); 262 Initialize(true, true, false, false, kSizeJustRight);
263 wtr_->OnPlaying(); 263 wtr_->OnPlaying();
264 EXPECT_TRUE(IsMonitoring()); 264 EXPECT_TRUE(IsMonitoring());
265 265
266 Initialize(true, true, true, false, kSizeJustRight); 266 Initialize(true, true, true, false, kSizeJustRight);
267 wtr_->OnPlaying(); 267 wtr_->OnPlaying();
268 EXPECT_TRUE(IsMonitoring()); 268 EXPECT_TRUE(IsMonitoring());
269
270 Initialize(true, false, true, true, gfx::Size());
271 wtr_->OnPlaying();
272 EXPECT_TRUE(IsMonitoring());
273
274 Initialize(true, false, false, false, gfx::Size());
275 wtr_->OnPlaying();
276 EXPECT_TRUE(IsMonitoring());
277
278 Initialize(true, false, true, false, gfx::Size());
279 wtr_->OnPlaying();
280 EXPECT_TRUE(IsMonitoring());
269 } 281 }
270 282
271 // Tests that basic reporting for the all category works. 283 // Tests that basic reporting for the all category works.
272 TEST_F(WatchTimeReporterTest, WatchTimeReporterBasic) { 284 TEST_F(WatchTimeReporterTest, WatchTimeReporterBasic) {
273 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(5); 285 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(5);
274 constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10); 286 constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10);
275 EXPECT_CALL(*this, GetCurrentMediaTime()) 287 EXPECT_CALL(*this, GetCurrentMediaTime())
276 .WillOnce(testing::Return(base::TimeDelta())) 288 .WillOnce(testing::Return(base::TimeDelta()))
277 .WillOnce(testing::Return(kWatchTimeEarly)) 289 .WillOnce(testing::Return(kWatchTimeEarly))
278 .WillRepeatedly(testing::Return(kWatchTimeLate)); 290 .WillRepeatedly(testing::Return(kWatchTimeLate));
279 Initialize(true, true, true, true, kSizeJustRight); 291 Initialize(true, true, true, true, kSizeJustRight);
280 wtr_->OnPlaying(); 292 wtr_->OnPlaying();
281 EXPECT_TRUE(IsMonitoring()); 293 EXPECT_TRUE(IsMonitoring());
282 294
283 // No log should have been generated yet since the message loop has not had 295 // No log should have been generated yet since the message loop has not had
284 // any chance to pump. 296 // any chance to pump.
285 CycleReportingTimer(); 297 CycleReportingTimer();
286 298
287 EXPECT_WATCH_TIME(MediaLog::kWatchTimeAudioVideoAc, kWatchTimeLate); 299 EXPECT_WATCH_TIME(MediaLog::kWatchTimeAudioVideoAc, kWatchTimeLate);
288 EXPECT_WATCH_TIME(MediaLog::kWatchTimeAudioVideoAll, kWatchTimeLate); 300 EXPECT_WATCH_TIME(MediaLog::kWatchTimeAudioVideoAll, kWatchTimeLate);
289 EXPECT_WATCH_TIME(MediaLog::kWatchTimeAudioVideoEme, kWatchTimeLate); 301 EXPECT_WATCH_TIME(MediaLog::kWatchTimeAudioVideoEme, kWatchTimeLate);
290 EXPECT_WATCH_TIME(MediaLog::kWatchTimeAudioVideoMse, kWatchTimeLate); 302 EXPECT_WATCH_TIME(MediaLog::kWatchTimeAudioVideoMse, kWatchTimeLate);
291 CycleReportingTimer(); 303 CycleReportingTimer();
292 } 304 }
305
293 // Tests that starting from a non-zero base works. 306 // Tests that starting from a non-zero base works.
294 TEST_F(WatchTimeReporterTest, WatchTimeReporterNonZeroStart) { 307 TEST_F(WatchTimeReporterTest, WatchTimeReporterNonZeroStart) {
295 constexpr base::TimeDelta kWatchTime1 = base::TimeDelta::FromSeconds(5); 308 constexpr base::TimeDelta kWatchTime1 = base::TimeDelta::FromSeconds(5);
296 constexpr base::TimeDelta kWatchTime2 = base::TimeDelta::FromSeconds(15); 309 constexpr base::TimeDelta kWatchTime2 = base::TimeDelta::FromSeconds(15);
297 EXPECT_CALL(*this, GetCurrentMediaTime()) 310 EXPECT_CALL(*this, GetCurrentMediaTime())
298 .WillOnce(testing::Return(kWatchTime1)) 311 .WillOnce(testing::Return(kWatchTime1))
299 .WillRepeatedly(testing::Return(kWatchTime2)); 312 .WillRepeatedly(testing::Return(kWatchTime2));
300 Initialize(true, true, true, true, kSizeJustRight); 313 Initialize(true, true, true, true, kSizeJustRight);
301 wtr_->OnPlaying(); 314 wtr_->OnPlaying();
302 EXPECT_TRUE(IsMonitoring()); 315 EXPECT_TRUE(IsMonitoring());
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 [i, j, start_event, stop_event]() { 552 [i, j, start_event, stop_event]() {
540 stop_event(i); 553 stop_event(i);
541 stop_event(j); 554 stop_event(j);
542 start_event(i); 555 start_event(i);
543 }); 556 });
544 } 557 }
545 } 558 }
546 } 559 }
547 560
548 } // namespace media 561 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698