Bug 973294 - Count the number of times 'Show Original' is used. r=felipe. a=gavin
authorAsaf Romano <mano@mozilla.com>
Tue, 24 Jun 2014 11:41:52 +0300
changeset 208436 d115bce9216939320400e98401c586dd66dadcd1
parent 208435 8d2520df7f5b9d7b09f7a296adab62a91cc7c56a
child 208437 971a50fabcfc27220d27ecb367332bbaf449c0ff
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, gavin
bugs973294
milestone32.0a2
Bug 973294 - Count the number of times 'Show Original' is used. r=felipe. a=gavin
browser/components/translation/Translation.jsm
browser/components/translation/test/browser_translation_fhr.js
browser/components/translation/test/unit/test_healthreport.js
services/healthreport/docs/dataformat.rst
--- a/browser/components/translation/Translation.jsm
+++ b/browser/components/translation/Translation.jsm
@@ -179,16 +179,17 @@ TranslationUI.prototype = {
     this._state = val;
   },
 
   originalShown: true,
   showOriginalContent: function() {
     this.originalShown = true;
     this.showURLBarIcon();
     this.browser.messageManager.sendAsyncMessage("Translation:ShowOriginal");
+    TranslationHealthReport.recordShowOriginalContent();
   },
 
   showTranslatedContent: function() {
     this.originalShown = false;
     this.showURLBarIcon();
     this.browser.messageManager.sendAsyncMessage("Translation:ShowTranslation");
   },
 
@@ -319,16 +320,23 @@ let TranslationHealthReport = {
   /**
    * Record a denied translation offer.
    */
   recordDeniedTranslationOffer: function () {
     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.
    *
    * @param callback
    *        The function that will be passed the translation provider.
    */
   _withProvider: function (callback) {
     try {
       let reporter = Cc["@mozilla.org/datareporting/service;1"]
@@ -377,16 +385,17 @@ TranslationMeasurement1.prototype = Obje
     pageTranslatedCount: DAILY_COUNTER_FIELD,
     charactersTranslatedCount: DAILY_COUNTER_FIELD,
     translationOpportunityCountsByLanguage: DAILY_LAST_TEXT_FIELD,
     missedTranslationOpportunityCountsByLanguage: DAILY_LAST_TEXT_FIELD,
     pageTranslatedCountsByLanguage: DAILY_LAST_TEXT_FIELD,
     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,
   },
 
   shouldIncludeField: function (field) {
     if (!Services.prefs.getBoolPref("toolkit.telemetry.enabled")) {
       // This measurement should only be included when telemetry is
       // enabled, so we will not include any fields.
@@ -522,16 +531,25 @@ TranslationProvider.prototype = Object.f
     let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
                                 TranslationMeasurement1.prototype.version);
 
     return this._enqueueTelemetryStorageTask(function* recordTask() {
       yield m.incrementDailyCounter("deniedTranslationOffer");
     }.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);
 
     return this._enqueueTelemetryStorageTask(function* recordTask() {
       let detectLanguageEnabled = Services.prefs.getBoolPref("browser.translation.detectLanguage");
       yield m.setDailyLastNumeric("detectLanguageEnabled", detectLanguageEnabled ? 1 : 0);
 
--- a/browser/components/translation/test/browser_translation_fhr.js
+++ b/browser/components/translation/test/browser_translation_fhr.js
@@ -27,17 +27,18 @@ let MetricsChecker = {
       // This should never happen except when the test runs at midnight.
       throw this._midnightError;
     }
 
     // .get() may return `undefined`, which we can't compute.
     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;
   }),
 
   checkAdditions: Task.async(function* (additions) {
     let prevMetrics = this._metrics, prevMetricsTime = this._metricsTime;
     try {
       yield this.updateMetrics();
@@ -100,16 +101,25 @@ add_task(function* test_deny_translation
   // 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);
   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 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");
   return notif._getAnonElt(anonid);
 }
 
 function offerTranslatationFor(text, from) {
   return Task.spawn(function* task_offer_translation() {
--- a/browser/components/translation/test/unit/test_healthreport.js
+++ b/browser/components/translation/test/unit/test_healthreport.js
@@ -191,36 +191,44 @@ add_task(function* test_record_translati
   Assert.equal(day.get("detectedLanguageChangedBefore"), 1);
   Assert.ok(day.has("detectedLanguageChangedAfter"));
   Assert.equal(day.get("detectedLanguageChangedAfter"), 2);
 
   yield provider.shutdown();
   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();
   Assert.equal(values.days.size, 1);
   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() {
   let storage = yield Metrics.Storage("translation");
   let provider = new TranslationProvider();
   yield provider.init(storage);
   let now = new Date();
 
@@ -272,16 +280,18 @@ add_task(function* test_healthreporter_j
     yield provider.recordTranslation("fr", "en", 1000, now);
     yield provider.recordLanguageChange(false);
 
     yield provider.recordTranslationOpportunity("es", now);
     yield provider.recordTranslation("es", "en", 1000, now);
 
     yield provider.recordDeniedTranslationOffer();
 
+    yield provider.recordShowOriginalContent();
+
     yield reporter.collectMeasurements();
     let payload = yield reporter.getJSONPayload(true);
     let today = reporter._formatDate(now);
 
     Assert.ok(today in payload.data.days);
     let day = payload.data.days[today];
 
     Assert.ok("org.mozilla.translation.translation" in day);
@@ -307,16 +317,19 @@ add_task(function* test_healthreporter_j
 
     Assert.ok("detectedLanguageChangedBefore" in translations);
     Assert.equal(translations["detectedLanguageChangedBefore"], 1);
     Assert.ok("detectedLanguageChangedAfter" in translations);
     Assert.equal(translations["detectedLanguageChangedAfter"], 1);
     
     Assert.ok("deniedTranslationOffer" in translations);
     Assert.equal(translations["deniedTranslationOffer"], 1);
+
+    Assert.ok("showOriginalContent" in translations);
+    Assert.equal(translations["showOriginalContent"], 1);
   } finally {
     reporter._shutdown();
   }
 });
 
 // Test the payload after recording with telemetry disabled.
 add_task(function* test_healthreporter_json2() {
   Services.prefs.setBoolPref("toolkit.telemetry.enabled", false);
@@ -333,16 +346,18 @@ add_task(function* test_healthreporter_j
     yield provider.recordTranslation("fr", "en", 1000, now);
     yield provider.recordLanguageChange(false);
 
     yield provider.recordTranslationOpportunity("es", now);
     yield provider.recordTranslation("es", "en", 1000, now);
 
     yield provider.recordDeniedTranslationOffer();
 
+    yield provider.recordShowOriginalContent();
+
     yield reporter.collectMeasurements();
     let payload = yield reporter.getJSONPayload(true);
     let today = reporter._formatDate(now);
 
     Assert.ok(today in payload.data.days);
     let day = payload.data.days[today];
 
     Assert.ok("org.mozilla.translation.translation" in day);
@@ -352,12 +367,13 @@ add_task(function* test_healthreporter_j
     Assert.ok(!("translationOpportunityCount" in translations));
     Assert.ok(!("pageTranslatedCount" in translations));
     Assert.ok(!("charactersTranslatedCount" in translations));
     Assert.ok(!("translationOpportunityCountsByLanguage" in translations));
     Assert.ok(!("pageTranslatedCountsByLanguage" in translations));
     Assert.ok(!("detectedLanguageChangedBefore" in translations));
     Assert.ok(!("detectedLanguageChangedAfter" in translations));
     Assert.ok(!("deniedTranslationOffer" in translations));
+    Assert.ok(!("showOriginalContent" in translations));
   } finally {
     reporter._shutdown();
   }
 });
--- a/services/healthreport/docs/dataformat.rst
+++ b/services/healthreport/docs/dataformat.rst
@@ -1552,19 +1552,22 @@ charactersTranslatedCount
     Integer count of the number of characters translated.
 detectedLanguageChangedBefore
     Integer count of the number of times the user manually adjusted the detected
     language before translating.
 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:
 
 translationOpportunityCountsByLanguage
     A mapping from language to count of opportunities to translate that
     language.
 missedTranslationOpportunityCountsByLanguage
@@ -1591,17 +1594,18 @@ Example
       "_v": 1,
       "detectLanguageEnabled": 1,
       "showTranslationUI": 1,
       "translationOpportunityCount": 134,
       "pageTranslatedCount": 6,
       "charactersTranslatedCount": "1126",
       "detectedLanguageChangedBefore": 1,
       "detectedLanguageChangedAfter": 2,
-      "deniedTranslationOffer": 3
+      "deniedTranslationOffer": 3,
+      "showOriginalContent": 2,
       "translationOpportunityCountsByLanguage": {
         "fr": 100,
         "es": 34
       },
       "pageTranslatedCountsByLanguage": {
         "fr": {
           "total": 6,
           "es": 5,