| 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) \ | 30 #define EXPECT_BACKGROUND_WATCH_TIME(key, value) \ |
| 31 do { \ | 31 do { \ |
| 32 DCHECK(has_video_); \ | 32 DCHECK(has_video_); \ |
| 33 EXPECT_CALL(*media_log_, \ | 33 EXPECT_CALL(media_log_, \ |
| 34 OnWatchTimeUpdate( \ | 34 OnWatchTimeUpdate( \ |
| 35 MediaLog::kWatchTimeAudioVideoBackground##key, value)) \ | 35 MediaLog::kWatchTimeAudioVideoBackground##key, value)) \ |
| 36 .RetiresOnSaturation(); \ | 36 .RetiresOnSaturation(); \ |
| 37 } while (0) | 37 } while (0) |
| 38 | 38 |
| 39 #define EXPECT_WATCH_TIME_FINALIZED() \ | 39 #define EXPECT_WATCH_TIME_FINALIZED() \ |
| 40 EXPECT_CALL(*media_log_, OnWatchTimeFinalized()).RetiresOnSaturation(); | 40 EXPECT_CALL(media_log_, OnWatchTimeFinalized()).RetiresOnSaturation(); |
| 41 | 41 |
| 42 #define EXPECT_POWER_WATCH_TIME_FINALIZED() \ | 42 #define EXPECT_POWER_WATCH_TIME_FINALIZED() \ |
| 43 EXPECT_CALL(*media_log_, OnPowerWatchTimeFinalized()).RetiresOnSaturation(); | 43 EXPECT_CALL(media_log_, OnPowerWatchTimeFinalized()).RetiresOnSaturation(); |
| 44 | 44 |
| 45 class WatchTimeReporterTest : public testing::TestWithParam<bool> { | 45 class WatchTimeReporterTest : public testing::TestWithParam<bool> { |
| 46 public: | 46 public: |
| 47 WatchTimeReporterTest() | 47 WatchTimeReporterTest() : has_video_(GetParam()) {} |
| 48 : has_video_(GetParam()), | |
| 49 media_log_(new testing::StrictMock<WatchTimeLogMonitor>()) {} | |
| 50 ~WatchTimeReporterTest() override {} | 48 ~WatchTimeReporterTest() override {} |
| 51 | 49 |
| 52 protected: | 50 protected: |
| 53 class WatchTimeLogMonitor : public MediaLog { | 51 class WatchTimeLogMonitor : public MediaLog { |
| 54 public: | 52 public: |
| 55 WatchTimeLogMonitor() {} | 53 WatchTimeLogMonitor() {} |
| 56 | 54 |
| 57 void AddEvent(std::unique_ptr<MediaLogEvent> event) override { | 55 void AddEvent(std::unique_ptr<MediaLogEvent> event) override { |
| 58 ASSERT_EQ(event->type, MediaLogEvent::Type::WATCH_TIME_UPDATE); | 56 ASSERT_EQ(event->type, MediaLogEvent::Type::WATCH_TIME_UPDATE); |
| 59 | 57 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 void Initialize(bool has_audio, | 86 void Initialize(bool has_audio, |
| 89 bool is_mse, | 87 bool is_mse, |
| 90 bool is_encrypted, | 88 bool is_encrypted, |
| 91 const gfx::Size& initial_video_size) { | 89 const gfx::Size& initial_video_size) { |
| 92 if (wtr_ && IsMonitoring()) | 90 if (wtr_ && IsMonitoring()) |
| 93 EXPECT_WATCH_TIME_FINALIZED(); | 91 EXPECT_WATCH_TIME_FINALIZED(); |
| 94 | 92 |
| 95 wtr_.reset(new WatchTimeReporter( | 93 wtr_.reset(new WatchTimeReporter( |
| 96 has_audio, has_video_, is_mse, is_encrypted, false, media_log_, | 94 has_audio, has_video_, is_mse, is_encrypted, false, &media_log_, |
| 97 initial_video_size, | 95 initial_video_size, |
| 98 base::Bind(&WatchTimeReporterTest::GetCurrentMediaTime, | 96 base::Bind(&WatchTimeReporterTest::GetCurrentMediaTime, |
| 99 base::Unretained(this)))); | 97 base::Unretained(this)))); |
| 100 | 98 |
| 101 // Setup the reporting interval to be immediate to avoid spinning real time | 99 // Setup the reporting interval to be immediate to avoid spinning real time |
| 102 // within the unit test. | 100 // within the unit test. |
| 103 wtr_->reporting_interval_ = base::TimeDelta(); | 101 wtr_->reporting_interval_ = base::TimeDelta(); |
| 104 if (wtr_->background_reporter_) | 102 if (wtr_->background_reporter_) |
| 105 wtr_->background_reporter_->reporting_interval_ = base::TimeDelta(); | 103 wtr_->background_reporter_->reporting_interval_ = base::TimeDelta(); |
| 106 } | 104 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 EXPECT_WATCH_TIME(Ac, kWatchTime4 - kWatchTime2); | 254 EXPECT_WATCH_TIME(Ac, kWatchTime4 - kWatchTime2); |
| 257 else | 255 else |
| 258 EXPECT_WATCH_TIME(Battery, kWatchTime4 - kWatchTime2); | 256 EXPECT_WATCH_TIME(Battery, kWatchTime4 - kWatchTime2); |
| 259 EXPECT_WATCH_TIME_FINALIZED(); | 257 EXPECT_WATCH_TIME_FINALIZED(); |
| 260 wtr_.reset(); | 258 wtr_.reset(); |
| 261 } | 259 } |
| 262 | 260 |
| 263 MOCK_METHOD0(GetCurrentMediaTime, base::TimeDelta()); | 261 MOCK_METHOD0(GetCurrentMediaTime, base::TimeDelta()); |
| 264 | 262 |
| 265 const bool has_video_; | 263 const bool has_video_; |
| 264 testing::StrictMock<WatchTimeLogMonitor> media_log_; |
| 266 base::TestMessageLoop message_loop_; | 265 base::TestMessageLoop message_loop_; |
| 267 scoped_refptr<testing::StrictMock<WatchTimeLogMonitor>> media_log_; | |
| 268 std::unique_ptr<WatchTimeReporter> wtr_; | 266 std::unique_ptr<WatchTimeReporter> wtr_; |
| 269 | 267 |
| 270 private: | 268 private: |
| 271 DISALLOW_COPY_AND_ASSIGN(WatchTimeReporterTest); | 269 DISALLOW_COPY_AND_ASSIGN(WatchTimeReporterTest); |
| 272 }; | 270 }; |
| 273 | 271 |
| 274 // Tests that watch time reporting is appropriately enabled or disabled. | 272 // Tests that watch time reporting is appropriately enabled or disabled. |
| 275 TEST_P(WatchTimeReporterTest, WatchTimeReporter) { | 273 TEST_P(WatchTimeReporterTest, WatchTimeReporter) { |
| 276 EXPECT_CALL(*this, GetCurrentMediaTime()) | 274 EXPECT_CALL(*this, GetCurrentMediaTime()) |
| 277 .WillRepeatedly(testing::Return(base::TimeDelta())); | 275 .WillRepeatedly(testing::Return(base::TimeDelta())); |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 }); | 827 }); |
| 830 } | 828 } |
| 831 } | 829 } |
| 832 } | 830 } |
| 833 | 831 |
| 834 INSTANTIATE_TEST_CASE_P(WatchTimeReporterTest, | 832 INSTANTIATE_TEST_CASE_P(WatchTimeReporterTest, |
| 835 WatchTimeReporterTest, | 833 WatchTimeReporterTest, |
| 836 testing::Values(true, false)); | 834 testing::Values(true, false)); |
| 837 | 835 |
| 838 } // namespace media | 836 } // namespace media |
| OLD | NEW |