| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 150 |
| 151 TEST(DesktopEngagementServiceTest, TestTimeoutDiscount) { | 151 // Flaky on Mac Debug. See http://crbug.com/646758 |
| 152 #if defined(OS_MACOSX) |
| 153 #define MAYBE_TestTimeoutDiscount DISABLED_TestTimeoutDiscount |
| 154 #else |
| 155 #define MAYBE_TestTimeoutDiscount TestTimeoutDiscount |
| 156 #endif |
| 157 TEST(DesktopEngagementServiceTest, MAYBE_TestTimeoutDiscount) { |
| 152 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); | 158 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); |
| 153 base::HistogramTester histogram_tester; | 159 base::HistogramTester histogram_tester; |
| 154 MockDesktopEngagementService instance; | 160 MockDesktopEngagementService instance; |
| 155 | 161 |
| 156 int inactivity_interval = 2; | 162 int inactivity_interval = 2; |
| 157 instance.SetInactivityTimeoutForTesting(inactivity_interval); | 163 instance.SetInactivityTimeoutForTesting(inactivity_interval); |
| 158 | 164 |
| 159 instance.OnVisibilityChanged(true); | 165 instance.OnVisibilityChanged(true); |
| 160 base::TimeTicks before_session_start = base::TimeTicks::Now(); | 166 base::TimeTicks before_session_start = base::TimeTicks::Now(); |
| 161 instance.OnUserEvent(); // This should start the session | 167 instance.OnUserEvent(); // This should start the session |
| 162 histogram_tester.ExpectTotalCount("Session.TotalDuration", 0); | 168 histogram_tester.ExpectTotalCount("Session.TotalDuration", 0); |
| 163 | 169 |
| 164 // Wait until the session expires. | 170 // Wait until the session expires. |
| 165 while (!instance.is_timeout()) { | 171 while (!instance.is_timeout()) { |
| 166 base::RunLoop().RunUntilIdle(); | 172 base::RunLoop().RunUntilIdle(); |
| 167 } | 173 } |
| 168 base::TimeTicks after_session_end = base::TimeTicks::Now(); | 174 base::TimeTicks after_session_end = base::TimeTicks::Now(); |
| 169 | 175 |
| 170 histogram_tester.ExpectTotalCount("Session.TotalDuration", 1); | 176 histogram_tester.ExpectTotalCount("Session.TotalDuration", 1); |
| 171 // The recorded value should be shorter than the specified inactivity | 177 // The recorded value should be shorter than the specified inactivity |
| 172 // interval. | 178 // interval. |
| 173 base::Bucket bucket = | 179 base::Bucket bucket = |
| 174 histogram_tester.GetAllSamples("Session.TotalDuration")[0]; | 180 histogram_tester.GetAllSamples("Session.TotalDuration")[0]; |
| 175 EXPECT_LE( | 181 EXPECT_LE( |
| 176 bucket.min + inactivity_interval, | 182 bucket.min + inactivity_interval, |
| 177 (after_session_end - before_session_start).InSeconds()); | 183 (after_session_end - before_session_start).InSeconds()); |
| 178 } | 184 } |
| OLD | NEW |