Bug 1048785 Part 2: Extend MozLoopAPI with channel, version and OS details. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Fri, 08 Aug 2014 18:10:54 +0100
changeset 198590 05d5db0c856ee9d3ed45a7ed77ad7a1facc7f4e7
parent 198589 eea2155f85dd3db6ed72fdb3afa24c2915f72630
child 198591 1d6500527f66a4cb61c549ff23a363f4d69d0ff0
child 198651 0f6e945dfe6c69fa11492bd1b242aa9bef73bc6e
push id27277
push userryanvm@gmail.com
push dateFri, 08 Aug 2014 20:25:17 +0000
treeherdermozilla-central@1d6500527f66 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1048785
milestone34.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 1048785 Part 2: Extend MozLoopAPI with channel, version and OS details. r=mikedeboer
browser/components/loop/MozLoopAPI.jsm
browser/components/loop/content/js/conversation.js
browser/components/loop/content/js/conversation.jsx
browser/components/loop/test/desktop-local/conversation_test.js
browser/components/loop/test/mochitest/browser.ini
browser/components/loop/test/mochitest/browser_mozLoop_appVersionInfo.js
--- a/browser/components/loop/MozLoopAPI.jsm
+++ b/browser/components/loop/MozLoopAPI.jsm
@@ -7,32 +7,38 @@
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource:///modules/loop/MozLoopService.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "hookWindowCloseForPanelClose",
                                         "resource://gre/modules/MozSocialAPI.jsm");
+XPCOMUtils.defineLazyGetter(this, "appInfo", function() {
+  return Cc["@mozilla.org/xre/app-info;1"]
+           .getService(Ci.nsIXULAppInfo)
+           .QueryInterface(Ci.nsIXULRuntime);
+});
 XPCOMUtils.defineLazyServiceGetter(this, "clipboardHelper",
                                          "@mozilla.org/widget/clipboardhelper;1",
                                          "nsIClipboardHelper");
 this.EXPORTED_SYMBOLS = ["injectLoopAPI"];
 
 /**
  * Inject the loop API into the given window.  The caller must be sure the
  * window is a loop content window (eg, a panel, chatwindow, or similar).
  *
  * See the documentation on the individual functions for details of the API.
  *
  * @param {nsIDOMWindow} targetWindow The content window to attach the API.
  */
 function injectLoopAPI(targetWindow) {
   let ringer;
   let ringerStopper;
+  let appVersionInfo;
 
   let api = {
     /**
      * Sets and gets the "do not disturb" mode activation flag.
      */
     doNotDisturb: {
       enumerable: true,
       get: function() {
@@ -234,17 +240,41 @@ function injectLoopAPI(targetWindow) {
      * @param {String} str The string to copy
      */
     copyString: {
       enumerable: true,
       writable: true,
       value: function(str) {
         clipboardHelper.copyString(str);
       }
-    }
+    },
+
+    /**
+     * Returns the app version information for use during feedback.
+     *
+     * @return {Object} An object containing:
+     *   - channel: The update channel the application is on
+     *   - version: The application version
+     *   - OS: The operating system the application is running on
+     */
+    appVersionInfo: {
+      enumerable: true,
+      get: function() {
+        if (!appVersionInfo) {
+          let defaults = Services.prefs.getDefaultBranch(null);
+
+          appVersionInfo = Cu.cloneInto({
+            channel: defaults.getCharPref("app.update.channel"),
+            version: appInfo.version,
+            OS: appInfo.OS
+          }, targetWindow);
+        }
+        return appVersionInfo;
+      }
+    },
   };
 
   let contentObj = Cu.createObjectIn(targetWindow);
   Object.defineProperties(contentObj, api);
   Object.seal(contentObj);
   Cu.makeObjectPropsNormal(contentObj);
 
   targetWindow.navigator.wrappedJSObject.__defineGetter__("mozLoop", function() {
--- a/browser/components/loop/content/js/conversation.js
+++ b/browser/components/loop/content/js/conversation.js
@@ -246,21 +246,23 @@ loop.conversation = (function(OT, mozL10
      * Call has ended, display a feedback form.
      */
     feedback: function() {
       document.title = mozL10n.get("call_has_ended");
 
       var feebackAPIBaseUrl = navigator.mozLoop.getLoopCharPref(
         "feedback.baseUrl");
 
+      var appVersionInfo = navigator.mozLoop.appVersionInfo;
+
       var feedbackClient = new loop.FeedbackAPIClient(feebackAPIBaseUrl, {
         product: navigator.mozLoop.getLoopCharPref("feedback.product"),
-        platform: navigator.platform
-        // XXX add "channel" and "version" options as per bug 1048785; these
-        //     could be provided by the mozLoop API.
+        platform: appVersionInfo.OS,
+        channel: appVersionInfo.channel,
+        version: appVersionInfo.version
       });
 
       this.loadReactComponent(sharedViews.FeedbackView({
         feedbackApiClient: feedbackClient
       }));
     }
   });
 
--- a/browser/components/loop/content/js/conversation.jsx
+++ b/browser/components/loop/content/js/conversation.jsx
@@ -246,21 +246,23 @@ loop.conversation = (function(OT, mozL10
      * Call has ended, display a feedback form.
      */
     feedback: function() {
       document.title = mozL10n.get("call_has_ended");
 
       var feebackAPIBaseUrl = navigator.mozLoop.getLoopCharPref(
         "feedback.baseUrl");
 
+      var appVersionInfo = navigator.mozLoop.appVersionInfo;
+
       var feedbackClient = new loop.FeedbackAPIClient(feebackAPIBaseUrl, {
         product: navigator.mozLoop.getLoopCharPref("feedback.product"),
-        platform: navigator.platform
-        // XXX add "channel" and "version" options as per bug 1048785; these
-        //     could be provided by the mozLoop API.
+        platform: appVersionInfo.OS,
+        channel: appVersionInfo.channel,
+        version: appVersionInfo.version
       });
 
       this.loadReactComponent(sharedViews.FeedbackView({
         feedbackApiClient: feedbackClient
       }));
     }
   });
 
--- a/browser/components/loop/test/desktop-local/conversation_test.js
+++ b/browser/components/loop/test/desktop-local/conversation_test.js
@@ -33,17 +33,24 @@ describe("loop.conversation", function()
       },
       get locale() {
         return "en-US";
       },
       setLoopCharPref: sandbox.stub(),
       getLoopCharPref: sandbox.stub(),
       startAlerting: function() {},
       stopAlerting: function() {},
-      ensureRegistered: function() {}
+      ensureRegistered: function() {},
+      get appVersionInfo() {
+        return {
+          version: "42",
+          channel: "test",
+          platform: "test"
+        };
+      }
     };
 
     // XXX These stubs should be hoisted in a common file
     // Bug 1040968
     document.mozL10n.initialize(navigator.mozLoop);
   });
 
   afterEach(function() {
--- a/browser/components/loop/test/mochitest/browser.ini
+++ b/browser/components/loop/test/mochitest/browser.ini
@@ -1,7 +1,8 @@
 [DEFAULT]
 support-files =
     head.js
 
+[browser_mozLoop_appVersionInfo.js]
 [browser_mozLoop_charPref.js]
 [browser_mozLoop_doNotDisturb.js]
 skip-if = buildapp == 'mulet'
new file mode 100644
--- /dev/null
+++ b/browser/components/loop/test/mochitest/browser_mozLoop_appVersionInfo.js
@@ -0,0 +1,33 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * This is an integration test from navigator.mozLoop through to the end
+ * effects - rather than just testing MozLoopAPI alone.
+ */
+
+add_task(loadLoopPanel);
+
+add_task(function* test_mozLoop_appVersionInfo() {
+  Assert.ok(gMozLoopAPI, "mozLoop should exist");
+
+  let appVersionInfo = gMozLoopAPI.appVersionInfo;
+
+  Assert.ok(appVersionInfo, "should have appVersionInfo");
+
+  Assert.equal(appVersionInfo.channel,
+               Services.prefs.getCharPref("app.update.channel"),
+               "appVersionInfo.channel should match the application channel");
+
+  var appInfo = Cc["@mozilla.org/xre/app-info;1"]
+                  .getService(Ci.nsIXULAppInfo)
+                  .QueryInterface(Ci.nsIXULRuntime);
+
+  Assert.equal(appVersionInfo.version,
+               appInfo.version,
+               "appVersionInfo.version should match the application version");
+
+  Assert.equal(appVersionInfo.OS,
+               appInfo.OS,
+               "appVersionInfo.os should match the running os");
+});