Bug 1046039 Have a longer time window for users to view Terms of Service and Privacy Notice from the Loop panel. r=mhammond
authorMark Banner <standard8@mozilla.com>
Tue, 26 Aug 2014 09:12:00 +0100
changeset 201571 851898432b6fdf0facdee2a57cd13ea895b5be77
parent 201570 662567a5e50966aea00811d8ba46dc0318916736
child 201572 d3b46bc636ad02747c1f9a9689784bf225fbb5d9
push id27374
push userryanvm@gmail.com
push dateTue, 26 Aug 2014 18:16:27 +0000
treeherdermozilla-central@c850f3af9f2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhammond
bugs1046039
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 1046039 Have a longer time window for users to view Terms of Service and Privacy Notice from the Loop panel. r=mhammond
browser/components/loop/MozLoopService.jsm
browser/components/loop/content/js/panel.js
browser/components/loop/content/js/panel.jsx
browser/components/loop/test/desktop-local/panel_test.js
browser/components/loop/test/xpcshell/test_loopservice_notification.js
browser/components/loop/test/xpcshell/xpcshell.ini
--- a/browser/components/loop/MozLoopService.jsm
+++ b/browser/components/loop/MozLoopService.jsm
@@ -290,16 +290,21 @@ let MozLoopServiceInternal = {
    *
    * @param {String} version The version information from the server.
    */
   onHandleNotification: function(version) {
     if (this.doNotDisturb) {
       return;
     }
 
+    // We set this here as it is assumed that once the user receives an incoming
+    // call, they'll have had enough time to see the terms of service. See
+    // bug 1046039 for background.
+    Services.prefs.setCharPref("loop.seenToS", "seen");
+
     this.openChatWindow(null,
                         this.localizedStrings["incoming_call_title"].textContent,
                         "about:loopconversation#incoming/" + version);
   },
 
   /**
    * A getter to obtain and store the strings for loop. This is structured
    * for use by l10n.js.
--- a/browser/components/loop/content/js/panel.js
+++ b/browser/components/loop/content/js/panel.js
@@ -118,17 +118,16 @@ loop.panel = (function(_, mozL10n) {
             )
           ),
           "privacy_notice": React.renderComponentToStaticMarkup(
             React.DOM.a({href: privacy_notice_url, target: "_blank"}, 
               __("legal_text_privacy")
             )
           ),
         });
-        navigator.mozLoop.setLoopCharPref('seenToS', 'seen');
         return React.DOM.p({className: "terms-service", 
                   dangerouslySetInnerHTML: {__html: tosHTML}});
       } else {
         return React.DOM.div(null);
       }
     }
   });
 
--- a/browser/components/loop/content/js/panel.jsx
+++ b/browser/components/loop/content/js/panel.jsx
@@ -118,17 +118,16 @@ loop.panel = (function(_, mozL10n) {
             </a>
           ),
           "privacy_notice": React.renderComponentToStaticMarkup(
             <a href={privacy_notice_url} target="_blank">
               {__("legal_text_privacy")}
             </a>
           ),
         });
-        navigator.mozLoop.setLoopCharPref('seenToS', 'seen');
         return <p className="terms-service"
                   dangerouslySetInnerHTML={{__html: tosHTML}}></p>;
       } else {
         return <div />;
       }
     }
   });
 
--- a/browser/components/loop/test/desktop-local/panel_test.js
+++ b/browser/components/loop/test/desktop-local/panel_test.js
@@ -352,36 +352,16 @@ describe("loop.panel", function() {
         sinon.assert.calledWithExactly(notifier.errorL10n,
                                        "unable_retrieve_url");
       });
     });
   });
 
   describe('loop.panel.ToSView', function() {
 
-    it("should set the value of the loop.seenToS preference to 'seen'",
-      function() {
-        TestUtils.renderIntoDocument(loop.panel.ToSView());
-
-        sinon.assert.calledOnce(navigator.mozLoop.setLoopCharPref);
-        sinon.assert.calledWithExactly(navigator.mozLoop.setLoopCharPref,
-          'seenToS', 'seen');
-      });
-
-    it("should not set the value of loop.seenToS when it's already set",
-      function() {
-        navigator.mozLoop.getLoopCharPref = function() {
-          return "seen";
-        };
-
-        TestUtils.renderIntoDocument(loop.panel.ToSView());
-
-        sinon.assert.notCalled(navigator.mozLoop.setLoopCharPref);
-      });
-
     it("should render when the value of loop.seenToS is not set", function() {
       var view = TestUtils.renderIntoDocument(loop.panel.ToSView());
 
       TestUtils.findRenderedDOMComponentWithClass(view, "terms-service");
     });
 
     it("should not render when the value of loop.seenToS is set to 'seen'",
       function(done) {
new file mode 100644
--- /dev/null
+++ b/browser/components/loop/test/xpcshell/test_loopservice_notification.js
@@ -0,0 +1,49 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+XPCOMUtils.defineLazyModuleGetter(this, "Chat",
+                                  "resource:///modules/Chat.jsm");
+
+let openChatOrig = Chat.open;
+
+add_test(function test_openChatWindow_on_notification() {
+  Services.prefs.setCharPref("loop.seenToS", "unseen");
+
+  MozLoopService.register(mockPushHandler).then(() => {
+    let opened = false;
+    Chat.open = function() {
+      opened = true;
+    };
+
+    mockPushHandler.notify(1);
+
+    do_check_true(opened, "should open a chat window");
+
+    do_check_eq(Services.prefs.getCharPref("loop.seenToS"), "seen",
+                "should set the pref to 'seen'");
+
+    run_next_test();
+  });
+});
+
+function run_test()
+{
+  setupFakeLoopServer();
+
+  loopServer.registerPathHandler("/registration", (request, response) => {
+    response.setStatusLine(null, 200, "OK");
+    response.processAsync();
+    response.finish();
+  });
+
+  do_register_cleanup(function() {
+    // Revert original Chat.open implementation
+    Chat.open = openChatOrig;
+
+    // clear test pref
+    Services.prefs.clearUserPref("loop.seenToS");
+  });
+
+  run_next_test();
+}
--- a/browser/components/loop/test/xpcshell/xpcshell.ini
+++ b/browser/components/loop/test/xpcshell/xpcshell.ini
@@ -4,13 +4,14 @@ tail =
 firefox-appdir = browser
 
 [test_looppush_initialize.js]
 [test_loopservice_dnd.js]
 [test_loopservice_expiry.js]
 [test_loopservice_loop_prefs.js]
 [test_loopservice_initialize.js]
 [test_loopservice_locales.js]
+[test_loopservice_notification.js]
 [test_loopservice_registration.js]
 [test_loopservice_token_invalid.js]
 [test_loopservice_token_save.js]
 [test_loopservice_token_send.js]
 [test_loopservice_token_validation.js]