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 #31018 from evanxd/bug-1183870
Browse files Browse the repository at this point in the history
Bug 1183870 - Set audio channel as none when audio channel is inactive r=dkuo
  • Loading branch information
evanxd committed Jul 21, 2015
2 parents b4ea357 + be3ce1d commit b79d2a4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion apps/system/js/audio_channel_service.js
Expand Up @@ -122,10 +122,11 @@
if (!isBackground) {
this.publish('visibleaudiochannelchanged', channel);
}
this.publish('audiochannelchangedasactive', channel);
this.publish('audiochannelchanged', channel);
} else {
this._resetAudioChannel(audioChannel);
this._resumeAudioChannels();
this.publish('audiochannelchanged', { channel: 'none' });
}
},

Expand Down
8 changes: 4 additions & 4 deletions apps/system/js/sound_manager.js
Expand Up @@ -83,7 +83,7 @@

/**
* Store the current active channel;
* change with 'audiochannelchangedasactive' event
* change with 'audiochannelchanged' event
* All candidates and definitions can be found at AudioChannels link.
*
* @see {@link https://wiki.mozilla.org/WebAPI/AudioChannels|AudioChannels}
Expand Down Expand Up @@ -265,7 +265,7 @@
window.addEventListener('holdhome', this);
window.addEventListener('homescreenopening', this);
window.addEventListener('homescreenopened', this);
window.addEventListener('audiochannelchangedasactive', this);
window.addEventListener('audiochannelchanged', this);

LazyLoader.load(['js/headphone_icon.js',
'js/mute_icon.js',
Expand Down Expand Up @@ -326,7 +326,7 @@
window.removeEventListener('holdhome', this);
window.removeEventListener('homescreenopening', this);
window.removeEventListener('homescreenopened', this);
window.removeEventListener('audiochannelchangedasactive', this);
window.removeEventListener('audiochannelchanged', this);

Service.unregisterState('isHeadsetConnected', this);
Service.unregisterState('currentChannel', this);
Expand All @@ -353,7 +353,7 @@
case 'unmute':
this.setMute(false);
break;
case 'audiochannelchangedasactive':
case 'audiochannelchanged':
this.setAudioChannel(e.detail.channel);
this.ceAccumulator();
break;
Expand Down
15 changes: 13 additions & 2 deletions apps/system/test/unit/audio_channel_service_test.js
Expand Up @@ -160,6 +160,17 @@ suite('system/AudioChannelService', function() {
.withArgs(audioChannel).calledOnce);
});

test('Handle inactive audio channel ', function() {
this.sinon.stub(audioChannel, 'isActive', function() {
return false;
});
this.sinon.spy(subject, 'publish');
subject._manageAudioChannels(audioChannel);
var channel = { channel: 'none' };
assert.ok(subject.publish
.withArgs('audiochannelchanged', channel).calledOnce);
});

suite('Foreground/background audio channel', function() {
setup(function() {
this.sinon.stub(audioChannel, 'isActive', function() {
Expand All @@ -177,7 +188,7 @@ suite('system/AudioChannelService', function() {
assert.ok(subject.publish
.withArgs('visibleaudiochannelchanged', channel).calledOnce);
assert.ok(subject.publish
.withArgs('audiochannelchangedasactive', channel).calledOnce);
.withArgs('audiochannelchanged', channel).calledOnce);
});

test('In background', function() {
Expand All @@ -189,7 +200,7 @@ suite('system/AudioChannelService', function() {
assert.ok(subject.publish
.withArgs('visibleaudiochannelchanged', channel).notCalled);
assert.ok(subject.publish
.withArgs('audiochannelchangedasactive', channel).calledOnce);
.withArgs('audiochannelchanged', channel).calledOnce);
});
});

Expand Down
4 changes: 2 additions & 2 deletions apps/system/test/unit/sound_manager_test.js
Expand Up @@ -143,7 +143,7 @@ suite('system/sound manager', function() {
});

test('audio channel changed', function() {
window.dispatchEvent(new CustomEvent('audiochannelchangedasactive', {
window.dispatchEvent(new CustomEvent('audiochannelchanged', {
detail: {
channel: 'alarm'
}
Expand Down Expand Up @@ -444,7 +444,7 @@ suite('system/sound manager', function() {
soundManager.currentVolume.content = 15;
sendChromeEvent({'type': 'headphones-status-changed',
'state': 'on' });
window.dispatchEvent(new CustomEvent('audiochannelchangedasactive',{
window.dispatchEvent(new CustomEvent('audiochannelchanged',{
detail: {
channel: 'content'
}
Expand Down

0 comments on commit b79d2a4

Please sign in to comment.