From 834aa3ccc50f4377a7a7a4a9f45044fb85d792b9 Mon Sep 17 00:00:00 2001 From: Asaf Romano Date: Tue, 24 Jun 2014 08:36:56 +0300 Subject: [PATCH] Bug 973294 - Firefox counts the number of times that users pick 'Show Original'. r=felipe. --- .../components/translation/Translation.jsm | 18 +++++++++++++ .../test/browser_translation_fhr.js | 12 ++++++++- .../test/unit/test_healthreport.js | 26 +++++++++++++++---- services/healthreport/docs/dataformat.rst | 8 ++++-- 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/browser/components/translation/Translation.jsm b/browser/components/translation/Translation.jsm index 64396829795..a28b1230e48 100644 --- a/browser/components/translation/Translation.jsm +++ b/browser/components/translation/Translation.jsm @@ -184,6 +184,7 @@ TranslationUI.prototype = { this.originalShown = true; this.showURLBarIcon(); this.browser.messageManager.sendAsyncMessage("Translation:ShowOriginal"); + TranslationHealthReport.recordShowOriginalContent(); }, showTranslatedContent: function() { @@ -323,6 +324,13 @@ let TranslationHealthReport = { this._withProvider(provider => provider.recordDeniedTranslationOffer()); }, + /** + * Record a "Show Original" command use. + */ + recordShowOriginalContent: function () { + this._withProvider(provider => provider.recordShowOriginalContent()); + }, + /** * Retrieve the translation provider and pass it to the given function. * @@ -382,6 +390,7 @@ TranslationMeasurement1.prototype = Object.freeze({ detectedLanguageChangedBefore: DAILY_COUNTER_FIELD, detectedLanguageChangedAfter: DAILY_COUNTER_FIELD, deniedTranslationOffer: DAILY_COUNTER_FIELD, + showOriginalContent: DAILY_COUNTER_FIELD, detectLanguageEnabled: DAILY_LAST_NUMERIC_FIELD, showTranslationUI: DAILY_LAST_NUMERIC_FIELD, }, @@ -527,6 +536,15 @@ TranslationProvider.prototype = Object.freeze({ }.bind(this)); }, + recordShowOriginalContent: function () { + let m = this.getMeasurement(TranslationMeasurement1.prototype.name, + TranslationMeasurement1.prototype.version); + + return this._enqueueTelemetryStorageTask(function* recordTask() { + yield m.incrementDailyCounter("showOriginalContent"); + }.bind(this)); + }, + collectDailyData: function () { let m = this.getMeasurement(TranslationMeasurement1.prototype.name, TranslationMeasurement1.prototype.version); diff --git a/browser/components/translation/test/browser_translation_fhr.js b/browser/components/translation/test/browser_translation_fhr.js index decedec1d30..57683bff28a 100644 --- a/browser/components/translation/test/browser_translation_fhr.js +++ b/browser/components/translation/test/browser_translation_fhr.js @@ -32,7 +32,8 @@ let MetricsChecker = { this._metrics = { pageCount: day.get("pageTranslatedCount") || 0, charCount: day.get("charactersTranslatedCount") || 0, - deniedOffers: day.get("deniedTranslationOffer") || 0 + deniedOffers: day.get("deniedTranslationOffer") || 0, + showOriginal: day.get("showOriginalContent") || 0 }; this._metricsTime = metricsTime; }), @@ -103,6 +104,15 @@ add_task(function* test_deny_translation_metric() { gBrowser.removeTab(tab); }); +add_task(function* test_show_original() { + let tab = + yield translate("

Hallo Welt!

Bratwurst!

", "de", "en", false); + yield MetricsChecker.checkAdditions({ pageCount: 1, showOriginal: 0 }); + getInfobarElement(tab.linkedBrowser, "showOriginal").doCommand(); + yield MetricsChecker.checkAdditions({ pageCount: 0, showOriginal: 1 }); + gBrowser.removeTab(tab); +}); + function getInfobarElement(browser, anonid) { let notif = browser.translationUI .notificationBox.getNotificationWithValue("translation"); diff --git a/browser/components/translation/test/unit/test_healthreport.js b/browser/components/translation/test/unit/test_healthreport.js index eed8a851d1d..e9d5200f2f4 100644 --- a/browser/components/translation/test/unit/test_healthreport.js +++ b/browser/components/translation/test/unit/test_healthreport.js @@ -196,14 +196,14 @@ add_task(function* test_record_translation() { yield storage.close(); }); -add_task(function* test_denied_translation_offer() { +function* test_simple_counter(aProviderFuncName, aCounterName) { let storage = yield Metrics.Storage("translation"); let provider = new TranslationProvider(); yield provider.init(storage); let now = new Date(); - yield provider.recordDeniedTranslationOffer(); - yield provider.recordDeniedTranslationOffer(); + yield provider[aProviderFuncName](); + yield provider[aProviderFuncName](); let m = provider.getMeasurement("translation", 1); let values = yield m.getValues(); @@ -211,11 +211,19 @@ add_task(function* test_denied_translation_offer() { Assert.ok(values.days.hasDay(now)); let day = values.days.getDay(now); - Assert.ok(day.has("deniedTranslationOffer")); - Assert.equal(day.get("deniedTranslationOffer"), 2); + Assert.ok(day.has(aCounterName)); + Assert.equal(day.get(aCounterName), 2); yield provider.shutdown(); yield storage.close(); +} + +add_task(function* test_denied_translation_offer() { + yield test_simple_counter("recordDeniedTranslationOffer", "deniedTranslationOffer"); +}); + +add_task(function* test_show_original() { + yield test_simple_counter("recordShowOriginalContent", "showOriginalContent"); }); add_task(function* test_collect_daily() { @@ -277,6 +285,8 @@ add_task(function* test_healthreporter_json() { yield provider.recordDeniedTranslationOffer(); + yield provider.recordShowOriginalContent(); + yield reporter.collectMeasurements(); let payload = yield reporter.getJSONPayload(true); let today = reporter._formatDate(now); @@ -312,6 +322,9 @@ add_task(function* test_healthreporter_json() { Assert.ok("deniedTranslationOffer" in translations); Assert.equal(translations["deniedTranslationOffer"], 1); + + Assert.ok("showOriginalContent" in translations); + Assert.equal(translations["showOriginalContent"], 1); } finally { reporter._shutdown(); } @@ -338,6 +351,8 @@ add_task(function* test_healthreporter_json2() { yield provider.recordDeniedTranslationOffer(); + yield provider.recordShowOriginalContent(); + yield reporter.collectMeasurements(); let payload = yield reporter.getJSONPayload(true); let today = reporter._formatDate(now); @@ -357,6 +372,7 @@ add_task(function* test_healthreporter_json2() { Assert.ok(!("detectedLanguageChangedBefore" in translations)); Assert.ok(!("detectedLanguageChangedAfter" in translations)); Assert.ok(!("deniedTranslationOffer" in translations)); + Assert.ok(!("showOriginalContent" in translations)); } finally { reporter._shutdown(); } diff --git a/services/healthreport/docs/dataformat.rst b/services/healthreport/docs/dataformat.rst index 5d41e43f709..816a0d5781f 100644 --- a/services/healthreport/docs/dataformat.rst +++ b/services/healthreport/docs/dataformat.rst @@ -1557,9 +1557,12 @@ detectedLanguageChangedAfter Integer count of the number of times the user manually adjusted the detected language after having first translated the page. deniedTranslationOffer - Integer count of the numbers of times the user opted-out offered + 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 close button in the "offer" state. +showOriginalContent + Integer count of the number of times the user activated the Show Original + command. Additional daily counts broken down by language are reported in the following properties: @@ -1596,7 +1599,8 @@ Example "charactersTranslatedCount": "1126", "detectedLanguageChangedBefore": 1, "detectedLanguageChangedAfter": 2, - "deniedTranslationOffer": 3 + "deniedTranslationOffer": 3, + showOriginalContent: 2, "translationOpportunityCountsByLanguage": { "fr": 100, "es": 34