| 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 | |
| 155 MockDesktopEngagementService instance; | |
| 156 instance.SetInactivityTimeoutForTesting(2); | |
| 157 | |
| 158 instance.OnVisibilityChanged(true); | |
| 159 instance.OnUserEvent(); | |
| 160 histogram_tester.ExpectTotalCount("Session.TotalDuration", 0); | |
| 161 | |
| 162 // Wait until the session expires. | |
| 163 while (!instance.is_timeout()) { | |
| 164 base::RunLoop().RunUntilIdle(); | |
| 165 } | |
| 166 | |
| 167 histogram_tester.ExpectTotalCount("Session.TotalDuration", 1); | |
| 168 | |
| 169 // The recorded value should be in the 0 bucket even though inactivity timeout | |
| 170 // is 2 seconds. | |
| 171 histogram_tester.ExpectUniqueSample("Session.TotalDuration", 0, 1); | |
| 172 } | |
| OLD | NEW |