Bug 1305878 - Pull activeTicks and profile creation from the source.
Instead of pulling activeTicks and the profile creation date from the
Telemetry ping, instead we pull them from the places they're tracked,
namely ProfileAge.jsm and SessionRecorder.jsm.
MozReview-Commit-ID: 20jT5wvJSvC
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -7,18 +7,20 @@
this.EXPORTED_SYMBOLS = ["UITour"];
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
+Cu.import("resource://gre/modules/ProfileAge.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource:///modules/RecentWindow.jsm");
+Cu.import("resource://gre/modules/SessionRecorder.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/TelemetryController.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
Cu.importGlobalProperties(["URL"]);
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
"resource://gre/modules/LightweightThemeManager.jsm");
@@ -1795,16 +1797,24 @@ this.UITour = {
aPanel.clientWidth; // flush
return;
}
aPanel.hidden = true;
aPanel.clientWidth; // flush
aPanel.hidden = false;
},
+ _getProfileCreated: Task.async(function*() {
+ return yield new ProfileAge(null, null).created;
+ }),
+
+ _getActiveTicks: Task.async(function*() {
+ return TelemetryController.getSessionRecorder().activeTicks;
+ }),
+
getConfiguration: function(aMessageManager, aWindow, aConfiguration, aCallbackID) {
switch (aConfiguration) {
case "appinfo":
let props = ["defaultUpdateChannel", "version"];
let appinfo = {};
props.forEach(property => appinfo[property] = Services.appinfo[property]);
// Identifier of the partner repack, as stored in preference "distribution.id"
@@ -1859,28 +1869,31 @@ this.UITour = {
};
} else {
data = {engines: [], searchEngineIdentifier: ""};
}
this.sendPageCallback(aMessageManager, aCallbackID, data);
});
break;
case "profileInfo":
- let pingData = TelemetryController.getCurrentPingData(true);
- let profileInfo = {};
- if (pingData !== null) {
+ Task.spawn(function*() {
+ let profileInfo = {
+ activeTicks: null,
+ created: null,
+ };
+
try {
- profileInfo.activeTicks = pingData.payload.simpleMeasurements.activeTicks;
+ profileInfo.activeTicks = yield this._getActiveTicks();
+ } catch (e) {}
+ try {
+ profileInfo.created = yield this._getProfileCreated();
} catch (e) {}
- try {
- profileInfo.creationDate = pingData.environment.profile.creationDate;
- } catch (e) {}
- }
- this.sendPageCallback(aMessageManager, aCallbackID, profileInfo);
+ this.sendPageCallback(aMessageManager, aCallbackID, profileInfo);
+ }.bind(this));
break;
case "sync":
this.sendPageCallback(aMessageManager, aCallbackID, {
setup: Services.prefs.prefHasUserValue("services.sync.username"),
desktopDevices: Preferences.get("services.sync.clients.devices.desktop", 0),
mobileDevices: Preferences.get("services.sync.clients.devices.mobile", 0),
totalDevices: Preferences.get("services.sync.numClients", 0),
});
--- a/browser/components/uitour/test/browser_UITour_profileInfo.js
+++ b/browser/components/uitour/test/browser_UITour_profileInfo.js
@@ -1,43 +1,57 @@
"use strict";
var gTestTab;
var gContentAPI;
var gContentWindow;
-function* setupMainPing(data, options) {
- let scope = {};
- Cu.import("resource://gre/modules/TelemetryController.jsm", scope);
- yield scope.TelemetryController.submitExternalPing("main", data, options);
+let originalGetProfileCreated = UITour._getProfileCreated;
+let originalGetActiveTicks = UITour._getActiveTicks;
+
+registerCleanupFunction(function() {
+ UITour._getProfileCreated = originalGetProfileCreated;
+ UITour._getActiveTicks = originalGetActiveTicks;
+});
+
+function mockGetProfileCreated(date, error) {
+ UITour._getProfileCreated = Task.async(function*() {
+ if (error) {
+ throw error;
+ }
+ return date;
+ });
+}
+
+function* mockGetActiveTicks(ticks, error) {
+ UITour._getActiveTicks = Task.async(function*() {
+ if (error) {
+ throw error;
+ }
+ return ticks;
+ });
}
add_task(setup_UITourTest);
-add_UITour_task(function* test_checkProfileInfo_missingPing() {
+add_UITour_task(function* test_checkProfileInfo() {
+ mockGetProfileCreated(15);
+ yield mockGetActiveTicks(30);
let result = yield getConfigurationPromise("profileInfo");
- is(Object.keys(result).length, 0, "profileInfo should be empty by default");
-});
-
-add_UITour_task(function* test_checkProfileInfo_missingPingData() {
- yield setupMainPing({
- payload: 'does not match expected payload'
- });
- let result = yield getConfigurationPromise("profileInfo");
- is(Object.keys(result).length, 0, "profileInfo should be empty");
+ is(result.created, 15, "created should be 15");
+ is(result.activeTicks, 30, "activeTicks should be 30");
});
-add_UITour_task(function* test_checkProfileInfo() {
- let payload = {
- simpleMeasurements: {
- activeTicks: 7
- }
- };
- let environment = {
- profile: {
- creationDate: 10
- }
- };
- yield setupMainPing(payload, {overrideEnvironment: environment});
+add_UITour_task(function* test_checkProfileInfo_getProfileCreatedError() {
+ mockGetProfileCreated(null, new Error());
+ yield mockGetActiveTicks(30);
let result = yield getConfigurationPromise("profileInfo");
- is(result.activeTicks, 7, "activeTicks should be set");
- is(result.creationDate, 10, "creationDate should be set");
+ is(result.created, null, "created should be null");
+ is(result.activeTicks, 30, "activeTicks should be 30");
});
+
+add_UITour_task(function* test_checkProfileInfo_getActiveTicksError() {
+ mockGetProfileCreated(15);
+ yield mockGetActiveTicks(null, new Error());
+ let result = yield getConfigurationPromise("profileInfo");
+ is(result.created, 15, "created should be 15");
+ is(result.activeTicks, null, "activeTicks should be null");
+});