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 #12749 from etiennesegonzac/bug-910584-dialer-head…
Browse files Browse the repository at this point in the history
…set-and-speaker

Bug 910584 - Plugging headphones in during a call should turn off the speaker if it's on. r=Rik
  • Loading branch information
etiennesegonzac committed Oct 11, 2013
2 parents e378651 + b1af4a5 commit 1deb60f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/communications/dialer/js/calls_handler.js
Expand Up @@ -64,6 +64,15 @@ var CallsHandler = (function callsHandler() {
telephony.muted = false;
}

var acm = navigator.mozAudioChannelManager;
if (acm) {
acm.addEventListener('headphoneschange', function onheadphoneschange() {
if (acm.headphones) {
CallScreen.turnSpeakerOff();
}
});
}

postToMainWindow('ready');
}

Expand Down
35 changes: 35 additions & 0 deletions apps/communications/dialer/test/unit/calls_handler_test.js
Expand Up @@ -1027,4 +1027,39 @@ suite('calls handler', function() {
});
});
});

suite('> headphone support', function() {
var realACM;
var acmStub;

suiteSetup(function() {
acmStub = {
headphones: false,
addEventListener: function() {}
};

realACM = navigator.mozAudioChannelManager;
navigator.mozAudioChannelManager = acmStub;
});

suiteTeardown(function() {
navigator.mozAudioChannelManager = realACM;
});

suite('> pluging headphones in', function() {
var headphonesChange;

setup(function() {
acmStub.headphones = true;
headphonesChange = this.sinon.stub(acmStub, 'addEventListener');
CallsHandler.setup();
});

test('should turn the speakerOff', function() {
var turnOffSpy = this.sinon.spy(MockCallScreen, 'turnSpeakerOff');
headphonesChange.yield();
assert.isTrue(turnOffSpy.calledOnce);
});
});
});
});

0 comments on commit 1deb60f

Please sign in to comment.