Bug 1081959 - "Something went wrong" isn't displayed when the call fails in the connection phase. r=dmose, a=lmandel
authorMark Banner <standard8@mozilla.com>
Mon, 20 Oct 2014 11:10:23 -0700
changeset 225796 8cf65ccdce3d
parent 225795 48e3c2f927d5
child 225797 033942f8f817
push id4021
push userryanvm@gmail.com
push date2014-10-24 13:05 +0000
treeherdermozilla-beta@b185e7a13e18 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdmose, lmandel
bugs1081959
milestone34.0
Bug 1081959 - "Something went wrong" isn't displayed when the call fails in the connection phase. r=dmose, a=lmandel
browser/components/loop/content/js/conversation.js
browser/components/loop/content/js/conversation.jsx
browser/components/loop/standalone/content/js/webapp.js
browser/components/loop/standalone/content/js/webapp.jsx
browser/components/loop/test/desktop-local/conversation_test.js
browser/components/loop/test/standalone/webapp_test.js
--- a/browser/components/loop/content/js/conversation.js
+++ b/browser/components/loop/content/js/conversation.js
@@ -394,19 +394,22 @@ loop.conversation = (function(mozL10n) {
         return;
 
       if (progressData.reason === "cancel" ||
           progressData.reason === "closed") {
         this._abortIncomingCall();
         return;
       }
 
-      if (progressData.reason === "timeout" &&
-          (previousState === "init" || previousState === "alerting")) {
-        this._abortIncomingCall();
+      if (progressData.reason === "timeout") {
+        if (previousState === "init" || previousState === "alerting") {
+          this._abortIncomingCall();
+        } else {
+          this.setState({callFailed: true, callStatus: "end"});
+        }
       }
     },
 
     /**
      * Silently aborts an incoming call - stops the alerting, and
      * closes the websocket.
      */
     _abortIncomingCall: function() {
--- a/browser/components/loop/content/js/conversation.jsx
+++ b/browser/components/loop/content/js/conversation.jsx
@@ -394,19 +394,22 @@ loop.conversation = (function(mozL10n) {
         return;
 
       if (progressData.reason === "cancel" ||
           progressData.reason === "closed") {
         this._abortIncomingCall();
         return;
       }
 
-      if (progressData.reason === "timeout" &&
-          (previousState === "init" || previousState === "alerting")) {
-        this._abortIncomingCall();
+      if (progressData.reason === "timeout") {
+        if (previousState === "init" || previousState === "alerting") {
+          this._abortIncomingCall();
+        } else {
+          this.setState({callFailed: true, callStatus: "end"});
+        }
       }
     },
 
     /**
      * Silently aborts an incoming call - stops the alerting, and
      * closes the websocket.
      */
     _abortIncomingCall: function() {
--- a/browser/components/loop/standalone/content/js/webapp.js
+++ b/browser/components/loop/standalone/content/js/webapp.js
@@ -809,17 +809,19 @@ loop.webapp = (function($, _, OT, mozL10
       this.props.notifications.errorL10n("call_timeout_notification_text");
       this.setState({callStatus: "failure"});
     },
 
     /**
      * Handles ending a call by resetting the view to the start state.
      */
     _endCall: function() {
-      this.setState({callStatus: "end"});
+      if (this.state.callStatus !== "failure") {
+        this.setState({callStatus: "end"});
+      }
     },
   });
 
   /**
    * Webapp Root View. This is the main, single, view that controls the display
    * of the webapp page.
    */
   var WebappRootView = React.createClass({displayName: 'WebappRootView',
--- a/browser/components/loop/standalone/content/js/webapp.jsx
+++ b/browser/components/loop/standalone/content/js/webapp.jsx
@@ -809,17 +809,19 @@ loop.webapp = (function($, _, OT, mozL10
       this.props.notifications.errorL10n("call_timeout_notification_text");
       this.setState({callStatus: "failure"});
     },
 
     /**
      * Handles ending a call by resetting the view to the start state.
      */
     _endCall: function() {
-      this.setState({callStatus: "end"});
+      if (this.state.callStatus !== "failure") {
+        this.setState({callStatus: "end"});
+      }
     },
   });
 
   /**
    * Webapp Root View. This is the main, single, view that controls the display
    * of the webapp page.
    */
   var WebappRootView = React.createClass({
--- a/browser/components/loop/test/desktop-local/conversation_test.js
+++ b/browser/components/loop/test/desktop-local/conversation_test.js
@@ -34,17 +34,17 @@ describe("loop.conversation", function()
       doNotDisturb: true,
       getStrings: function() {
         return JSON.stringify({textContent: "fakeText"});
       },
       get locale() {
         return "en-US";
       },
       setLoopCharPref: sinon.stub(),
-      getLoopCharPref: sinon.stub().returns(null),
+      getLoopCharPref: sinon.stub().returns("http://fakeurl"),
       getLoopBoolPref: sinon.stub(),
       getCallData: sinon.stub(),
       releaseCallData: sinon.stub(),
       startAlerting: sinon.stub(),
       stopAlerting: sinon.stub(),
       ensureRegistered: sinon.stub(),
       get appVersionInfo() {
         return {
@@ -351,16 +351,18 @@ describe("loop.conversation", function()
               done();
             });
           });
         });
 
         describe("WebSocket Events", function() {
           describe("Call cancelled or timed out before acceptance", function() {
             beforeEach(function() {
+              // Mounting the test component automatically calls the required
+              // setup functions
               icView = mountTestComponent();
               promise = new Promise(function(resolve, reject) {
                 resolve();
               });
 
               sandbox.stub(loop.CallConnectionWebSocket.prototype, "promiseConnect").returns(promise);
               sandbox.stub(loop.CallConnectionWebSocket.prototype, "close");
               sandbox.stub(window, "close");
@@ -480,16 +482,32 @@ describe("loop.conversation", function()
 
                   sandbox.clock.tick(1);
 
                   sinon.assert.calledOnce(window.close);
                   done();
                 });
               });
             });
+
+            describe("progress - terminated - timeout (previousState not init" +
+                     " nor alerting)",
+              function() {
+                it("should set the state to end", function(done) {
+                  promise.then(function() {
+                    icView._websocket.trigger("progress", {
+                      state: "terminated",
+                      reason: "timeout"
+                    }, "connecting");
+
+                    expect(icView.state.callStatus).eql("end");
+                    done();
+                  });
+                });
+              });
           });
         });
       });
 
       describe("#accept", function() {
         beforeEach(function() {
           icView = mountTestComponent();
           conversation.setIncomingSessionData({
--- a/browser/components/loop/test/standalone/webapp_test.js
+++ b/browser/components/loop/test/standalone/webapp_test.js
@@ -303,22 +303,34 @@ describe("loop.webapp", function() {
             ocView.startCall();
 
             TestUtils.findRenderedComponentWithType(ocView,
               loop.webapp.PendingConversationView);
           });
       });
 
       describe("session:ended", function() {
-        it("should set display the StartConversationView", function() {
+        it("should display the StartConversationView", function() {
           conversation.trigger("session:ended");
 
           TestUtils.findRenderedComponentWithType(ocView,
             loop.webapp.EndedConversationView);
         });
+
+        it("should display the FailedConversationView if callStatus is failure",
+          function() {
+            ocView.setState({
+              callStatus: "failure"
+            });
+            conversation.trigger("session:ended");
+
+            var failedView = TestUtils.findRenderedComponentWithType(ocView,
+                loop.webapp.FailedConversationView);
+            expect(failedView).to.not.equal(null);
+          });
       });
 
       describe("session:peer-hungup", function() {
         it("should set display the StartConversationView", function() {
           conversation.trigger("session:peer-hungup");
 
           TestUtils.findRenderedComponentWithType(ocView,
             loop.webapp.EndedConversationView);