Bug 1015525: changes to translation prefs are now recorded by FHR. r=rnewman

This commit is contained in:
Mike de Boer 2014-06-04 15:32:08 +02:00
parent 910fc9c948
commit 7c46c8794e
3 changed files with 65 additions and 2 deletions

View File

@ -20,6 +20,7 @@ Cu.import("resource://gre/modules/Task.jsm", this);
const DAILY_COUNTER_FIELD = {type: Metrics.Storage.FIELD_DAILY_COUNTER};
const DAILY_LAST_TEXT_FIELD = {type: Metrics.Storage.FIELD_DAILY_LAST_TEXT};
const DAILY_LAST_NUMERIC_FIELD = {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC};
this.Translation = {
@ -300,6 +301,8 @@ TranslationMeasurement1.prototype = Object.freeze({
pageTranslatedCountsByLanguage: DAILY_LAST_TEXT_FIELD,
detectedLanguageChangedBefore: DAILY_COUNTER_FIELD,
detectedLanguageChangedAfter: DAILY_COUNTER_FIELD,
detectLanguageEnabled: DAILY_LAST_NUMERIC_FIELD,
showTranslationUI: DAILY_LAST_NUMERIC_FIELD,
},
shouldIncludeField: function (field) {
@ -324,7 +327,7 @@ TranslationMeasurement1.prototype = Object.freeze({
return data;
});
},
},
_wrapJSONSerializer: function (serializer) {
let _parseInPlace = function(o, k) {
@ -414,6 +417,19 @@ TranslationProvider.prototype = Object.freeze({
}.bind(this));
},
collectDailyData: function () {
let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
TranslationMeasurement1.prototype.version);
return this._enqueueTelemetryStorageTask(function* recordTask() {
let detectLanguageEnabled = Services.prefs.getBoolPref("browser.translation.detectLanguage");
yield m.setDailyLastNumeric("detectLanguageEnabled", detectLanguageEnabled ? 1 : 0);
let showTranslationUI = Services.prefs.getBoolPref("browser.translation.ui.show");
yield m.setDailyLastNumeric("showTranslationUI", showTranslationUI ? 1 : 0);
}.bind(this));
},
_enqueueTelemetryStorageTask: function (task) {
if (!Services.prefs.getBoolPref("toolkit.telemetry.enabled")) {
// This measurement should only be included when telemetry is

View File

@ -170,6 +170,44 @@ add_task(function* test_record_translation() {
yield storage.close();
});
add_task(function* test_collect_daily() {
let storage = yield Metrics.Storage("translation");
let provider = new TranslationProvider();
yield provider.init(storage);
let now = new Date();
// Set the prefs we test here to `false` initially.
const kPrefDetectLanguage = "browser.translation.detectLanguage";
const kPrefShowUI = "browser.translation.ui.show";
Services.prefs.setBoolPref(kPrefDetectLanguage, false);
Services.prefs.setBoolPref(kPrefShowUI, false);
// Initially nothing should be configured.
yield provider.collectDailyData();
let m = provider.getMeasurement("translation", 1);
let values = yield m.getValues();
Assert.equal(values.days.size, 1);
Assert.ok(values.days.hasDay(now));
let day = values.days.getDay(now);
Assert.ok(day.has("detectLanguageEnabled"));
Assert.ok(day.has("showTranslationUI"));
// Changes to the repective prefs should be picked up.
Services.prefs.setBoolPref(kPrefDetectLanguage, true);
Services.prefs.setBoolPref(kPrefShowUI, true);
yield provider.collectDailyData();
values = yield m.getValues();
day = values.days.getDay(now);
Assert.equal(day.get("detectLanguageEnabled"), 1);
Assert.equal(day.get("showTranslationUI"), 1);
yield provider.shutdown();
yield storage.close();
});
// Test the payload after recording with telemetry enabled.
add_task(function* test_healthreporter_json() {
Services.prefs.setBoolPref("toolkit.telemetry.enabled", true);
@ -227,7 +265,7 @@ add_task(function* test_healthreporter_json() {
});
// Test the payload after recording with telemetry disabled.
add_task(function* test_healthreporter_json() {
add_task(function* test_healthreporter_json2() {
Services.prefs.setBoolPref("toolkit.telemetry.enabled", false);
let reporter = yield getHealthReporter("healthreporter_json");

View File

@ -1564,6 +1564,13 @@ pageTranslatedCountsByLanguage
language. Each language entry will be an object containing a "total" member
along with individual counts for each language translated to.
Other properties:
detectLanguageEnabled
Whether automatic language detection is enabled. This is an integer, 0 or 1.
showTranslationUI
Whether the translation feature UI will be shown. This is an integer, 0 or 1.
Example
^^^^^^^
@ -1571,6 +1578,8 @@ Example
"org.mozilla.translation.translation": {
"_v": 1,
"detectLanguageEnabled": 1,
"showTranslationUI": 1,
"translationOpportunityCount": 134,
"pageTranslatedCount": 6,
"charactersTranslatedCount": "1126",