Bug 1143796 - Add test for TelemetryScheduler tick interval changing when user is idle. r=gfritzsche,a=lmandel
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Thu, 02 Apr 2015 21:33:47 +0200
changeset 265756 c587374a3ba9fd2f26cccadbc2c0c28e43cf08b4
parent 265755 25a86f3c31e124499484ae0e7f23f02c8dfe6541
child 265757 221c6a458a01cdabd477f6f093986a8199c5d3a4
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, lmandel
bugs1143796
milestone39.0a2
Bug 1143796 - Add test for TelemetryScheduler tick interval changing when user is idle. r=gfritzsche,a=lmandel
toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySession.js
@@ -131,16 +131,21 @@ function wrapWithExceptionHandler(f) {
 }
 
 function fakeGenerateUUID(sessionFunc, subsessionFunc) {
   let session = Cu.import("resource://gre/modules/TelemetrySession.jsm");
   session.Policy.generateSessionUUID = sessionFunc;
   session.Policy.generateSubsessionUUID = subsessionFunc;
 }
 
+function fakeIdleNotification(topic) {
+  let session = Cu.import("resource://gre/modules/TelemetrySession.jsm");
+  session.TelemetryScheduler.observe(null, topic, null);
+}
+
 function registerPingHandler(handler) {
   gHttpServer.registerPrefixHandler("/submit/telemetry/",
 				   wrapWithExceptionHandler(handler));
 }
 
 function setupTestData() {
   Telemetry.newHistogram(IGNORE_HISTOGRAM, "never", Telemetry.HISTOGRAM_BOOLEAN);
   Telemetry.histogramFrom(IGNORE_CLONED_HISTOGRAM, IGNORE_HISTOGRAM_TO_CLONE);
@@ -1609,16 +1614,49 @@ add_task(function* test_pingExtendedStat
   }
 
   Assert.ok("addonManager" in ping.payload.simpleMeasurements,
             "addonManager must be sent if the extended set is on.");
   Assert.ok("UITelemetry" in ping.payload.simpleMeasurements,
             "UITelemetry must be sent if the extended set is on.");
 });
 
+add_task(function* test_schedulerUserIdle() {
+  if (gIsAndroid || gIsGonk) {
+    // We don't have the aborted session or the daily ping here.
+    return;
+  }
+
+  const SCHEDULER_TICK_INTERVAL_MS = 5 * 60 * 1000;
+  const SCHEDULER_TICK_IDLE_INTERVAL_MS = 60 * 60 * 1000;
+
+  let schedulerTimeout = 0;
+  fakeSchedulerTimer((callback, timeout) => {
+    schedulerTimeout = timeout;
+  }, () => {});
+  yield TelemetrySession.reset();
+
+  // When not idle, the scheduler should have a 5 minutes tick interval.
+  Assert.equal(schedulerTimeout, SCHEDULER_TICK_INTERVAL_MS);
+
+  // Send an "idle" notification to the scheduler.
+  fakeIdleNotification("idle");
+
+  // When idle, the scheduler should have a 1hr tick interval.
+  Assert.equal(schedulerTimeout, SCHEDULER_TICK_IDLE_INTERVAL_MS);
+
+  // Send an "active" notification to the scheduler.
+  fakeIdleNotification("active");
+
+  // When user is back active, the scheduler tick should be 5 minutes again.
+  Assert.equal(schedulerTimeout, SCHEDULER_TICK_INTERVAL_MS);
+
+  yield TelemetrySession.shutdown();
+});
+
 add_task(function* stopServer(){
   gHttpServer.stop(do_test_finished);
 });
 
 // An iterable sequence of http requests
 function Request() {
   let defers = [];
   let current = 0;