Bug 1250495 - Improved privacy by opening Hello FTU Url when there is no context url r=standard8
authorDavid Critchley <david@priologic.com>
Wed, 24 Feb 2016 19:42:01 +0000
changeset 321666 8dac48a684eebfad868cd6df3ef4a852e7f48471
parent 321665 057c0e7cf189ada0745d58b3d83b326bf1cb3ffb
child 321667 6d20cb4a0dd85df647eb0e27c6c099d7439fd217
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs1250495
milestone47.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 1250495 - Improved privacy by opening Hello FTU Url when there is no context url r=standard8
browser/extensions/loop/chrome/content/modules/MozLoopAPI.jsm
browser/extensions/loop/chrome/content/panels/js/panel.js
browser/extensions/loop/chrome/content/panels/test/panel_test.js
browser/extensions/loop/chrome/test/xpcshell/test_loopapi_ftu_url.js
browser/extensions/loop/chrome/test/xpcshell/xpcshell.ini
--- a/browser/extensions/loop/chrome/content/modules/MozLoopAPI.jsm
+++ b/browser/extensions/loop/chrome/content/modules/MozLoopAPI.jsm
@@ -817,16 +817,32 @@ const kMessageHandlers = {
    *                           the senders' channel.
    */
   OpenGettingStartedTour: function(message, reply) {
     MozLoopService.openGettingStartedTour();
     reply();
   },
 
   /**
+   * Retrieves the Getting Started tour url.
+   *
+   * @param {Object}   message Message meant for the handler function, containing
+   *                           the following parameters in its `data` property:
+   *                           [aSrc, aAdditionalParams]
+   * @param {Function} reply   Callback function, invoked with the result of this
+   *                           message handler. The result will be sent back to
+   *                           the senders' channel.
+   */
+  GettingStartedURL: function(message, reply) {
+    let aSrc = message.data[0] || null;
+    let aAdditionalParams = message.data[1] || {};
+    reply(MozLoopService.getTourURL(aSrc, aAdditionalParams).href);
+  },
+
+  /**
    * Open the FxA profile/ settings page.
    *
    * @param {Object}   message Message meant for the handler function, containing
    *                           the following parameters in its `data` property:
    *                           [ ]
    * @param {Function} reply   Callback function, invoked with the result of this
    *                           message handler. The result will be sent back to
    *                           the senders' channel.
--- a/browser/extensions/loop/chrome/content/panels/js/panel.js
+++ b/browser/extensions/loop/chrome/content/panels/js/panel.js
@@ -462,19 +462,25 @@ loop.panel = function (_, mozL10n) {
     handleClickEntry: function (event) {
       event.preventDefault();
 
       this.props.dispatcher.dispatch(new sharedActions.OpenRoom({
         roomToken: this.props.room.roomToken
       }));
 
       // Open url if needed.
-      loop.request("getSelectedTabMetadata").then(function (metadata) {
+      loop.requestMulti(
+        ["getSelectedTabMetadata"],
+        ["GettingStartedURL", null, {}]
+      ).then(function(results) {
         var contextURL = this.props.room.decryptedContext.urls && this.props.room.decryptedContext.urls[0].location;
-        if (contextURL && metadata.url !== contextURL) {
+
+        contextURL = contextURL || (results[1] + "?noopenpanel=1");
+
+        if (results[0].url !== contextURL) {
           loop.request("OpenURL", contextURL);
         }
         this.closeWindow();
       }.bind(this));
     },
 
     handleClick: function (e) {
       e.preventDefault();
--- a/browser/extensions/loop/chrome/content/panels/test/panel_test.js
+++ b/browser/extensions/loop/chrome/content/panels/test/panel_test.js
@@ -71,16 +71,17 @@ describe("loop.panel", function() {
       Confirm: sinon.stub(),
       GetHasEncryptionKey: function() { return true; },
       HangupAllChatWindows: function() {},
       IsMultiProcessActive: sinon.stub(),
       LoginToFxA: sinon.stub(),
       LogoutFromFxA: sinon.stub(),
       NotifyUITour: sinon.stub(),
       OpenURL: sinon.stub(),
+      GettingStartedURL: sinon.stub().returns("http://fakeFTUUrl.com"),
       GetSelectedTabMetadata: sinon.stub().returns({}),
       GetUserProfile: function() { return null; }
     });
 
     loop.storedRequests = {
       GetFxAEnabled: true,
       GetHasEncryptionKey: true,
       GetUserProfile: null,
@@ -824,16 +825,50 @@ describe("loop.panel", function() {
         });
 
         it("should open a new tab with the room context if it is not the same as the currently open tab", function() {
           TestUtils.Simulate.click(roomEntry.refs.roomEntry.getDOMNode());
           sinon.assert.calledOnce(openURLStub);
           sinon.assert.calledWithExactly(openURLStub, "http://testurl.com");
         });
 
+        it("should open a new tab with the FTU Getting Started URL if the room context is blank", function() {
+          var roomDataNoURL = {
+            roomToken: "QzBbvGmIZWU",
+            roomUrl: "http://sample/QzBbvGmIZWU",
+            decryptedContext: {
+              roomName: roomName,
+              urls: [{
+                location: ""
+              }]
+            },
+            maxSize: 2,
+            participants: [{
+              displayName: "Alexis",
+              account: "alexis@example.com",
+              roomConnectionId: "2a1787a6-4a73-43b5-ae3e-906ec1e763cb"
+            }, {
+              displayName: "Adam",
+              roomConnectionId: "781f012b-f1ea-4ce1-9105-7cfc36fb4ec7"
+            }],
+            ctime: 1405517418
+          };
+          roomEntry = mountRoomEntry({
+            deleteRoom: sandbox.stub(),
+            isOpenedRoom: false,
+            room: new loop.store.Room(roomDataNoURL)
+          });
+          var ftuURL = requestStubs.GettingStartedURL() + "?noopenpanel=1";
+
+          TestUtils.Simulate.click(roomEntry.refs.roomEntry.getDOMNode());
+
+          sinon.assert.calledOnce(openURLStub);
+          sinon.assert.calledWithExactly(openURLStub, ftuURL);
+        });
+
         it("should not open a new tab if the context is the same as the currently open tab", function() {
           LoopMochaUtils.stubLoopRequest({
             GetSelectedTabMetadata: function() {
               return {
                 url: "http://testurl.com",
                 description: "fakeSite"
               };
             }
new file mode 100644
--- /dev/null
+++ b/browser/extensions/loop/chrome/test/xpcshell/test_loopapi_ftu_url.js
@@ -0,0 +1,14 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+const { LoopAPI } = Cu.import("chrome://loop/content/modules/MozLoopAPI.jsm", {});
+var [, gHandlers] = LoopAPI.inspect();
+
+add_task(function* test_mozLoop_gettingStartedURL() {
+  let expectedURL = MozLoopService.getTourURL().href;
+  // Test gettingStartedURL
+  gHandlers.GettingStartedURL({ data: [] }, result => {
+    Assert.equal(result, expectedURL, "should get mozLoopService GettingStartedURL value correctly");
+  });
+});
--- a/browser/extensions/loop/chrome/test/xpcshell/xpcshell.ini
+++ b/browser/extensions/loop/chrome/test/xpcshell/xpcshell.ini
@@ -1,15 +1,16 @@
 [DEFAULT]
 head = head.js
 tail =
 firefox-appdir = browser
 skip-if = toolkit == 'gonk'
 
 [test_loopapi_doNotDisturb.js]
+[test_loopapi_ftu_url.js]
 [test_loopapi_internal.js]
 [test_loopapi_prefs.js]
 [test_looppush_initialize.js]
 [test_looprooms.js]
 [test_looprooms_encryption_in_fxa.js]
 [test_looprooms_first_notification.js]
 [test_looprooms_getall.js]
 [test_looprooms_upgrade_to_encryption.js]