Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #18727 from bentian/bug-997578-14
Browse files Browse the repository at this point in the history
Bug 997578 - [1.4] Answer incoming call after hanging up active call, r=etienne, a=1.4+
  • Loading branch information
Ben Tian committed Apr 29, 2014
2 parents 01b7794 + 8005952 commit cf590ec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
22 changes: 20 additions & 2 deletions apps/communications/dialer/js/calls_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,26 @@ var CallsHandler = (function callsHandler() {
var callToEnd = telephony.active || // connected, incoming
handledCalls[handledCalls.length - 2].call; // held, incoming

if (callToEnd) {
callToEnd.hangUp(); // the incoming call is answered by gecko
var callToAnswer;
handledCalls.some(function(handledCall) {
if (handledCall.call !== callToEnd) {
callToAnswer = handledCall.call;
return true;
}
});

if (callToEnd && callToAnswer) {
callToEnd.addEventListener('disconnected', function ondisconnected() {
callToEnd.removeEventListener('disconnected', ondisconnected);
// Answer the incoming call after hanging up the active call
callToAnswer.answer();
});

callToEnd.hangUp(); // hangup the active call
} else if (callToEnd) {
callToEnd.hangUp(); // hangup the active call
} else if (callToAnswer) {
callToAnswer.answer(); // answer the incoming call
}
}

Expand Down
25 changes: 20 additions & 5 deletions apps/communications/dialer/test/unit/calls_handler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,24 @@ suite('calls handler', function() {
var secondConfCall = new MockCall('12334', 'held');
extraCall = new MockCall('424242', 'incoming');

/**
* Don't add all 3 calls at once since |CallsHandler.addCall|
* would hangup the 3rd call
*/
telephonyAddCall.call(this, firstConfCall, {trigger: true});
telephonyAddCall.call(this, secondConfCall, {trigger: true});
telephonyAddCall.call(this, extraCall, {trigger: true});

MockNavigatorMozTelephony.calls = [extraCall];
// Merge calls
MockNavigatorMozTelephony.conferenceGroup.calls = [firstConfCall,
secondConfCall];
firstConfCall.group = MockNavigatorMozTelephony.conferenceGroup;
secondConfCall.group = MockNavigatorMozTelephony.conferenceGroup;

MockNavigatorMozTelephony.calls = [];
MockNavigatorMozTelephony.mTriggerGroupCallsChanged();

// Add extra call
telephonyAddCall.call(this, extraCall, {trigger: true});
MockNavigatorMozTelephony.calls = [extraCall];
MockNavigatorMozTelephony.mTriggerCallsChanged();
});

Expand Down Expand Up @@ -789,11 +796,15 @@ suite('calls handler', function() {
telephonyAddCall.call(this, incomingCall, {trigger: true});
});

test('should hang up the active call', function() {
test('should hang up the active call and answer the incoming call',
function() {
var hangUpSpy =
this.sinon.spy(MockNavigatorMozTelephony.active, 'hangUp');
var answerSpy = this.sinon.spy(incomingCall, 'answer');

CallsHandler.endAndAnswer();
assert.isTrue(hangUpSpy.calledOnce);
assert.isTrue(answerSpy.calledOnce);
});

test('should hide the call waiting UI', function() {
Expand All @@ -816,10 +827,14 @@ suite('calls handler', function() {
telephonyAddCall.call(this, incomingCall, {trigger: true});
});

test('should hang up the held call', function() {
test('should hang up the held call and answer the incoming call',
function() {
var hangUpSpy = this.sinon.spy(heldCall, 'hangUp');
var answerSpy = this.sinon.spy(incomingCall, 'answer');

CallsHandler.endAndAnswer();
assert.isTrue(hangUpSpy.calledOnce);
assert.isTrue(answerSpy.calledOnce);
});

test('should hide the call waiting UI', function() {
Expand Down
4 changes: 3 additions & 1 deletion apps/communications/dialer/test/unit/mock_call.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function MockCall(aNumber, aState, aServiceId) {
this.state = aState;

this.answer = function() {};
this.hangUp = function() {};
this.hangUp = function() {
this._disconnect();
};
this.hold = function() {};
this.resume = function() {};

Expand Down

0 comments on commit cf590ec

Please sign in to comment.