| OLD | NEW |
| 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" |
| 11 #include "media/base/mock_media_log.h" | 11 #include "media/base/mock_media_log.h" |
| 12 #include "media/blink/watch_time_reporter.h" | 12 #include "media/blink/watch_time_reporter.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 constexpr gfx::Size kSizeJustRight = gfx::Size(201, 201); | 18 constexpr gfx::Size kSizeJustRight = gfx::Size(201, 201); |
| 19 | 19 |
| 20 #define EXPECT_WATCH_TIME(key, value) \ | 20 #define EXPECT_WATCH_TIME(key, value) \ |
| 21 do { \ | 21 do { \ |
| 22 EXPECT_CALL( \ | 22 EXPECT_CALL( \ |
| 23 *media_log_, \ | 23 *media_log_, \ |
| 24 OnWatchTimeUpdate(has_video_ ? MediaLog::kWatchTimeAudioVideo##key \ | 24 OnWatchTimeUpdate(has_video_ ? MediaLog::kWatchTimeAudioVideo##key \ |
| 25 : MediaLog::kWatchTimeAudio##key, \ | 25 : MediaLog::kWatchTimeAudio##key, \ |
| 26 value)) \ | 26 value)) \ |
| 27 .RetiresOnSaturation(); \ | 27 .RetiresOnSaturation(); \ |
| 28 } while (0) | 28 } while (0) |
| 29 | 29 |
| 30 #define EXPECT_BACKGROUND_WATCH_TIME(key, value) \ |
| 31 do { \ |
| 32 DCHECK(has_video_); \ |
| 33 EXPECT_CALL(*media_log_, \ |
| 34 OnWatchTimeUpdate( \ |
| 35 MediaLog::kWatchTimeAudioVideoBackground##key, value)) \ |
| 36 .RetiresOnSaturation(); \ |
| 37 } while (0) |
| 38 |
| 30 #define EXPECT_WATCH_TIME_FINALIZED() \ | 39 #define EXPECT_WATCH_TIME_FINALIZED() \ |
| 31 EXPECT_CALL(*media_log_, OnWatchTimeFinalized()).RetiresOnSaturation(); | 40 EXPECT_CALL(*media_log_, OnWatchTimeFinalized()).RetiresOnSaturation(); |
| 32 | 41 |
| 33 #define EXPECT_POWER_WATCH_TIME_FINALIZED() \ | 42 #define EXPECT_POWER_WATCH_TIME_FINALIZED() \ |
| 34 EXPECT_CALL(*media_log_, OnPowerWatchTimeFinalized()).RetiresOnSaturation(); | 43 EXPECT_CALL(*media_log_, OnPowerWatchTimeFinalized()).RetiresOnSaturation(); |
| 35 | 44 |
| 36 class WatchTimeReporterTest : public testing::TestWithParam<bool> { | 45 class WatchTimeReporterTest : public testing::TestWithParam<bool> { |
| 37 public: | 46 public: |
| 38 WatchTimeReporterTest() | 47 WatchTimeReporterTest() |
| 39 : has_video_(GetParam()), | 48 : has_video_(GetParam()), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 ~WatchTimeLogMonitor() override {} | 82 ~WatchTimeLogMonitor() override {} |
| 74 | 83 |
| 75 private: | 84 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(WatchTimeLogMonitor); | 85 DISALLOW_COPY_AND_ASSIGN(WatchTimeLogMonitor); |
| 77 }; | 86 }; |
| 78 | 87 |
| 79 void Initialize(bool has_audio, | 88 void Initialize(bool has_audio, |
| 80 bool is_mse, | 89 bool is_mse, |
| 81 bool is_encrypted, | 90 bool is_encrypted, |
| 82 const gfx::Size& initial_video_size) { | 91 const gfx::Size& initial_video_size) { |
| 92 if (wtr_ && IsMonitoring()) |
| 93 EXPECT_WATCH_TIME_FINALIZED(); |
| 94 |
| 83 wtr_.reset(new WatchTimeReporter( | 95 wtr_.reset(new WatchTimeReporter( |
| 84 has_audio, has_video_, is_mse, is_encrypted, false, media_log_, | 96 has_audio, has_video_, is_mse, is_encrypted, false, media_log_, |
| 85 initial_video_size, | 97 initial_video_size, |
| 86 base::Bind(&WatchTimeReporterTest::GetCurrentMediaTime, | 98 base::Bind(&WatchTimeReporterTest::GetCurrentMediaTime, |
| 87 base::Unretained(this)))); | 99 base::Unretained(this)))); |
| 88 | 100 |
| 89 // Setup the reporting interval to be immediate to avoid spinning real time | 101 // Setup the reporting interval to be immediate to avoid spinning real time |
| 90 // within the unit test. | 102 // within the unit test. |
| 91 wtr_->reporting_interval_ = base::TimeDelta(); | 103 wtr_->reporting_interval_ = base::TimeDelta(); |
| 104 if (wtr_->background_reporter_) |
| 105 wtr_->background_reporter_->reporting_interval_ = base::TimeDelta(); |
| 92 } | 106 } |
| 93 | 107 |
| 94 void CycleReportingTimer() { | 108 void CycleReportingTimer() { |
| 95 base::RunLoop run_loop; | 109 base::RunLoop run_loop; |
| 96 message_loop_.task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); | 110 message_loop_.task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure()); |
| 97 run_loop.Run(); | 111 run_loop.Run(); |
| 98 } | 112 } |
| 99 | 113 |
| 100 bool IsMonitoring() { return wtr_->reporting_timer_.IsRunning(); } | 114 bool IsMonitoring() const { return wtr_->reporting_timer_.IsRunning(); } |
| 115 |
| 116 bool IsBackgroundMonitoring() const { |
| 117 return wtr_->background_reporter_->reporting_timer_.IsRunning(); |
| 118 } |
| 101 | 119 |
| 102 // We call directly into the reporter for this instead of using an actual | 120 // We call directly into the reporter for this instead of using an actual |
| 103 // PowerMonitorTestSource since that results in a posted tasks which interfere | 121 // PowerMonitorTestSource since that results in a posted tasks which interfere |
| 104 // with our ability to test the timer. | 122 // with our ability to test the timer. |
| 105 void SetOnBatteryPower(bool on_battery_power) { | 123 void SetOnBatteryPower(bool on_battery_power) { |
| 106 wtr_->is_on_battery_power_ = on_battery_power; | 124 wtr_->is_on_battery_power_ = on_battery_power; |
| 107 } | 125 } |
| 108 | 126 |
| 109 void OnPowerStateChange(bool on_battery_power) { | 127 void OnPowerStateChange(bool on_battery_power) { |
| 110 wtr_->OnPowerStateChange(on_battery_power); | 128 wtr_->OnPowerStateChange(on_battery_power); |
| 129 if (wtr_->background_reporter_) |
| 130 wtr_->background_reporter_->OnPowerStateChange(on_battery_power); |
| 111 } | 131 } |
| 112 | 132 |
| 113 enum { | 133 enum { |
| 114 // After |test_callback_func| is executed, should watch time continue to | 134 // After |test_callback_func| is executed, should watch time continue to |
| 115 // accumulate? | 135 // accumulate? |
| 116 kAccumulationContinuesAfterTest = 1, | 136 kAccumulationContinuesAfterTest = 1, |
| 117 | 137 |
| 118 // |test_callback_func| for hysteresis tests enters and exits finalize mode | 138 // |test_callback_func| for hysteresis tests enters and exits finalize mode |
| 119 // for watch time, not all exits require a new current time update. | 139 // for watch time, not all exits require a new current time update. |
| 120 kFinalizeExitDoesNotRequireCurrentTime = 2, | 140 kFinalizeExitDoesNotRequireCurrentTime = 2, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 133 kStartOnBattery = 16, | 153 kStartOnBattery = 16, |
| 134 | 154 |
| 135 // Indicates an extra start event may be generated during test execution. | 155 // Indicates an extra start event may be generated during test execution. |
| 136 kFinalizeInterleavedStartEvent = 32, | 156 kFinalizeInterleavedStartEvent = 32, |
| 137 }; | 157 }; |
| 138 | 158 |
| 139 template <int TestFlags = 0, typename HysteresisTestCallback> | 159 template <int TestFlags = 0, typename HysteresisTestCallback> |
| 140 void RunHysteresisTest(HysteresisTestCallback test_callback_func) { | 160 void RunHysteresisTest(HysteresisTestCallback test_callback_func) { |
| 141 Initialize(true, false, false, kSizeJustRight); | 161 Initialize(true, false, false, kSizeJustRight); |
| 142 | 162 |
| 163 // Disable background reporting for the hysteresis tests. |
| 164 wtr_->background_reporter_.reset(); |
| 165 |
| 143 // Setup all current time expectations first since they need to use the | 166 // Setup all current time expectations first since they need to use the |
| 144 // InSequence macro for ease of use, but we don't want the watch time | 167 // InSequence macro for ease of use, but we don't want the watch time |
| 145 // expectations to be in sequence (or expectations would depend on sorted | 168 // expectations to be in sequence (or expectations would depend on sorted |
| 146 // order of histogram names). | 169 // order of histogram names). |
| 147 constexpr base::TimeDelta kWatchTime1 = base::TimeDelta::FromSeconds(10); | 170 constexpr base::TimeDelta kWatchTime1 = base::TimeDelta::FromSeconds(10); |
| 148 constexpr base::TimeDelta kWatchTime2 = base::TimeDelta::FromSeconds(12); | 171 constexpr base::TimeDelta kWatchTime2 = base::TimeDelta::FromSeconds(12); |
| 149 constexpr base::TimeDelta kWatchTime3 = base::TimeDelta::FromSeconds(15); | 172 constexpr base::TimeDelta kWatchTime3 = base::TimeDelta::FromSeconds(15); |
| 150 constexpr base::TimeDelta kWatchTime4 = base::TimeDelta::FromSeconds(30); | 173 constexpr base::TimeDelta kWatchTime4 = base::TimeDelta::FromSeconds(30); |
| 151 { | 174 { |
| 152 testing::InSequence s; | 175 testing::InSequence s; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 wtr_->OnPlaying(); | 305 wtr_->OnPlaying(); |
| 283 EXPECT_EQ(!has_video_, IsMonitoring()); | 306 EXPECT_EQ(!has_video_, IsMonitoring()); |
| 284 | 307 |
| 285 Initialize(true, false, false, gfx::Size()); | 308 Initialize(true, false, false, gfx::Size()); |
| 286 wtr_->OnPlaying(); | 309 wtr_->OnPlaying(); |
| 287 EXPECT_EQ(!has_video_, IsMonitoring()); | 310 EXPECT_EQ(!has_video_, IsMonitoring()); |
| 288 | 311 |
| 289 Initialize(true, true, false, gfx::Size()); | 312 Initialize(true, true, false, gfx::Size()); |
| 290 wtr_->OnPlaying(); | 313 wtr_->OnPlaying(); |
| 291 EXPECT_EQ(!has_video_, IsMonitoring()); | 314 EXPECT_EQ(!has_video_, IsMonitoring()); |
| 315 |
| 316 if (!has_video_) |
| 317 EXPECT_WATCH_TIME_FINALIZED(); |
| 318 wtr_.reset(); |
| 292 } | 319 } |
| 293 | 320 |
| 294 // Tests that basic reporting for the all category works. | |
| 295 TEST_P(WatchTimeReporterTest, WatchTimeReporterBasic) { | 321 TEST_P(WatchTimeReporterTest, WatchTimeReporterBasic) { |
| 296 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(5); | 322 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(5); |
| 297 constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10); | 323 constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10); |
| 298 EXPECT_CALL(*this, GetCurrentMediaTime()) | 324 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 299 .WillOnce(testing::Return(base::TimeDelta())) | 325 .WillOnce(testing::Return(base::TimeDelta())) |
| 300 .WillOnce(testing::Return(kWatchTimeEarly)) | 326 .WillOnce(testing::Return(kWatchTimeEarly)) |
| 301 .WillRepeatedly(testing::Return(kWatchTimeLate)); | 327 .WillRepeatedly(testing::Return(kWatchTimeLate)); |
| 302 Initialize(true, true, true, kSizeJustRight); | 328 Initialize(true, true, true, kSizeJustRight); |
| 303 wtr_->OnPlaying(); | 329 wtr_->OnPlaying(); |
| 304 EXPECT_TRUE(IsMonitoring()); | 330 EXPECT_TRUE(IsMonitoring()); |
| 305 | 331 |
| 306 // No log should have been generated yet since the message loop has not had | 332 // No log should have been generated yet since the message loop has not had |
| 307 // any chance to pump. | 333 // any chance to pump. |
| 308 CycleReportingTimer(); | 334 CycleReportingTimer(); |
| 309 | 335 |
| 310 EXPECT_WATCH_TIME(Ac, kWatchTimeLate); | 336 EXPECT_WATCH_TIME(Ac, kWatchTimeLate); |
| 311 EXPECT_WATCH_TIME(All, kWatchTimeLate); | 337 EXPECT_WATCH_TIME(All, kWatchTimeLate); |
| 312 EXPECT_WATCH_TIME(Eme, kWatchTimeLate); | 338 EXPECT_WATCH_TIME(Eme, kWatchTimeLate); |
| 313 EXPECT_WATCH_TIME(Mse, kWatchTimeLate); | 339 EXPECT_WATCH_TIME(Mse, kWatchTimeLate); |
| 314 CycleReportingTimer(); | 340 CycleReportingTimer(); |
| 341 |
| 342 EXPECT_WATCH_TIME_FINALIZED(); |
| 343 wtr_.reset(); |
| 315 } | 344 } |
| 316 | 345 |
| 317 // Tests that basic reporting for the all category works. | |
| 318 TEST_P(WatchTimeReporterTest, WatchTimeReporterShownHidden) { | 346 TEST_P(WatchTimeReporterTest, WatchTimeReporterShownHidden) { |
| 319 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(8); | 347 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(8); |
| 320 constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10); | 348 constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(25); |
| 321 EXPECT_CALL(*this, GetCurrentMediaTime()) | 349 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 322 .WillOnce(testing::Return(base::TimeDelta())) | 350 .WillOnce(testing::Return(base::TimeDelta())) |
| 323 .WillOnce(testing::Return(kWatchTimeEarly)) | 351 .WillOnce(testing::Return(kWatchTimeEarly)) |
| 352 .WillOnce(testing::Return(kWatchTimeEarly)) |
| 324 .WillRepeatedly(testing::Return(kWatchTimeLate)); | 353 .WillRepeatedly(testing::Return(kWatchTimeLate)); |
| 325 Initialize(true, true, true, kSizeJustRight); | 354 Initialize(true, true, true, kSizeJustRight); |
| 326 wtr_->OnPlaying(); | 355 wtr_->OnPlaying(); |
| 327 EXPECT_TRUE(IsMonitoring()); | 356 EXPECT_TRUE(IsMonitoring()); |
| 328 | 357 |
| 329 // If we have video, this will halt watch time collection, if only audio it | 358 // If we have video, this will halt watch time collection, if only audio it |
| 330 // will do nothing. Consume the expectation if audio only. | 359 // will do nothing. Consume the expectations if audio only. |
| 331 wtr_->OnHidden(); | 360 wtr_->OnHidden(); |
| 332 if (!has_video_) | 361 if (!has_video_) { |
| 333 GetCurrentMediaTime(); | 362 GetCurrentMediaTime(); |
| 363 GetCurrentMediaTime(); |
| 364 } else { |
| 365 const base::TimeDelta kExpectedWatchTime = kWatchTimeLate - kWatchTimeEarly; |
| 366 EXPECT_BACKGROUND_WATCH_TIME(Ac, kExpectedWatchTime); |
| 367 EXPECT_BACKGROUND_WATCH_TIME(All, kExpectedWatchTime); |
| 368 EXPECT_BACKGROUND_WATCH_TIME(Eme, kExpectedWatchTime); |
| 369 EXPECT_BACKGROUND_WATCH_TIME(Mse, kExpectedWatchTime); |
| 370 EXPECT_WATCH_TIME_FINALIZED(); |
| 371 } |
| 334 | 372 |
| 335 const base::TimeDelta kExpectedWatchTime = | 373 const base::TimeDelta kExpectedWatchTime = |
| 336 has_video_ ? kWatchTimeEarly : kWatchTimeLate; | 374 has_video_ ? kWatchTimeEarly : kWatchTimeLate; |
| 337 EXPECT_WATCH_TIME(Ac, kExpectedWatchTime); | 375 EXPECT_WATCH_TIME(Ac, kExpectedWatchTime); |
| 338 EXPECT_WATCH_TIME(All, kExpectedWatchTime); | 376 EXPECT_WATCH_TIME(All, kExpectedWatchTime); |
| 339 EXPECT_WATCH_TIME(Eme, kExpectedWatchTime); | 377 EXPECT_WATCH_TIME(Eme, kExpectedWatchTime); |
| 340 EXPECT_WATCH_TIME(Mse, kExpectedWatchTime); | 378 EXPECT_WATCH_TIME(Mse, kExpectedWatchTime); |
| 341 EXPECT_WATCH_TIME_FINALIZED(); | 379 EXPECT_WATCH_TIME_FINALIZED(); |
| 342 wtr_.reset(); | 380 wtr_.reset(); |
| 343 } | 381 } |
| 344 | 382 |
| 383 TEST_P(WatchTimeReporterTest, WatchTimeReporterBackgroundHysteresis) { |
| 384 // Only run these background tests when video is present. |
| 385 if (!has_video_) |
| 386 return; |
| 387 |
| 388 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(8); |
| 389 constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10); |
| 390 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 391 .WillOnce(testing::Return(base::TimeDelta())) // 2x for playing |
| 392 .WillOnce(testing::Return(base::TimeDelta())) |
| 393 .WillOnce(testing::Return(kWatchTimeEarly)) // 2x for shown |
| 394 .WillOnce(testing::Return(kWatchTimeEarly)) |
| 395 .WillOnce(testing::Return(kWatchTimeEarly)) // 2x for hidden |
| 396 .WillOnce(testing::Return(kWatchTimeEarly)) |
| 397 .WillOnce(testing::Return(kWatchTimeEarly)) // 1x for timer cycle. |
| 398 .WillRepeatedly(testing::Return(kWatchTimeLate)); |
| 399 Initialize(true, true, true, kSizeJustRight); |
| 400 wtr_->OnHidden(); |
| 401 wtr_->OnPlaying(); |
| 402 EXPECT_TRUE(IsBackgroundMonitoring()); |
| 403 EXPECT_FALSE(IsMonitoring()); |
| 404 |
| 405 wtr_->OnShown(); |
| 406 wtr_->OnHidden(); |
| 407 EXPECT_BACKGROUND_WATCH_TIME(Ac, kWatchTimeEarly); |
| 408 EXPECT_BACKGROUND_WATCH_TIME(All, kWatchTimeEarly); |
| 409 EXPECT_BACKGROUND_WATCH_TIME(Eme, kWatchTimeEarly); |
| 410 EXPECT_BACKGROUND_WATCH_TIME(Mse, kWatchTimeEarly); |
| 411 EXPECT_TRUE(IsBackgroundMonitoring()); |
| 412 EXPECT_TRUE(IsMonitoring()); |
| 413 EXPECT_WATCH_TIME_FINALIZED(); |
| 414 CycleReportingTimer(); |
| 415 |
| 416 EXPECT_TRUE(IsBackgroundMonitoring()); |
| 417 EXPECT_FALSE(IsMonitoring()); |
| 418 |
| 419 EXPECT_BACKGROUND_WATCH_TIME(Ac, kWatchTimeLate); |
| 420 EXPECT_BACKGROUND_WATCH_TIME(All, kWatchTimeLate); |
| 421 EXPECT_BACKGROUND_WATCH_TIME(Eme, kWatchTimeLate); |
| 422 EXPECT_BACKGROUND_WATCH_TIME(Mse, kWatchTimeLate); |
| 423 EXPECT_WATCH_TIME_FINALIZED(); |
| 424 wtr_.reset(); |
| 425 } |
| 426 |
| 427 TEST_P(WatchTimeReporterTest, WatchTimeReporterShownHiddenBackground) { |
| 428 // Only run these background tests when video is present. |
| 429 if (!has_video_) |
| 430 return; |
| 431 |
| 432 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(8); |
| 433 constexpr base::TimeDelta kWatchTimeLate = base::TimeDelta::FromSeconds(10); |
| 434 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 435 .WillOnce(testing::Return(base::TimeDelta())) |
| 436 .WillOnce(testing::Return(base::TimeDelta())) |
| 437 .WillOnce(testing::Return(kWatchTimeEarly)) |
| 438 .WillOnce(testing::Return(kWatchTimeEarly)) |
| 439 .WillRepeatedly(testing::Return(kWatchTimeLate)); |
| 440 Initialize(true, true, true, kSizeJustRight); |
| 441 wtr_->OnHidden(); |
| 442 wtr_->OnPlaying(); |
| 443 EXPECT_TRUE(IsBackgroundMonitoring()); |
| 444 EXPECT_FALSE(IsMonitoring()); |
| 445 |
| 446 wtr_->OnShown(); |
| 447 EXPECT_BACKGROUND_WATCH_TIME(Ac, kWatchTimeEarly); |
| 448 EXPECT_BACKGROUND_WATCH_TIME(All, kWatchTimeEarly); |
| 449 EXPECT_BACKGROUND_WATCH_TIME(Eme, kWatchTimeEarly); |
| 450 EXPECT_BACKGROUND_WATCH_TIME(Mse, kWatchTimeEarly); |
| 451 EXPECT_WATCH_TIME_FINALIZED(); |
| 452 CycleReportingTimer(); |
| 453 |
| 454 EXPECT_FALSE(IsBackgroundMonitoring()); |
| 455 EXPECT_TRUE(IsMonitoring()); |
| 456 |
| 457 EXPECT_WATCH_TIME_FINALIZED(); |
| 458 wtr_.reset(); |
| 459 } |
| 460 |
| 461 TEST_P(WatchTimeReporterTest, WatchTimeReporterHiddenPausedBackground) { |
| 462 // Only run these background tests when video is present. |
| 463 if (!has_video_) |
| 464 return; |
| 465 |
| 466 constexpr base::TimeDelta kWatchTime = base::TimeDelta::FromSeconds(8); |
| 467 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 468 .WillOnce(testing::Return(base::TimeDelta())) |
| 469 .WillOnce(testing::Return(base::TimeDelta())) |
| 470 .WillRepeatedly(testing::Return(kWatchTime)); |
| 471 Initialize(true, true, true, kSizeJustRight); |
| 472 wtr_->OnHidden(); |
| 473 wtr_->OnPlaying(); |
| 474 EXPECT_TRUE(IsBackgroundMonitoring()); |
| 475 EXPECT_FALSE(IsMonitoring()); |
| 476 |
| 477 wtr_->OnPaused(); |
| 478 EXPECT_BACKGROUND_WATCH_TIME(Ac, kWatchTime); |
| 479 EXPECT_BACKGROUND_WATCH_TIME(All, kWatchTime); |
| 480 EXPECT_BACKGROUND_WATCH_TIME(Eme, kWatchTime); |
| 481 EXPECT_BACKGROUND_WATCH_TIME(Mse, kWatchTime); |
| 482 EXPECT_WATCH_TIME_FINALIZED(); |
| 483 CycleReportingTimer(); |
| 484 |
| 485 EXPECT_FALSE(IsBackgroundMonitoring()); |
| 486 EXPECT_FALSE(IsMonitoring()); |
| 487 wtr_.reset(); |
| 488 } |
| 489 |
| 490 TEST_P(WatchTimeReporterTest, WatchTimeReporterHiddenSeekedBackground) { |
| 491 // Only run these background tests when video is present. |
| 492 if (!has_video_) |
| 493 return; |
| 494 |
| 495 constexpr base::TimeDelta kWatchTime = base::TimeDelta::FromSeconds(8); |
| 496 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 497 .WillOnce(testing::Return(base::TimeDelta())) |
| 498 .WillOnce(testing::Return(base::TimeDelta())) |
| 499 .WillRepeatedly(testing::Return(kWatchTime)); |
| 500 Initialize(true, false, true, kSizeJustRight); |
| 501 wtr_->OnHidden(); |
| 502 wtr_->OnPlaying(); |
| 503 EXPECT_TRUE(IsBackgroundMonitoring()); |
| 504 EXPECT_FALSE(IsMonitoring()); |
| 505 |
| 506 EXPECT_BACKGROUND_WATCH_TIME(Ac, kWatchTime); |
| 507 EXPECT_BACKGROUND_WATCH_TIME(All, kWatchTime); |
| 508 EXPECT_BACKGROUND_WATCH_TIME(Eme, kWatchTime); |
| 509 EXPECT_BACKGROUND_WATCH_TIME(Src, kWatchTime); |
| 510 EXPECT_WATCH_TIME_FINALIZED(); |
| 511 wtr_->OnSeeking(); |
| 512 |
| 513 EXPECT_FALSE(IsBackgroundMonitoring()); |
| 514 EXPECT_FALSE(IsMonitoring()); |
| 515 wtr_.reset(); |
| 516 } |
| 517 |
| 518 TEST_P(WatchTimeReporterTest, WatchTimeReporterHiddenPowerBackground) { |
| 519 // Only run these background tests when video is present. |
| 520 if (!has_video_) |
| 521 return; |
| 522 |
| 523 constexpr base::TimeDelta kWatchTime1 = base::TimeDelta::FromSeconds(8); |
| 524 constexpr base::TimeDelta kWatchTime2 = base::TimeDelta::FromSeconds(16); |
| 525 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 526 .WillOnce(testing::Return(base::TimeDelta())) |
| 527 .WillOnce(testing::Return(base::TimeDelta())) |
| 528 .WillOnce(testing::Return(kWatchTime1)) |
| 529 .WillOnce(testing::Return(kWatchTime1)) |
| 530 .WillRepeatedly(testing::Return(kWatchTime2)); |
| 531 Initialize(true, true, true, kSizeJustRight); |
| 532 wtr_->OnHidden(); |
| 533 wtr_->OnPlaying(); |
| 534 EXPECT_TRUE(IsBackgroundMonitoring()); |
| 535 EXPECT_FALSE(IsMonitoring()); |
| 536 |
| 537 OnPowerStateChange(true); |
| 538 EXPECT_BACKGROUND_WATCH_TIME(Ac, kWatchTime1); |
| 539 EXPECT_BACKGROUND_WATCH_TIME(All, kWatchTime1); |
| 540 EXPECT_BACKGROUND_WATCH_TIME(Eme, kWatchTime1); |
| 541 EXPECT_BACKGROUND_WATCH_TIME(Mse, kWatchTime1); |
| 542 EXPECT_POWER_WATCH_TIME_FINALIZED(); |
| 543 CycleReportingTimer(); |
| 544 |
| 545 wtr_->OnPaused(); |
| 546 EXPECT_BACKGROUND_WATCH_TIME(Battery, kWatchTime2 - kWatchTime1); |
| 547 EXPECT_BACKGROUND_WATCH_TIME(All, kWatchTime2); |
| 548 EXPECT_BACKGROUND_WATCH_TIME(Eme, kWatchTime2); |
| 549 EXPECT_BACKGROUND_WATCH_TIME(Mse, kWatchTime2); |
| 550 EXPECT_WATCH_TIME_FINALIZED(); |
| 551 CycleReportingTimer(); |
| 552 |
| 553 EXPECT_FALSE(IsBackgroundMonitoring()); |
| 554 EXPECT_FALSE(IsMonitoring()); |
| 555 wtr_.reset(); |
| 556 } |
| 557 |
| 345 // Tests that starting from a non-zero base works. | 558 // Tests that starting from a non-zero base works. |
| 346 TEST_P(WatchTimeReporterTest, WatchTimeReporterNonZeroStart) { | 559 TEST_P(WatchTimeReporterTest, WatchTimeReporterNonZeroStart) { |
| 347 constexpr base::TimeDelta kWatchTime1 = base::TimeDelta::FromSeconds(5); | 560 constexpr base::TimeDelta kWatchTime1 = base::TimeDelta::FromSeconds(5); |
| 348 constexpr base::TimeDelta kWatchTime2 = base::TimeDelta::FromSeconds(15); | 561 constexpr base::TimeDelta kWatchTime2 = base::TimeDelta::FromSeconds(15); |
| 349 EXPECT_CALL(*this, GetCurrentMediaTime()) | 562 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 350 .WillOnce(testing::Return(kWatchTime1)) | 563 .WillOnce(testing::Return(kWatchTime1)) |
| 351 .WillRepeatedly(testing::Return(kWatchTime2)); | 564 .WillRepeatedly(testing::Return(kWatchTime2)); |
| 352 Initialize(true, true, true, kSizeJustRight); | 565 Initialize(true, true, true, kSizeJustRight); |
| 353 wtr_->OnPlaying(); | 566 wtr_->OnPlaying(); |
| 354 EXPECT_TRUE(IsMonitoring()); | 567 EXPECT_TRUE(IsMonitoring()); |
| 355 | 568 |
| 356 const base::TimeDelta kWatchTime = kWatchTime2 - kWatchTime1; | 569 const base::TimeDelta kWatchTime = kWatchTime2 - kWatchTime1; |
| 357 EXPECT_WATCH_TIME(Ac, kWatchTime); | 570 EXPECT_WATCH_TIME(Ac, kWatchTime); |
| 358 EXPECT_WATCH_TIME(All, kWatchTime); | 571 EXPECT_WATCH_TIME(All, kWatchTime); |
| 359 EXPECT_WATCH_TIME(Eme, kWatchTime); | 572 EXPECT_WATCH_TIME(Eme, kWatchTime); |
| 360 EXPECT_WATCH_TIME(Mse, kWatchTime); | 573 EXPECT_WATCH_TIME(Mse, kWatchTime); |
| 361 CycleReportingTimer(); | 574 CycleReportingTimer(); |
| 575 |
| 576 EXPECT_WATCH_TIME_FINALIZED(); |
| 577 wtr_.reset(); |
| 362 } | 578 } |
| 363 | 579 |
| 364 // Tests that seeking causes an immediate finalization. | 580 // Tests that seeking causes an immediate finalization. |
| 365 TEST_P(WatchTimeReporterTest, SeekFinalizes) { | 581 TEST_P(WatchTimeReporterTest, SeekFinalizes) { |
| 366 constexpr base::TimeDelta kWatchTime = base::TimeDelta::FromSeconds(10); | 582 constexpr base::TimeDelta kWatchTime = base::TimeDelta::FromSeconds(10); |
| 367 EXPECT_CALL(*this, GetCurrentMediaTime()) | 583 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 368 .WillOnce(testing::Return(base::TimeDelta())) | 584 .WillOnce(testing::Return(base::TimeDelta())) |
| 369 .WillOnce(testing::Return(kWatchTime)); | 585 .WillOnce(testing::Return(kWatchTime)); |
| 370 Initialize(true, true, true, kSizeJustRight); | 586 Initialize(true, true, true, kSizeJustRight); |
| 371 wtr_->OnPlaying(); | 587 wtr_->OnPlaying(); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 }); | 820 }); |
| 605 } | 821 } |
| 606 } | 822 } |
| 607 } | 823 } |
| 608 | 824 |
| 609 INSTANTIATE_TEST_CASE_P(WatchTimeReporterTest, | 825 INSTANTIATE_TEST_CASE_P(WatchTimeReporterTest, |
| 610 WatchTimeReporterTest, | 826 WatchTimeReporterTest, |
| 611 testing::Values(true, false)); | 827 testing::Values(true, false)); |
| 612 | 828 |
| 613 } // namespace media | 829 } // namespace media |
| OLD | NEW |