Chromium Code Reviews| 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 // Flaky on Mac Debug. See http://crbug.com/646758 | 151 TEST(DesktopEngagementServiceTest, TestTimeoutDiscount) { |
| 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) { | |
| 158 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); | 152 base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT); |
| 159 base::HistogramTester histogram_tester; | 153 base::HistogramTester histogram_tester; |
| 160 MockDesktopEngagementService instance; | 154 MockDesktopEngagementService instance; |
| 161 | 155 |
| 162 int inactivity_interval = 2; | 156 int inactivity_interval = 2; |
| 163 instance.SetInactivityTimeoutForTesting(inactivity_interval); | 157 instance.SetInactivityTimeoutForTesting(inactivity_interval); |
| 164 | 158 |
| 165 instance.OnVisibilityChanged(true); | 159 instance.OnVisibilityChanged(true); |
| 166 base::TimeTicks before_session_start = base::TimeTicks::Now(); | 160 base::TimeTicks before_session_start = base::TimeTicks::Now(); |
| 167 instance.OnUserEvent(); // This should start the session | 161 instance.OnUserEvent(); // This should start the session |
| 168 histogram_tester.ExpectTotalCount("Session.TotalDuration", 0); | 162 histogram_tester.ExpectTotalCount("Session.TotalDuration", 0); |
| 169 | 163 |
| 170 // Wait until the session expires. | 164 // Wait until the session expires. |
| 171 while (!instance.is_timeout()) { | 165 while (!instance.is_timeout()) { |
| 172 base::RunLoop().RunUntilIdle(); | 166 base::RunLoop().RunUntilIdle(); |
| 173 } | 167 } |
| 174 base::TimeTicks after_session_end = base::TimeTicks::Now(); | 168 base::TimeTicks after_session_end = base::TimeTicks::Now(); |
| 175 | 169 |
| 176 histogram_tester.ExpectTotalCount("Session.TotalDuration", 1); | 170 histogram_tester.ExpectTotalCount("Session.TotalDuration", 1); |
| 177 // The recorded value should be shorter than the specified inactivity | |
| 178 // interval. | |
| 179 base::Bucket bucket = | 171 base::Bucket bucket = |
| 180 histogram_tester.GetAllSamples("Session.TotalDuration")[0]; | 172 histogram_tester.GetAllSamples("Session.TotalDuration")[0]; |
| 181 EXPECT_LE( | 173 int max_expected_value = |
| 182 bucket.min + inactivity_interval, | 174 (after_session_end - before_session_start - |
| 183 (after_session_end - before_session_start).InSeconds()); | 175 base::TimeDelta::FromSeconds(inactivity_interval)).ToInternalValue(); |
|
Alexei Svitkine (slow)
2016/09/15 16:40:22
If the unit is milliseconds, please convert explic
gayane -on leave until 09-2017
2016/09/15 18:37:36
Done.
| |
| 176 EXPECT_LE(bucket.min, max_expected_value); | |
| 184 } | 177 } |
| OLD | NEW |