OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/media/media_internals.h" | 5 #include "content/browser/media/media_internals.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 MediaInternalsAudioLogTest, | 314 MediaInternalsAudioLogTest, |
315 testing::Values(media::AudioLogFactory::AUDIO_INPUT_CONTROLLER, | 315 testing::Values(media::AudioLogFactory::AUDIO_INPUT_CONTROLLER, |
316 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER, | 316 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER, |
317 media::AudioLogFactory::AUDIO_OUTPUT_STREAM)); | 317 media::AudioLogFactory::AUDIO_OUTPUT_STREAM)); |
318 | 318 |
319 class DirectMediaLog : public media::MediaLog { | 319 class DirectMediaLog : public media::MediaLog { |
320 public: | 320 public: |
321 explicit DirectMediaLog(int render_process_id) | 321 explicit DirectMediaLog(int render_process_id) |
322 : render_process_id_(render_process_id), | 322 : render_process_id_(render_process_id), |
323 internals_(content::MediaInternals::GetInstance()) {} | 323 internals_(content::MediaInternals::GetInstance()) {} |
| 324 ~DirectMediaLog() override {} |
324 | 325 |
325 void AddEvent(std::unique_ptr<media::MediaLogEvent> event) override { | 326 void AddEvent(std::unique_ptr<media::MediaLogEvent> event) override { |
326 std::vector<media::MediaLogEvent> events(1, *event); | 327 std::vector<media::MediaLogEvent> events(1, *event); |
327 internals_->OnMediaEvents(render_process_id_, events); | 328 internals_->OnMediaEvents(render_process_id_, events); |
328 } | 329 } |
329 | 330 |
330 private: | 331 private: |
331 ~DirectMediaLog() override {} | |
332 | |
333 const int render_process_id_; | 332 const int render_process_id_; |
334 MediaInternals* const internals_; | 333 MediaInternals* const internals_; |
335 | 334 |
336 DISALLOW_COPY_AND_ASSIGN(DirectMediaLog); | 335 DISALLOW_COPY_AND_ASSIGN(DirectMediaLog); |
337 }; | 336 }; |
338 | 337 |
339 class MediaInternalsWatchTimeTest : public testing::Test, | 338 class MediaInternalsWatchTimeTest : public testing::Test, |
340 public MediaInternalsTestBase { | 339 public MediaInternalsTestBase { |
341 public: | 340 public: |
342 MediaInternalsWatchTimeTest() | 341 MediaInternalsWatchTimeTest() |
343 : render_process_id_(0), | 342 : render_process_id_(0), |
344 internals_(content::MediaInternals::GetInstance()), | 343 internals_(content::MediaInternals::GetInstance()), |
345 media_log_(new DirectMediaLog(render_process_id_)), | 344 media_log_(new DirectMediaLog(render_process_id_)), |
346 histogram_tester_(new base::HistogramTester()), | 345 histogram_tester_(new base::HistogramTester()), |
347 watch_time_keys_(media::MediaLog::GetWatchTimeKeys()), | 346 watch_time_keys_(media::MediaLog::GetWatchTimeKeys()), |
348 watch_time_power_keys_(media::MediaLog::GetWatchTimePowerKeys()) {} | 347 watch_time_power_keys_(media::MediaLog::GetWatchTimePowerKeys()) {} |
349 | 348 |
350 void Initialize(bool has_audio, | 349 void Initialize(bool has_audio, |
351 bool has_video, | 350 bool has_video, |
352 bool is_mse, | 351 bool is_mse, |
353 bool is_encrypted) { | 352 bool is_encrypted) { |
354 wtr_.reset(new media::WatchTimeReporter( | 353 wtr_.reset(new media::WatchTimeReporter( |
355 has_audio, has_video, is_mse, is_encrypted, true, media_log_, | 354 has_audio, has_video, is_mse, is_encrypted, true, media_log_.get(), |
356 gfx::Size(800, 600), | 355 gfx::Size(800, 600), |
357 base::Bind(&MediaInternalsWatchTimeTest::GetCurrentMediaTime, | 356 base::Bind(&MediaInternalsWatchTimeTest::GetCurrentMediaTime, |
358 base::Unretained(this)))); | 357 base::Unretained(this)))); |
359 wtr_->set_reporting_interval_for_testing(); | 358 wtr_->set_reporting_interval_for_testing(); |
360 } | 359 } |
361 | 360 |
362 void CycleWatchTimeReporter() { | 361 void CycleWatchTimeReporter() { |
363 base::RunLoop run_loop; | 362 base::RunLoop run_loop; |
364 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 363 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
365 run_loop.QuitClosure()); | 364 run_loop.QuitClosure()); |
(...skipping 15 matching lines...) Expand all Loading... |
381 | 380 |
382 void ResetHistogramTester() { | 381 void ResetHistogramTester() { |
383 histogram_tester_.reset(new base::HistogramTester()); | 382 histogram_tester_.reset(new base::HistogramTester()); |
384 } | 383 } |
385 | 384 |
386 MOCK_METHOD0(GetCurrentMediaTime, base::TimeDelta()); | 385 MOCK_METHOD0(GetCurrentMediaTime, base::TimeDelta()); |
387 | 386 |
388 protected: | 387 protected: |
389 const int render_process_id_; | 388 const int render_process_id_; |
390 MediaInternals* const internals_; | 389 MediaInternals* const internals_; |
391 scoped_refptr<DirectMediaLog> media_log_; | 390 std::unique_ptr<DirectMediaLog> media_log_; |
392 std::unique_ptr<base::HistogramTester> histogram_tester_; | 391 std::unique_ptr<base::HistogramTester> histogram_tester_; |
393 std::unique_ptr<media::WatchTimeReporter> wtr_; | 392 std::unique_ptr<media::WatchTimeReporter> wtr_; |
394 const base::flat_set<base::StringPiece> watch_time_keys_; | 393 const base::flat_set<base::StringPiece> watch_time_keys_; |
395 const base::flat_set<base::StringPiece> watch_time_power_keys_; | 394 const base::flat_set<base::StringPiece> watch_time_power_keys_; |
396 | 395 |
397 DISALLOW_COPY_AND_ASSIGN(MediaInternalsWatchTimeTest); | 396 DISALLOW_COPY_AND_ASSIGN(MediaInternalsWatchTimeTest); |
398 }; | 397 }; |
399 | 398 |
400 TEST_F(MediaInternalsWatchTimeTest, BasicAudio) { | 399 TEST_F(MediaInternalsWatchTimeTest, BasicAudio) { |
401 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(5); | 400 constexpr base::TimeDelta kWatchTimeEarly = base::TimeDelta::FromSeconds(5); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 internals_->OnProcessTerminatedForTesting(render_process_id_); | 577 internals_->OnProcessTerminatedForTesting(render_process_id_); |
579 ExpectWatchTime({media::MediaLog::kWatchTimeAudioVideoAll, | 578 ExpectWatchTime({media::MediaLog::kWatchTimeAudioVideoAll, |
580 media::MediaLog::kWatchTimeAudioVideoSrc, | 579 media::MediaLog::kWatchTimeAudioVideoSrc, |
581 media::MediaLog::kWatchTimeAudioVideoEme, | 580 media::MediaLog::kWatchTimeAudioVideoEme, |
582 media::MediaLog::kWatchTimeAudioVideoAc, | 581 media::MediaLog::kWatchTimeAudioVideoAc, |
583 media::MediaLog::kWatchTimeAudioVideoEmbeddedExperience}, | 582 media::MediaLog::kWatchTimeAudioVideoEmbeddedExperience}, |
584 kWatchTimeLate); | 583 kWatchTimeLate); |
585 } | 584 } |
586 | 585 |
587 } // namespace content | 586 } // namespace content |
OLD | NEW |