Review fixes.
draft
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -6,21 +6,21 @@
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/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/TelemetryArchive.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
Cu.importGlobalProperties(["URL"]);
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
"resource://gre/modules/LightweightThemeManager.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ResetProfile",
"resource://gre/modules/ResetProfile.jsm");
@@ -1859,38 +1859,36 @@ this.UITour = {
};
} else {
data = {engines: [], searchEngineIdentifier: ""};
}
this.sendPageCallback(aMessageManager, aCallbackID, data);
});
break;
case "profileInfo":
- TelemetryArchive.promiseArchivedPingList().then(pings => {
- let mainPing = pings.find(ping => ping.type === "main");
- return TelemetryArchive.promiseArchivedPingById(mainPing.id);
- }).then(mainPing => {
- this.sendPageCallback(aMessageManager, aCallbackID, {
- activeTicks: mainPing.payload.simpleMeasurements.activeTicks,
- creationDate: mainPing.environment.profile.creationDate,
- });
- }).catch(error => {
- this.sendPageCallback(aMessageManager, aCallbackID, {});
- });
+ let pingData = TelemetryController.getCurrentPingData(true);
+ let profileInfo = {};
+ if (pingData !== null) {
+ try {
+ profileInfo.activeTicks = pingData.payload.simpleMeasurements.activeTicks;
+ } catch (e) {}
+
+ try {
+ profileInfo.creationDate = pingData.environment.profile.creationDate;
+ } catch (e) {}
+ }
+ this.sendPageCallback(aMessageManager, aCallbackID, profileInfo);
break;
case "sync":
- let data = {
+ this.sendPageCallback(aMessageManager, aCallbackID, {
setup: Services.prefs.prefHasUserValue("services.sync.username"),
- };
- try {
- data.desktopDevices = Services.prefs.getIntPref("services.sync.clients.devices.desktop");
- data.mobileDevices = Services.prefs.getIntPref("services.sync.clients.devices.mobile");
- data.totalDevices = Services.prefs.getIntPref("services.sync.numClients");
- } catch (ex) {}
- this.sendPageCallback(aMessageManager, aCallbackID, data);
+ 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;
case "canReset":
this.sendPageCallback(aMessageManager, aCallbackID, ResetProfile.resetSupported());
break;
default:
log.error("getConfiguration: Unknown configuration requested: " + aConfiguration);
break;
}
--- a/browser/components/uitour/test/browser_UITour_profileInfo.js
+++ b/browser/components/uitour/test/browser_UITour_profileInfo.js
@@ -1,28 +1,29 @@
"use strict";
var gTestTab;
var gContentAPI;
var gContentWindow;
-Cu.import("resource://gre/modules/TelemetryController.jsm", this);
-Cu.import("resource://gre/modules/TelemetryStorage.jsm", this);
+function* setupMainPing(data, options) {
+ let scope = {};
+ Cu.import("resource://gre/modules/TelemetryController.jsm", scope);
+ yield scope.TelemetryController.submitExternalPing("main", data, options);
+}
add_task(setup_UITourTest);
-// TODO: How to set up Telemetry for these tests?
-
add_UITour_task(function* test_checkProfileInfo_missingPing() {
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 TelemetryController.submitExternalPing("main", {
+ yield setupMainPing({
payload: 'does not match expected payload'
});
let result = yield getConfigurationPromise("profileInfo");
is(Object.keys(result).length, 0, "profileInfo should be empty");
});
add_UITour_task(function* test_checkProfileInfo() {
let payload = {
@@ -30,13 +31,13 @@ add_UITour_task(function* test_checkProf
activeTicks: 7
}
};
let environment = {
profile: {
creationDate: 10
}
};
- yield TelemetryController.submitExternalPing("main", payload, {overrideEnvironment: environment});
+ yield setupMainPing(payload, {overrideEnvironment: environment});
let result = yield getConfigurationPromise("profileInfo");
is(result.activeTicks, 7, "activeTicks should be set");
is(result.creationDate, 10, "creationDate should be set");
});
--- a/browser/components/uitour/test/browser_UITour_sync.js
+++ b/browser/components/uitour/test/browser_UITour_sync.js
@@ -16,35 +16,42 @@ add_UITour_task(function* test_checkSync
});
add_UITour_task(function* test_checkSyncSetup_enabled() {
Services.prefs.setCharPref("services.sync.username", "uitour@tests.mozilla.org");
let result = yield getConfigurationPromise("sync");
is(result.setup, true, "Sync should be setup");
});
-add_UITour_task(function* test_checkSyncDesktopDevices() {
+add_UITour_task(function* test_checkSyncCounts() {
Services.prefs.setIntPref("services.sync.clients.devices.desktop", 4);
Services.prefs.setIntPref("services.sync.clients.devices.mobile", 5);
Services.prefs.setIntPref("services.sync.numClients", 9);
let result = yield getConfigurationPromise("sync");
is(result.mobileDevices, 5, "mobileDevices should be set");
is(result.desktopDevices, 4, "desktopDevices should be set");
is(result.totalDevices, 9, "totalDevices should be set");
-});
+
+ Services.prefs.clearUserPref("services.sync.clients.devices.desktop");
+ result = yield getConfigurationPromise("sync");
+ is(result.mobileDevices, 5, "mobileDevices should be set");
+ is(result.desktopDevices, 0, "desktopDevices should be 0");
+ is(result.totalDevices, 9, "totalDevices should be set");
-add_UITour_task(function* test_checkSyncCounts_missing() {
- Services.prefs.clearUserPref("services.sync.clients.devices.desktop");
Services.prefs.clearUserPref("services.sync.clients.devices.mobile");
+ result = yield getConfigurationPromise("sync");
+ is(result.mobileDevices, 0, "mobileDevices should be 0");
+ is(result.desktopDevices, 0, "desktopDevices should be 0");
+ is(result.totalDevices, 9, "totalDevices should be set");
+
Services.prefs.clearUserPref("services.sync.numClients");
- let result = yield getConfigurationPromise("sync");
- let msg = "Sync device counts should not be set by default";
- is(result.desktopDevices, undefined, msg);
- is(result.mobileDevices, undefined, msg);
- is(result.totalDevices, undefined, msg);
+ result = yield getConfigurationPromise("sync");
+ is(result.mobileDevices, 0, "mobileDevices should be 0");
+ is(result.desktopDevices, 0, "desktopDevices should be 0");
+ is(result.totalDevices, 0, "totalDevices should be 0");
});
// The showFirefoxAccounts API is sync related, so we test that here too...
add_UITour_task(function* test_firefoxAccountsNoParams() {
yield gContentAPI.showFirefoxAccounts();
yield BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser, false,
"about:accounts?action=signup&entrypoint=uitour");
});