Bug 1150134 - Part 2: Make fakeNow() test helper easier to use. r=yoric
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Tue, 14 Apr 2015 16:49:57 +0200
changeset 270458 80336b8a9ada4e9770d934e7081a796a53770dba
parent 270457 146ffc4624e9cf6498d1b6cf55b685a291f19841
child 270459 9ad1a99dfdaa53bb3a9f8fa9cfc503a4f8b5d37f
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyoric
bugs1150134
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1150134 - Part 2: Make fakeNow() test helper easier to use. r=yoric
toolkit/components/telemetry/tests/unit/head.js
--- a/toolkit/components/telemetry/tests/unit/head.js
+++ b/toolkit/components/telemetry/tests/unit/head.js
@@ -128,24 +128,34 @@ function createAppInfo(id, name, version
 
 // Fake the timeout functions for the TelemetryScheduler.
 function fakeSchedulerTimer(set, clear) {
   let session = Cu.import("resource://gre/modules/TelemetrySession.jsm");
   session.Policy.setSchedulerTickTimeout = set;
   session.Policy.clearSchedulerTickTimeout = clear;
 }
 
-// Fake the current date.
-function fakeNow(date) {
+/**
+ * Fake the current date.
+ * This passes all received arguments to a new Date constructor and
+ * uses the resulting date to fake the time in Telemetry modules.
+ *
+ * @return Date The new faked date.
+ */
+function fakeNow(...arguments) {
+  const date = new Date(...arguments);
+
   let ping = Cu.import("resource://gre/modules/TelemetryPing.jsm");
   ping.Policy.now = () => date;
   let session = Cu.import("resource://gre/modules/TelemetrySession.jsm");
   session.Policy.now = () => date;
   let environment = Cu.import("resource://gre/modules/TelemetryEnvironment.jsm");
   environment.Policy.now = () => date;
+
+  return new Date(date);
 }
 
 // Return a date that is |offset| ms in the future from |date|.
 function futureDate(date, offset) {
   return new Date(date.getTime() + offset);
 }
 
 function truncateToDays(aMsec) {