Bug 1045569 - Revoke the correct call url in loop desktop client, r=rgauthier@mozilla.com

This commit is contained in:
Andrei Oprea
2014-08-21 11:14:04 -07:00
parent faf1fc00f5
commit 04110c60b8
8 changed files with 25 additions and 23 deletions

View File

@@ -263,7 +263,7 @@ loop.conversation = (function(OT, mozL10n) {
*/
declineAndBlock: function() {
navigator.mozLoop.stopAlerting();
var token = navigator.mozLoop.getLoopCharPref("loopToken");
var token = this._conversation.get("callToken");
this._client.deleteCallUrl(token, function(error) {
// XXX The conversation window will be closed when this cb is triggered
// figure out if there is a better way to report the error to the user

View File

@@ -263,7 +263,7 @@ loop.conversation = (function(OT, mozL10n) {
*/
declineAndBlock: function() {
navigator.mozLoop.stopAlerting();
var token = navigator.mozLoop.getLoopCharPref("loopToken");
var token = this._conversation.get("callToken");
this._client.deleteCallUrl(token, function(error) {
// XXX The conversation window will be closed when this cb is triggered
// figure out if there is a better way to report the error to the user

View File

@@ -170,10 +170,6 @@ loop.panel = (function(_, mozL10n) {
* Returns a random 5 character string used to identify
* the conversation.
* XXX this will go away once the backend changes
* @note:
* - When we get back a callUrl we use setLoopCharPref to store the token
* (the last fragment of the URL) so that it can be used to ignore&block
* the call. The preference is used by the conversation router.
*/
conversationIdentifier: function() {
return Math.random().toString(36).substring(5);
@@ -199,7 +195,6 @@ loop.panel = (function(_, mozL10n) {
var token = callUrlData.callToken ||
callUrl.pathname.split('/').pop();
navigator.mozLoop.setLoopCharPref('loopToken', token);
this.setState({pending: false, copied: false, callUrl: callUrl.href});
} catch(e) {
console.log(e);

View File

@@ -170,10 +170,6 @@ loop.panel = (function(_, mozL10n) {
* Returns a random 5 character string used to identify
* the conversation.
* XXX this will go away once the backend changes
* @note:
* - When we get back a callUrl we use setLoopCharPref to store the token
* (the last fragment of the URL) so that it can be used to ignore&block
* the call. The preference is used by the conversation router.
*/
conversationIdentifier: function() {
return Math.random().toString(36).substring(5);
@@ -199,7 +195,6 @@ loop.panel = (function(_, mozL10n) {
var token = callUrlData.callToken ||
callUrl.pathname.split('/').pop();
navigator.mozLoop.setLoopCharPref('loopToken', token);
this.setState({pending: false, copied: false, callUrl: callUrl.href});
} catch(e) {
console.log(e);

View File

@@ -32,8 +32,10 @@ loop.shared.models = (function() {
// requires.
callType: undefined, // The type of incoming call selected by
// other peer ("audio" or "audio-video")
selectedCallType: undefined // The selected type for the call that was
selectedCallType: undefined, // The selected type for the call that was
// initiated ("audio" or "audio-video")
callToken: undefined // Incoming call token.
// Used for blocking a call url
},
/**
@@ -168,7 +170,8 @@ loop.shared.models = (function() {
callId: sessionData.callId,
progressURL: sessionData.progressURL,
websocketToken: sessionData.websocketToken.toString(16),
callType: sessionData.callType || "audio-video"
callType: sessionData.callType || "audio-video",
callToken: sessionData.callToken
});
},

View File

@@ -120,6 +120,7 @@ describe("loop.conversation", function() {
pendingCallTimeout: 1000,
});
sandbox.stub(client, "requestCallsInfo");
sandbox.spy(conversation, "setIncomingSessionData");
sandbox.stub(conversation, "setOutgoingSessionData");
});
@@ -201,7 +202,6 @@ describe("loop.conversation", function() {
};
sandbox.stub(router, "_setupWebSocketAndCallView");
sandbox.stub(conversation, "setIncomingSessionData");
client.requestCallsInfo.callsArgWith(1, null, [fakeSessionData]);
});
@@ -436,10 +436,23 @@ describe("loop.conversation", function() {
});
it("should call delete call", function() {
var deleteCallUrl = sandbox.stub(loop.Client.prototype, "deleteCallUrl");
sandbox.stub(conversation, "get").withArgs("callToken")
.returns("fakeToken");
var deleteCallUrl = sandbox.stub(loop.Client.prototype,
"deleteCallUrl");
router.declineAndBlock();
sinon.assert.calledOnce(deleteCallUrl);
sinon.assert.calledWithExactly(deleteCallUrl, "fakeToken",
sinon.match.func);
});
it("should get callToken from conversation model", function() {
sandbox.stub(conversation, "get");
router.declineAndBlock();
sinon.assert.calledOnce(conversation.get);
sinon.assert.calledWithExactly(conversation.get, "callToken");
});
it("should trigger error handling in case of error", function() {

View File

@@ -352,12 +352,6 @@ describe("loop.panel", function() {
sinon.assert.calledWithExactly(notifier.errorL10n,
"unable_retrieve_url");
});
it("should set 'loopToken' with the callUrl token", function() {
sinon.assert.calledOnce(navigator.mozLoop.setLoopCharPref);
sinon.assert.calledWithExactly(navigator.mozLoop.setLoopCharPref,
"loopToken", "fakeToken");
});
});
});

View File

@@ -26,7 +26,8 @@ describe("loop.shared.models", function() {
sessionToken: "sessionToken",
apiKey: "apiKey",
callType: "callType",
websocketToken: 123
websocketToken: 123,
callToken: "callToken"
};
fakeSession = _.extend({
connect: function () {},
@@ -159,6 +160,7 @@ describe("loop.shared.models", function() {
expect(conversation.get("sessionToken")).eql("sessionToken");
expect(conversation.get("apiKey")).eql("apiKey");
expect(conversation.get("callType")).eql("callType");
expect(conversation.get("callToken")).eql("callToken");
});
});