Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc

Issue 2333923002: Discount for inactivity timeout for recording session length (Closed)
Patch Set: Modify tests Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc
diff --git a/chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc b/chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc
index 4670e22f60092f77f8783393827f68f09cfc08d8..f2b3365527faa561a5e7da683513bd88e63cc71a 100644
--- a/chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc
+++ b/chrome/browser/metrics/desktop_engagement/desktop_engagement_service_unittest.cc
@@ -147,3 +147,32 @@ TEST(DesktopEngagementServiceTest, TestAudioEvent) {
EXPECT_FALSE(instance.is_audio_playing());
histogram_tester.ExpectTotalCount("Session.TotalDuration", 1);
}
+
+TEST(DesktopEngagementServiceTest, TestTimeoutDiscount) {
+ base::MessageLoop loop(base::MessageLoop::TYPE_DEFAULT);
+ base::HistogramTester histogram_tester;
+ MockDesktopEngagementService instance;
+
+ int inactivity_interval = 2;
+ instance.SetInactivityTimeoutForTesting(inactivity_interval);
+
+ instance.OnVisibilityChanged(true);
+ base::TimeTicks before_session_start = base::TimeTicks::Now();
+ instance.OnUserEvent(); // This should start the session
+ histogram_tester.ExpectTotalCount("Session.TotalDuration", 0);
+
+ // Wait until the session expires.
+ while (!instance.is_timeout()) {
+ base::RunLoop().RunUntilIdle();
+ }
+ base::TimeTicks after_session_end = base::TimeTicks::Now();
+
+ histogram_tester.ExpectTotalCount("Session.TotalDuration", 1);
+ // The recorded value should be shorter than the specified inactivity
+ // interval.
+ base::Bucket bucket =
+ histogram_tester.GetAllSamples("Session.TotalDuration")[0];
+ EXPECT_LE(
+ bucket.min + inactivity_interval,
+ (after_session_end - before_session_start).InSeconds());
+}
« no previous file with comments | « chrome/browser/metrics/desktop_engagement/desktop_engagement_service.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698