Bug 1035337 - Introduce API to record when the infobar is hidden due to 'Never translate this language/site'. r=felipe a=lmandel
authorSteven MacLeod <smacleod@mozilla.com>
Thu, 10 Jul 2014 18:31:56 -0400
changeset 207996 40ef545ebd79f87fbe1868c1475c2ef3c8857e71
parent 207995 93046aa1a6e3e8a7eed1c5093f7591a0968c20bd
child 207997 0874ec920408fca58bff427777e7937f881d9041
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, lmandel
bugs1035337
milestone32.0a2
Bug 1035337 - Introduce API to record when the infobar is hidden due to 'Never translate this language/site'. r=felipe a=lmandel
browser/components/translation/Translation.jsm
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
@@ -313,16 +313,30 @@ let TranslationHealthReport = {
    * of the supported languages.
    * @param language
    *        The language of the page.
    */
   recordMissedTranslationOpportunity: function (language) {
     this._withProvider(provider => provider.recordMissedTranslationOpportunity(language));
   },
 
+  /**
+   * Record an automatically rejected translation offer in the health
+   * report. A translation offer is automatically rejected when a user
+   * has previously clicked "Never translate this language" or "Never
+   * translate this site", which results in the infobar not being shown for
+   * the translation opportunity.
+   *
+   * These translation opportunities should still be recorded in addition to
+   * recording the automatic rejection of the offer.
+   */
+  recordAutoRejectedTranslationOffer: function () {
+    this._withProvider(provider => provider.recordAutoRejectedTranslationOffer());
+  },
+
    /**
    * Record a translation in the health report.
    * @param langFrom
    *        The language of the page.
    * @param langTo
    *        The language translated to
    * @param numCharacters
    *        The number of characters that were translated
@@ -428,16 +442,17 @@ TranslationMeasurement1.prototype = Obje
     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,
     showTranslationUI: DAILY_LAST_NUMERIC_FIELD,
+    autoRejectedTranslationOffer: DAILY_COUNTER_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.
       return false;
     }
@@ -526,16 +541,25 @@ TranslationProvider.prototype = Object.f
       langCounts = JSON.stringify(langCounts);
 
       yield m.setDailyLastText("missedTranslationOpportunityCountsByLanguage",
                                langCounts, date);
 
     }.bind(this));
   },
 
+  recordAutoRejectedTranslationOffer: function (date=new Date()) {
+    let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
+                                TranslationMeasurement1.prototype.version);
+
+    return this._enqueueTelemetryStorageTask(function* recordTask() {
+      yield m.incrementDailyCounter("autoRejectedTranslationOffer", date);
+    }.bind(this));
+  },
+
   recordTranslation: function (langFrom, langTo, numCharacters, date=new Date()) {
     let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
                                 TranslationMeasurement1.prototype.version);
 
     return this._enqueueTelemetryStorageTask(function* recordTask() {
       yield m.incrementDailyCounter("pageTranslatedCount", date);
       yield m.incrementDailyCounter("charactersTranslatedCount", date,
                                     numCharacters);
--- a/browser/components/translation/test/unit/test_healthreport.js
+++ b/browser/components/translation/test/unit/test_healthreport.js
@@ -227,16 +227,21 @@ function* test_simple_counter(aProviderF
 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_show_original() {
+  yield test_simple_counter("recordAutoRejectedTranslationOffer",
+                            "autoRejectedTranslationOffer");
+});
+
 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";
@@ -286,16 +291,18 @@ add_task(function* test_healthreporter_j
     yield provider.recordTranslation("fr", "en", 1000, now);
     yield provider.recordDetectedLanguageChange(false);
 
     yield provider.recordTranslationOpportunity("es", now);
     yield provider.recordTranslation("es", "en", 1000, now);
 
     yield provider.recordDeniedTranslationOffer();
 
+    yield provider.recordAutoRejectedTranslationOffer();
+
     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];
@@ -324,16 +331,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("autoRejectedTranslationOffer" in translations);
+    Assert.equal(translations["autoRejectedTranslationOffer"], 1);
+
     Assert.ok("showOriginalContent" in translations);
     Assert.equal(translations["showOriginalContent"], 1);
   } finally {
     reporter._shutdown();
   }
 });
 
 // Test the payload after recording with telemetry disabled.
@@ -352,16 +362,18 @@ add_task(function* test_healthreporter_j
     yield provider.recordTranslation("fr", "en", 1000, now);
     yield provider.recordDetectedLanguageChange(false);
 
     yield provider.recordTranslationOpportunity("es", now);
     yield provider.recordTranslation("es", "en", 1000, now);
 
     yield provider.recordDeniedTranslationOffer();
 
+    yield provider.recordAutoRejectedTranslationOffer();
+
     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];
@@ -373,13 +385,14 @@ 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(!("autoRejectedTranslationOffer" in translations));
     Assert.ok(!("showOriginalContent" in translations));
   } finally {
     reporter._shutdown();
   }
 });
--- a/services/healthreport/docs/dataformat.rst
+++ b/services/healthreport/docs/dataformat.rst
@@ -1588,16 +1588,20 @@ detectedLanguageChangedAfter
     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
     close button in the "offer" state.
+autoRejectedTranlationOffer
+    Integer count of the number of times the user is not offered page
+    translation because they had previously clicked "Never translate this
+    language" or "Never translate this site".
 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
@@ -1630,16 +1634,17 @@ Example
       "translationOpportunityCount": 134,
       "missedTranslationOpportunityCount": 32,
       "pageTranslatedCount": 6,
       "charactersTranslatedCount": "1126",
       "detectedLanguageChangedBefore": 1,
       "detectedLanguageChangedAfter": 2,
       "targetLanguageChanged": 0,
       "deniedTranslationOffer": 3,
+      "autoRejectedTranlationOffer": 1,
       "showOriginalContent": 2,
       "translationOpportunityCountsByLanguage": {
         "fr": 100,
         "es": 34
       },
       "missedTranslationOpportunityCountsByLanguage": {
         "it": 20,
         "nl": 10,