Bug 757287 - Submit flash version from telemetry ping. r=nfroyd
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 04 Jul 2012 08:30:58 -0400
changeset 98313 936ee90e6e549aa8876a26cfb3cf5c465917f89d
parent 98312 e997600270c2ce1c039bcee4f4da21c8d68a9977
child 98314 78353003288ed531ba2ddf00c65d3104cc2e4860
push id23040
push userryanvm@gmail.com
push dateWed, 04 Jul 2012 16:48:55 +0000
treeherdermozilla-central@f4a40f677391 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs757287
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 757287 - Submit flash version from telemetry ping. r=nfroyd
toolkit/components/telemetry/TelemetryPing.js
toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
--- a/toolkit/components/telemetry/TelemetryPing.js
+++ b/toolkit/components/telemetry/TelemetryPing.js
@@ -350,16 +350,20 @@ TelemetryPing.prototype = {
 
     let theme = LightweightThemeManager.currentTheme;
     if (theme)
       ret.persona = theme.id;
 
     if (this._addons)
       ret.addons = this._addons;
 
+    let flashVersion = this.getFlashVersion();
+    if (flashVersion)
+      ret.flashVersion = flashVersion;
+
     return ret;
   },
 
   /**
    * Pull values from about:memory into corresponding histograms
    */
   gatherMemory: function gatherMemory() {
     let mgr;
@@ -729,16 +733,28 @@ TelemetryPing.prototype = {
       NetUtil.asyncCopy(istream, ostream,
                         function(result) {
                           self.finishTelemetrySave(Components.isSuccessCode(result),
                                                    ostream);
                         });
     }
   },
 
+  getFlashVersion: function getFlashVersion() {
+    let host = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
+    let tags = host.getPluginTags();
+    
+    for (let i = 0; i < tags.length; i++) {
+      if (tags[i].name == "Shockwave Flash")
+        return tags[i].version;
+    }
+    
+    return null;
+  },
+
   /** 
    * Remove observers to avoid leaks
    */
   uninstall: function uninstall() {
     this.detachObservers()
     if (this._hasWindowRestoredObserver) {
       Services.obs.removeObserver(this, "sessionstore-windows-restored");
       this._hasWindowRestoredObserver = false;
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
@@ -14,16 +14,17 @@ Cu.import("resource://gre/modules/Lightw
 
 const PATH = "/submit/telemetry/test-ping";
 const SERVER = "http://localhost:4444";
 const IGNORE_HISTOGRAM = "test::ignore_me";
 const IGNORE_HISTOGRAM_TO_CLONE = "MEMORY_HEAP_ALLOCATED";
 const IGNORE_CLONED_HISTOGRAM = "test::ignore_me_also";
 const ADDON_NAME = "Telemetry test addon";
 const ADDON_HISTOGRAM = "addon-histogram";
+const FLASH_VERSION = "1.1.1.1";
 
 const BinaryInputStream = Components.Constructor(
   "@mozilla.org/binaryinputstream;1",
   "nsIBinaryInputStream",
   "setInputStream");
 const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
 
 var httpserver = new nsHttpServer();
@@ -120,17 +121,18 @@ function decodeRequestPayload(request) {
 function checkPayloadInfo(payload, reason) {
   // get rid of the non-deterministic field
   const expected_info = {
     OS: "XPCShell", 
     appID: "xpcshell@tests.mozilla.org", 
     appVersion: "1", 
     appName: "XPCShell", 
     appBuildID: "2007010101",
-    platformBuildID: "2007010101"
+    platformBuildID: "2007010101",
+    flashVersion: FLASH_VERSION
   };
 
   for (let f in expected_info) {
     do_check_eq(payload.info[f], expected_info[f]);
   }
 
   do_check_eq(payload.info.reason, reason);
   do_check_true("appUpdateChannel" in payload.info);
@@ -321,16 +323,50 @@ function dummyTheme(id) {
     name: Math.random().toString(),
     headerURL: "http://lwttest.invalid/a.png",
     footerURL: "http://lwttest.invalid/b.png",
     textcolor: Math.random().toString(),
     accentcolor: Math.random().toString()
   };
 }
 
+// A fake plugin host for testing flash version telemetry
+var PluginHost = {
+  getPluginTags: function(countRef) {
+    let plugins = [{name: "Shockwave Flash", version: FLASH_VERSION}];
+    countRef.value = plugins.length;
+    return plugins;
+  },
+
+  QueryInterface: function(iid) {
+    if (iid.equals(Ci.nsIPluginHost)
+     || iid.equals(Ci.nsISupports))
+      return this;
+  
+    throw Components.results.NS_ERROR_NO_INTERFACE;
+  }
+}
+
+var PluginHostFactory = {
+  createInstance: function (outer, iid) {
+    if (outer != null)
+      throw Components.results.NS_ERROR_NO_AGGREGATION;
+    return PluginHost.QueryInterface(iid);
+  }
+};
+
+const PLUGINHOST_CONTRACTID = "@mozilla.org/plugin/host;1";
+const PLUGINHOST_CID = Components.ID("{2329e6ea-1f15-4cbe-9ded-6e98e842de0e}");
+
+function registerFakePluginHost() {
+  var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+  registrar.registerFactory(PLUGINHOST_CID, "Fake Plugin Host",
+                            PLUGINHOST_CONTRACTID, PluginHostFactory);
+}
+
 function run_test() {
   try {
     var gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfoDebug);
     gfxInfo.spoofVendorID("0xabcd");
     gfxInfo.spoofDeviceID("0x1234");
   } catch (x) {
     // If we can't test gfxInfo, that's fine, we'll note it later.
   }
@@ -341,15 +377,18 @@ function run_test() {
   // try to make LightweightThemeManager do stuff
   let gInternalManager = Cc["@mozilla.org/addons/integration;1"]
                          .getService(Ci.nsIObserver)
                          .QueryInterface(Ci.nsITimerCallback);
 
   gInternalManager.observe(null, "addons-startup", null);
   LightweightThemeManager.currentTheme = dummyTheme("1234");
 
+  // fake plugin host for consistent flash version data
+  registerFakePluginHost();
+
   Services.obs.addObserver(nonexistentServerObserver, "telemetry-test-xhr-complete", false);
   telemetry_ping();
   // spin the event loop
   do_test_pending();
   // ensure that test runs to completion
   do_register_cleanup(function () do_check_true(gFinished));
- }
+}