| 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 "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h
" | 5 #include "chrome/browser/metrics/desktop_engagement/desktop_engagement_service.h
" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
| 10 #include "base/test/test_mock_time_task_runner.h" | 10 #include "base/test/test_mock_time_task_runner.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // Wait until the session expires. | 140 // Wait until the session expires. |
| 141 while (!instance.is_timeout()) { | 141 while (!instance.is_timeout()) { |
| 142 base::RunLoop().RunUntilIdle(); | 142 base::RunLoop().RunUntilIdle(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 EXPECT_FALSE(instance.in_session()); | 145 EXPECT_FALSE(instance.in_session()); |
| 146 EXPECT_FALSE(instance.is_visible()); | 146 EXPECT_FALSE(instance.is_visible()); |
| 147 EXPECT_FALSE(instance.is_audio_playing()); | 147 EXPECT_FALSE(instance.is_audio_playing()); |
| 148 histogram_tester.ExpectTotalCount("Session.TotalDuration", 1); | 148 histogram_tester.ExpectTotalCount("Session.TotalDuration", 1); |
| 149 } | 149 } |
| 150 |
| 151 TEST(DesktopEngagementServiceTest, TestTimeoutDiscount) { |
| 152 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); |
| 153 base::HistogramTester histogram_tester; |
| 154 MockDesktopEngagementService instance; |
| 155 |
| 156 int inactivity_interval = 2; |
| 157 instance.SetInactivityTimeoutForTesting(inactivity_interval); |
| 158 |
| 159 instance.OnVisibilityChanged(true); |
| 160 base::TimeTicks before_session_start = base::TimeTicks::Now(); |
| 161 instance.OnUserEvent(); // This should start the session |
| 162 histogram_tester.ExpectTotalCount("Session.TotalDuration", 0); |
| 163 |
| 164 // Wait until the session expires. |
| 165 while (!instance.is_timeout()) { |
| 166 base::RunLoop().RunUntilIdle(); |
| 167 } |
| 168 base::TimeTicks after_session_end = base::TimeTicks::Now(); |
| 169 |
| 170 histogram_tester.ExpectTotalCount("Session.TotalDuration", 1); |
| 171 // The recorded value should be shorter than the specified inactivity |
| 172 // interval. |
| 173 base::Bucket bucket = |
| 174 histogram_tester.GetAllSamples("Session.TotalDuration")[0]; |
| 175 EXPECT_LE( |
| 176 bucket.min + inactivity_interval, |
| 177 (after_session_end - before_session_start).InSeconds()); |
| 178 } |
| OLD | NEW |