зеркало из https://github.com/mozilla/gecko-dev.git
Bug 977770 - Count the times users manually adjust the offered translation pair. r=felipe.
This commit is contained in:
Родитель
65453653d0
Коммит
900b49eb1e
|
@ -124,6 +124,16 @@ TranslationUI.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
if (this.state == Translation.STATE_OFFER) {
|
||||
if (this.detectedLanguage != aFrom)
|
||||
TranslationHealthReport.recordDetectedLanguageChange(true);
|
||||
} else {
|
||||
if (this.translatedFrom != aFrom)
|
||||
TranslationHealthReport.recordDetectedLanguageChange(false);
|
||||
if (this.translatedTo != aTo)
|
||||
TranslationHealthReport.recordTargetLanguageChange();
|
||||
}
|
||||
|
||||
this.state = Translation.STATE_TRANSLATING;
|
||||
this.translatedFrom = aFrom;
|
||||
this.translatedTo = aTo;
|
||||
|
@ -303,7 +313,7 @@ let TranslationHealthReport = {
|
|||
|
||||
/**
|
||||
* Record a change of the detected language in the health report. This should
|
||||
* only be called when actually executing a translation not every time the
|
||||
* only be called when actually executing a translation, not every time the
|
||||
* user changes in the language in the UI.
|
||||
*
|
||||
* @param beforeFirstTranslation
|
||||
|
@ -313,8 +323,17 @@ let TranslationHealthReport = {
|
|||
* the user has manually adjusted the detected language false should
|
||||
* be passed.
|
||||
*/
|
||||
recordLanguageChange: function (beforeFirstTranslation) {
|
||||
this._withProvider(provider => provider.recordLanguageChange(beforeFirstTranslation));
|
||||
recordDetectedLanguageChange: function (beforeFirstTranslation) {
|
||||
this._withProvider(provider => provider.recordDetectedLanguageChange(beforeFirstTranslation));
|
||||
},
|
||||
|
||||
/**
|
||||
* Record a change of the target language in the health report. This should
|
||||
* only be called when actually executing a translation, not every time the
|
||||
* user changes in the language in the UI.
|
||||
*/
|
||||
recordTargetLanguageChange: function () {
|
||||
this._withProvider(provider => provider.recordTargetLanguageChange());
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -389,6 +408,7 @@ TranslationMeasurement1.prototype = Object.freeze({
|
|||
pageTranslatedCountsByLanguage: DAILY_LAST_TEXT_FIELD,
|
||||
detectedLanguageChangedBefore: DAILY_COUNTER_FIELD,
|
||||
detectedLanguageChangedAfter: DAILY_COUNTER_FIELD,
|
||||
targetLanguageChanged: DAILY_COUNTER_FIELD,
|
||||
deniedTranslationOffer: DAILY_COUNTER_FIELD,
|
||||
showOriginalContent: DAILY_COUNTER_FIELD,
|
||||
detectLanguageEnabled: DAILY_LAST_NUMERIC_FIELD,
|
||||
|
@ -514,7 +534,7 @@ TranslationProvider.prototype = Object.freeze({
|
|||
}.bind(this));
|
||||
},
|
||||
|
||||
recordLanguageChange: function (beforeFirstTranslation) {
|
||||
recordDetectedLanguageChange: function (beforeFirstTranslation) {
|
||||
let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
|
||||
TranslationMeasurement1.prototype.version);
|
||||
|
||||
|
@ -527,6 +547,15 @@ TranslationProvider.prototype = Object.freeze({
|
|||
}.bind(this));
|
||||
},
|
||||
|
||||
recordTargetLanguageChange: function () {
|
||||
let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
|
||||
TranslationMeasurement1.prototype.version);
|
||||
|
||||
return this._enqueueTelemetryStorageTask(function* recordTask() {
|
||||
yield m.incrementDailyCounter("targetLanguageChanged");
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
recordDeniedTranslationOffer: function () {
|
||||
let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
|
||||
TranslationMeasurement1.prototype.version);
|
||||
|
|
|
@ -33,7 +33,10 @@ let MetricsChecker = {
|
|||
pageCount: day.get("pageTranslatedCount") || 0,
|
||||
charCount: day.get("charactersTranslatedCount") || 0,
|
||||
deniedOffers: day.get("deniedTranslationOffer") || 0,
|
||||
showOriginal: day.get("showOriginalContent") || 0
|
||||
showOriginal: day.get("showOriginalContent") || 0,
|
||||
detectedLanguageChangedBefore: day.get("detectedLanguageChangedBefore") || 0,
|
||||
detectedLanguageChangeAfter: day.get("detectedLanguageChangedAfter") || 0,
|
||||
targetLanguageChanged: day.get("targetLanguageChanged") || 0
|
||||
};
|
||||
this._metricsTime = metricsTime;
|
||||
}),
|
||||
|
@ -72,16 +75,16 @@ add_task(function* setup() {
|
|||
});
|
||||
|
||||
// Make sure there are some initial metrics in place when the test starts.
|
||||
yield translate("<h1>Hallo Welt!</h1>", "de", "en");
|
||||
yield translate("<h1>Hallo Welt!</h1>", "de");
|
||||
yield MetricsChecker.updateMetrics();
|
||||
});
|
||||
|
||||
add_task(function* test_fhr() {
|
||||
// Translate a page.
|
||||
yield translate("<h1>Hallo Welt!</h1>", "de", "en");
|
||||
yield translate("<h1>Hallo Welt!</h1>", "de");
|
||||
|
||||
// Translate another page.
|
||||
yield translate("<h1>Hallo Welt!</h1><h1>Bratwurst!</h1>", "de", "en");
|
||||
yield translate("<h1>Hallo Welt!</h1><h1>Bratwurst!</h1>", "de");
|
||||
yield MetricsChecker.checkAdditions({ pageCount: 1, charCount: 21, deniedOffers: 0});
|
||||
});
|
||||
|
||||
|
@ -100,21 +103,62 @@ add_task(function* test_deny_translation_metric() {
|
|||
|
||||
// Test that the close button doesn't record a denied translation if
|
||||
// the infobar is not in its "offer" state.
|
||||
let tab =
|
||||
yield translate("<h1>Hallo Welt!</h1>", "de", "en", false);
|
||||
let tab = yield translate("<h1>Hallo Welt!</h1>", "de", false);
|
||||
yield MetricsChecker.checkAdditions({ deniedOffers: 0 });
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(function* test_show_original() {
|
||||
let tab =
|
||||
yield translate("<h1>Hallo Welt!</h1><h1>Bratwurst!</h1>", "de", "en", false);
|
||||
yield translate("<h1>Hallo Welt!</h1><h1>Bratwurst!</h1>", "de", false);
|
||||
yield MetricsChecker.checkAdditions({ pageCount: 1, showOriginal: 0 });
|
||||
getInfobarElement(tab.linkedBrowser, "showOriginal").doCommand();
|
||||
yield MetricsChecker.checkAdditions({ pageCount: 0, showOriginal: 1 });
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
add_task(function* test_language_change() {
|
||||
for (let i of Array(4)) {
|
||||
let tab = yield offerTranslatationFor("<h1>Hallo Welt!</h1>", "fr");
|
||||
let browser = tab.linkedBrowser;
|
||||
// In the offer state, translation is executed by the Translate button,
|
||||
// so we expect just a single recoding.
|
||||
let detectedLangMenulist = getInfobarElement(browser, "detectedLanguage");
|
||||
simulateUserSelectInMenulist(detectedLangMenulist, "de");
|
||||
simulateUserSelectInMenulist(detectedLangMenulist, "it");
|
||||
simulateUserSelectInMenulist(detectedLangMenulist, "de");
|
||||
yield acceptTranslationOffer(tab);
|
||||
|
||||
// In the translated state, a change in the form or to menulists
|
||||
// triggers re-translation right away.
|
||||
let fromLangMenulist = getInfobarElement(browser, "fromLanguage");
|
||||
simulateUserSelectInMenulist(fromLangMenulist, "it");
|
||||
simulateUserSelectInMenulist(fromLangMenulist, "de");
|
||||
|
||||
// Selecting the same item shouldn't count.
|
||||
simulateUserSelectInMenulist(fromLangMenulist, "de");
|
||||
|
||||
let toLangMenulist = getInfobarElement(browser, "toLanguage");
|
||||
simulateUserSelectInMenulist(toLangMenulist, "fr");
|
||||
simulateUserSelectInMenulist(toLangMenulist, "en");
|
||||
simulateUserSelectInMenulist(toLangMenulist, "it");
|
||||
|
||||
// Selecting the same item shouldn't count.
|
||||
simulateUserSelectInMenulist(toLangMenulist, "it");
|
||||
|
||||
// Setting the target language to the source language is a no-op,
|
||||
// so it shouldn't count.
|
||||
simulateUserSelectInMenulist(toLangMenulist, "de");
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
}
|
||||
yield MetricsChecker.checkAdditions({
|
||||
detectedLanguageChangedBefore: 4,
|
||||
detectedLanguageChangeAfter: 8,
|
||||
targetLanguageChanged: 12
|
||||
});
|
||||
});
|
||||
|
||||
function getInfobarElement(browser, anonid) {
|
||||
let notif = browser.translationUI
|
||||
.notificationBox.getNotificationWithValue("translation");
|
||||
|
@ -140,19 +184,18 @@ function offerTranslatationFor(text, from) {
|
|||
});
|
||||
}
|
||||
|
||||
function acceptTranslationOffer(tab, to) {
|
||||
function acceptTranslationOffer(tab) {
|
||||
return Task.spawn(function* task_accept_translation_offer() {
|
||||
let browser = tab.linkedBrowser;
|
||||
getInfobarElement(browser, "toLanguage").value = to;
|
||||
getInfobarElement(browser, "toLanguage").doCommand();
|
||||
getInfobarElement(browser, "translate").doCommand();
|
||||
yield waitForMessage(browser, "Translation:Finished");
|
||||
});
|
||||
}
|
||||
|
||||
function translate(text, from, to, closeTab = true) {
|
||||
function translate(text, from, closeTab = true) {
|
||||
return Task.spawn(function* task_translate() {
|
||||
let tab = yield offerTranslatationFor(text, from);
|
||||
yield acceptTranslationOffer(tab, to);
|
||||
yield acceptTranslationOffer(tab);
|
||||
if (closeTab) {
|
||||
gBrowser.removeTab(tab);
|
||||
} else {
|
||||
|
@ -180,3 +223,8 @@ function promiseBrowserLoaded(browser) {
|
|||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
function simulateUserSelectInMenulist(menulist, value) {
|
||||
menulist.value = value;
|
||||
menulist.doCommand();
|
||||
}
|
||||
|
|
|
@ -173,13 +173,16 @@ add_task(function* test_record_translation() {
|
|||
yield provider.init(storage);
|
||||
let now = new Date();
|
||||
|
||||
// Record a language change before translation.
|
||||
yield provider.recordLanguageChange(true);
|
||||
// Record a change to the source language changes before translation.
|
||||
yield provider.recordDetectedLanguageChange(true);
|
||||
|
||||
// Record two language changes after translation.
|
||||
yield provider.recordLanguageChange(false);
|
||||
yield provider.recordLanguageChange(false);
|
||||
// Record two changes to the source language changes after translation.
|
||||
yield provider.recordDetectedLanguageChange(false);
|
||||
yield provider.recordDetectedLanguageChange(false);
|
||||
|
||||
// Record two changes to the target language.
|
||||
yield provider.recordTargetLanguageChange();
|
||||
yield provider.recordTargetLanguageChange();
|
||||
|
||||
let m = provider.getMeasurement("translation", 1);
|
||||
let values = yield m.getValues();
|
||||
|
@ -189,8 +192,11 @@ add_task(function* test_record_translation() {
|
|||
|
||||
Assert.ok(day.has("detectedLanguageChangedBefore"));
|
||||
Assert.equal(day.get("detectedLanguageChangedBefore"), 1);
|
||||
|
||||
Assert.ok(day.has("detectedLanguageChangedAfter"));
|
||||
Assert.equal(day.get("detectedLanguageChangedAfter"), 2);
|
||||
Assert.ok(day.has("targetLanguageChanged"));
|
||||
Assert.equal(day.get("targetLanguageChanged"), 2);
|
||||
|
||||
yield provider.shutdown();
|
||||
yield storage.close();
|
||||
|
@ -276,9 +282,9 @@ add_task(function* test_healthreporter_json() {
|
|||
yield reporter._providerManager.registerProvider(provider);
|
||||
|
||||
yield provider.recordTranslationOpportunity("fr", now);
|
||||
yield provider.recordLanguageChange(true);
|
||||
yield provider.recordDetectedLanguageChange(true);
|
||||
yield provider.recordTranslation("fr", "en", 1000, now);
|
||||
yield provider.recordLanguageChange(false);
|
||||
yield provider.recordDetectedLanguageChange(false);
|
||||
|
||||
yield provider.recordTranslationOpportunity("es", now);
|
||||
yield provider.recordTranslation("es", "en", 1000, now);
|
||||
|
@ -342,9 +348,9 @@ add_task(function* test_healthreporter_json2() {
|
|||
yield reporter._providerManager.registerProvider(provider);
|
||||
|
||||
yield provider.recordTranslationOpportunity("fr", now);
|
||||
yield provider.recordLanguageChange(true);
|
||||
yield provider.recordDetectedLanguageChange(true);
|
||||
yield provider.recordTranslation("fr", "en", 1000, now);
|
||||
yield provider.recordLanguageChange(false);
|
||||
yield provider.recordDetectedLanguageChange(false);
|
||||
|
||||
yield provider.recordTranslationOpportunity("es", now);
|
||||
yield provider.recordTranslation("es", "en", 1000, now);
|
||||
|
|
|
@ -1556,6 +1556,9 @@ detectedLanguageChangedBefore
|
|||
detectedLanguageChangedAfter
|
||||
Integer count of the number of times the user manually adjusted the detected
|
||||
language after having first translated the page.
|
||||
targetLanguageChanged
|
||||
Integer count of the number of times the user manually adjusted the target
|
||||
language.
|
||||
deniedTranslationOffer
|
||||
Integer count of the number of times the user opted-out offered
|
||||
page translation, either by the Not Now button or by the notification's
|
||||
|
@ -1600,6 +1603,7 @@ Example
|
|||
"charactersTranslatedCount": "1126",
|
||||
"detectedLanguageChangedBefore": 1,
|
||||
"detectedLanguageChangedAfter": 2,
|
||||
"targetLanguageChanged": 0,
|
||||
"deniedTranslationOffer": 3,
|
||||
"showOriginalContent": 2,
|
||||
"translationOpportunityCountsByLanguage": {
|
||||
|
|
Загрузка…
Ссылка в новой задаче