From b1af4a5226067ec72bd34c86535366a460da9077 Mon Sep 17 00:00:00 2001 From: Etienne Segonzac Date: Wed, 9 Oct 2013 15:26:32 +0200 Subject: [PATCH] Bug 910584 - Plugging headphones in during a call should turn off the speaker if it's on. r=Rik --- .../communications/dialer/js/calls_handler.js | 9 +++++ .../dialer/test/unit/calls_handler_test.js | 35 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/apps/communications/dialer/js/calls_handler.js b/apps/communications/dialer/js/calls_handler.js index 0f2b434c22d2..09494f334f5a 100644 --- a/apps/communications/dialer/js/calls_handler.js +++ b/apps/communications/dialer/js/calls_handler.js @@ -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'); } diff --git a/apps/communications/dialer/test/unit/calls_handler_test.js b/apps/communications/dialer/test/unit/calls_handler_test.js index ddf8a6b0a14b..74c7d4878b30 100644 --- a/apps/communications/dialer/test/unit/calls_handler_test.js +++ b/apps/communications/dialer/test/unit/calls_handler_test.js @@ -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); + }); + }); + }); });