Bug 1305878 - Add profileInfo to UITour.getConfiguration.
Add a new type of configuration called "profileInfo" that includes
"activeTicks" and "created" properties describing the active time a
user has spent with the client and the date the current profile was
created. These values are provided by ProfileAge.jsm and
SessionRecorder.jsm (via TelemetryController) respectively.
MozReview-Commit-ID: FDOP6tKt0xq
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -7,16 +7,17 @@
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/Task.jsm");
Cu.import("resource://gre/modules/TelemetryController.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
Cu.importGlobalProperties(["URL"]);
@@ -1795,16 +1796,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"
@@ -1858,16 +1867,33 @@ this.UITour = {
.map((engine) => TARGET_SEARCHENGINE_PREFIX + engine.identifier)
};
} else {
data = {engines: [], searchEngineIdentifier: ""};
}
this.sendPageCallback(aMessageManager, aCallbackID, data);
});
break;
+ case "profileInfo":
+ Task.spawn(function*() {
+ let profileInfo = {
+ activeTicks: null,
+ created: null,
+ };
+
+ try {
+ profileInfo.activeTicks = yield this._getActiveTicks();
+ } catch (e) {}
+ try {
+ profileInfo.created = yield this._getProfileCreated();
+ } catch (e) {}
+
+ 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),
});
break;
--- a/browser/components/uitour/test/browser.ini
+++ b/browser/components/uitour/test/browser.ini
@@ -38,8 +38,9 @@ skip-if = os != "mac" # modal dialog dis
[browser_UITour_panel_close_annotation.js]
skip-if = true # Disabled due to frequent failures, bugs 1026310 and 1032137
[browser_UITour_pocket.js]
skip-if = true # Disabled pending removal of pocket UI Tour
[browser_UITour_registerPageID.js]
[browser_UITour_resetProfile.js]
[browser_UITour_sync.js]
[browser_UITour_toggleReaderMode.js]
+[browser_UITour_profileInfo.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/uitour/test/browser_UITour_profileInfo.js
@@ -0,0 +1,57 @@
+"use strict";
+
+var gTestTab;
+var gContentAPI;
+var gContentWindow;
+
+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() {
+ mockGetProfileCreated(15);
+ yield mockGetActiveTicks(30);
+ let result = yield getConfigurationPromise("profileInfo");
+ is(result.created, 15, "created should be 15");
+ is(result.activeTicks, 30, "activeTicks should be 30");
+});
+
+add_UITour_task(function* test_checkProfileInfo_getProfileCreatedError() {
+ mockGetProfileCreated(null, new Error());
+ yield mockGetActiveTicks(30);
+ let result = yield getConfigurationPromise("profileInfo");
+ 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");
+});