| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/session/media_session_uma_helper.h" | 5 #include "content/browser/media/session/media_session_uma_helper.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_samples.h" | 7 #include "base/metrics/histogram_samples.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "base/test/simple_test_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 using MediaSessionSuspendedSource = | 14 using MediaSessionSuspendedSource = |
| 15 MediaSessionUmaHelper::MediaSessionSuspendedSource; | 15 MediaSessionUmaHelper::MediaSessionSuspendedSource; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class MediaSessionUmaHelperTest : public testing::Test { | 19 class MediaSessionUmaHelperTest : public testing::Test { |
| 20 public: | 20 public: |
| 21 MediaSessionUmaHelperTest() = default; | 21 MediaSessionUmaHelperTest() = default; |
| 22 | 22 |
| 23 void SetUp() override { | 23 void SetUp() override { |
| 24 clock_ = new base::SimpleTestClock(); | 24 clock_ = new base::SimpleTestTickClock(); |
| 25 clock_->SetNow(base::Time::Now()); | 25 clock_->SetNowTicks(base::TimeTicks::Now()); |
| 26 media_session_uma_helper_.SetClockForTest( | 26 media_session_uma_helper_.SetClockForTest( |
| 27 std::unique_ptr<base::SimpleTestClock>(clock_)); | 27 std::unique_ptr<base::SimpleTestTickClock>(clock_)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void TearDown() override { | 30 void TearDown() override { |
| 31 clock_ = nullptr; | 31 clock_ = nullptr; |
| 32 } | 32 } |
| 33 | 33 |
| 34 base::SimpleTestClock* clock() { return clock_; } | 34 base::SimpleTestTickClock* clock() { return clock_; } |
| 35 | 35 |
| 36 MediaSessionUmaHelper& media_session_uma_helper() { | 36 MediaSessionUmaHelper& media_session_uma_helper() { |
| 37 return media_session_uma_helper_; | 37 return media_session_uma_helper_; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 std::unique_ptr<base::HistogramSamples> GetHistogramSamplesSinceTestStart( | 40 std::unique_ptr<base::HistogramSamples> GetHistogramSamplesSinceTestStart( |
| 41 const std::string& name) { | 41 const std::string& name) { |
| 42 return histogram_tester_.GetHistogramSamplesSinceCreation(name); | 42 return histogram_tester_.GetHistogramSamplesSinceCreation(name); |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 base::SimpleTestClock* clock_ = nullptr; | 46 base::SimpleTestTickClock* clock_ = nullptr; |
| 47 MediaSessionUmaHelper media_session_uma_helper_; | 47 MediaSessionUmaHelper media_session_uma_helper_; |
| 48 base::HistogramTester histogram_tester_; | 48 base::HistogramTester histogram_tester_; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 } // anonymous namespace | 51 } // anonymous namespace |
| 52 | 52 |
| 53 TEST_F(MediaSessionUmaHelperTest, CreateAndKillDoesNothing) { | 53 TEST_F(MediaSessionUmaHelperTest, CreateAndKillDoesNothing) { |
| 54 { | 54 { |
| 55 MediaSessionUmaHelper* uma_helper = new MediaSessionUmaHelper(); | 55 MediaSessionUmaHelper* uma_helper = new MediaSessionUmaHelper(); |
| 56 delete uma_helper; | 56 delete uma_helper; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 media_session_uma_helper().OnSessionInactive(); | 306 media_session_uma_helper().OnSessionInactive(); |
| 307 | 307 |
| 308 // If the session is already inactive, OnSessionInactive() calls are ignored. | 308 // If the session is already inactive, OnSessionInactive() calls are ignored. |
| 309 std::unique_ptr<base::HistogramSamples> samples( | 309 std::unique_ptr<base::HistogramSamples> samples( |
| 310 GetHistogramSamplesSinceTestStart("Media.Session.ActiveTime")); | 310 GetHistogramSamplesSinceTestStart("Media.Session.ActiveTime")); |
| 311 EXPECT_EQ(1, samples->TotalCount()); | 311 EXPECT_EQ(1, samples->TotalCount()); |
| 312 EXPECT_EQ(1, samples->GetCount(3000)); | 312 EXPECT_EQ(1, samples->GetCount(3000)); |
| 313 } | 313 } |
| 314 | 314 |
| 315 } // namespace content | 315 } // namespace content |
| OLD | NEW |