This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1227824 - Normal audio channels compete with all kinds of audio c…
…hannels r=lchang
- Loading branch information
Showing
6 changed files
with
364 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Audio Channel Test App</title> | ||
<style> | ||
html, body { | ||
width: 100%; | ||
height: 100%; | ||
overflow: hidden; | ||
} | ||
</style> | ||
<script defer src="/js/index.js"></script> | ||
</head> | ||
<body> | ||
<div id="normal"> | ||
<span>Normal</span> | ||
<button class="play">Play</button> | ||
<button class="pause">Pause</button> | ||
<div/> | ||
<div id="content"> | ||
<span>Content</span> | ||
<button class="play">Play</button> | ||
<button class="pause">Pause</button> | ||
<div/> | ||
<div id="alarm"> | ||
<span>Alarm</span> | ||
<button class="play">Play</button> | ||
<button class="pause">Pause</button> | ||
<div/> | ||
<div id="system"> | ||
<span>System</span> | ||
<button class="play">Play</button> | ||
<button class="pause">Pause</button> | ||
<div/> | ||
<div id="ringer"> | ||
<span>Ringer</span> | ||
<button class="play">Play</button> | ||
<button class="pause">Pause</button> | ||
<div/> | ||
<div id="telephony"> | ||
<span>Telephony</span> | ||
<button class="play">Play</button> | ||
<button class="pause">Pause</button> | ||
<div/> | ||
<div id="notification"> | ||
<span>Notification</span> | ||
<button class="play">Play</button> | ||
<button class="pause">Pause</button> | ||
<div/> | ||
<div id="publicnotification"> | ||
<span>Public Notification</span> | ||
<button class="play">Play</button> | ||
<button class="pause">Pause</button> | ||
<div/> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
(function() { | ||
['normal', 'content', 'alarm', 'system', 'ringer', | ||
'telephony', 'notification', 'publicnotification'].forEach(function(type){ | ||
var play = document.querySelector('#' + type + ' .play'); | ||
var pause = document.querySelector('#' + type + ' .pause'); | ||
var audio = new Audio(); | ||
|
||
audio.src = 'audio/b2g.ogg'; | ||
audio.loop = true; | ||
audio.mozAudioChannelType = type; | ||
|
||
play.addEventListener('click', function() { | ||
audio.play(); | ||
}); | ||
|
||
pause.addEventListener('click', function() { | ||
audio.pause(); | ||
}); | ||
}); | ||
}()); |
19 changes: 19 additions & 0 deletions
19
apps/system/test/apps/audio_channel_test_app/manifest.webapp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "Audio Channel Test App", | ||
"type": "certified", | ||
"description": "Audio Channel Test App", | ||
"launch_path": "/index.html", | ||
"developer": { | ||
"name": "The Gaia Team", | ||
"url": "https://github.com/mozilla-b2g/gaia" | ||
}, | ||
"permissions": { | ||
"audio-channel-content": {}, | ||
"audio-channel-alarm": {}, | ||
"audio-channel-system": {}, | ||
"audio-channel-ringer": {}, | ||
"audio-channel-telephony": {}, | ||
"audio-channel-notification": {}, | ||
"audio-channel-publicnotification": {} | ||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
apps/system/test/marionette/audio_channel_competing_test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* jshint node: true*/ | ||
/* global marionette, setup, suite, test*/ | ||
'use strict'; | ||
|
||
var System = require('./lib/system'); | ||
var assert = require('assert'); | ||
var AudioChannelTestApp = require('./lib/audio_channel_test_app.js'); | ||
|
||
marionette('Audio channel competing', function() { | ||
var client = marionette.client({ | ||
profile: { | ||
apps: { | ||
'audiochanneltest1.gaiamobile.org': __dirname + | ||
'/../apps/audio_channel_test_app', | ||
'audiochanneltest2.gaiamobile.org': __dirname + | ||
'/../apps/audio_channel_test_app' | ||
} | ||
} | ||
}); | ||
|
||
var sys, audioChannelTestApp1, audioChannelTestApp2; | ||
|
||
suite('Normal audio channel competes with audio channels', function() { | ||
setup(function() { | ||
client.setScriptTimeout(20000); | ||
sys = new System(client); | ||
audioChannelTestApp1 = new AudioChannelTestApp( | ||
client, 'app://audiochanneltest1.gaiamobile.org'); | ||
audioChannelTestApp2 = new AudioChannelTestApp( | ||
client, 'app://audiochanneltest2.gaiamobile.org'); | ||
}); | ||
|
||
test('Normal channel competes with normal channel', function() { | ||
assertPolicy1('normal', 'normal'); | ||
}); | ||
|
||
test('Normal channel competes with content channel', function() { | ||
assertPolicy1('normal', 'content'); | ||
}); | ||
|
||
test('Normal channel competes with alarm channel', function() { | ||
assertPolicy1('normal', 'alarm'); | ||
}); | ||
|
||
test('Normal channel competes with system channel', function() { | ||
assertPolicy0('normal', 'system'); | ||
}); | ||
|
||
test('Normal channel competes with ringer channel', function() { | ||
assertPolicy1('normal', 'ringer'); | ||
}); | ||
|
||
test('Normal channel competes with telephony channel', function() { | ||
assertPolicy1('normal', 'telephony'); | ||
}); | ||
|
||
// Fix it in Bug 1228925. | ||
test.skip('Normal channel competes with notification channel', function() { | ||
assertPolicy3('normal', 'notification'); | ||
}); | ||
|
||
// Fix it in Bug 1228925. | ||
test.skip('Normal channel competes with' + | ||
'public notification channel', function() { | ||
assertPolicy3('normal', 'publicnotification'); | ||
}); | ||
}); | ||
|
||
// Ensure the two audio channels can pass the policy 0 in the spec. | ||
// Policy 0: Play both the current and the new channels. | ||
function assertPolicy0(audioChannel1, audioChannel2) { | ||
var testApp = sys.waitForLaunch(audioChannelTestApp1.origin); | ||
client.switchToFrame(testApp); | ||
audioChannelTestApp1[audioChannel1 + 'Play'].click(); | ||
audioChannelTestApp1[audioChannel2 + 'Play'].click(); | ||
|
||
client.switchToFrame(); | ||
var isPlaying = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isPlaying(); | ||
}, [audioChannelTestApp1.origin, audioChannel1]); | ||
assert.ok(isPlaying); | ||
isPlaying = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isPlaying(); | ||
}, [audioChannelTestApp1.origin, audioChannel2]); | ||
assert.ok(isPlaying); | ||
} | ||
|
||
// Ensure the two audio channels can pass the policy 1 in the spec. | ||
// Policy 1: Pause the current channel, | ||
// resume the current channel after the new channel ends and | ||
// when app comes to foreground. | ||
function assertPolicy1(audioChannel1, audioChannel2) { | ||
// Play an audio channel in Test App 1, and ensure it is played. | ||
var testApp1 = sys.waitForLaunch(audioChannelTestApp1.origin); | ||
client.switchToFrame(testApp1); | ||
audioChannelTestApp1[audioChannel1 + 'Play'].click(); | ||
|
||
client.switchToFrame(); | ||
var isPlaying = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isPlaying(); | ||
}, [audioChannelTestApp1.origin, audioChannel1]); | ||
assert.ok(isPlaying); | ||
|
||
// Play an audio channel in Test App 2. | ||
// Ensure the new audio channel is played, | ||
// and the current audio channel is paused. | ||
var testApp2 = sys.waitForLaunch(audioChannelTestApp2.origin); | ||
client.switchToFrame(testApp2); | ||
audioChannelTestApp2[audioChannel2 + 'Play'].click(); | ||
|
||
client.switchToFrame(); | ||
isPlaying = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isPlaying(); | ||
}, [audioChannelTestApp2.origin, audioChannel2]); | ||
assert.ok(isPlaying); | ||
isPlaying = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isPlaying(); | ||
}, [audioChannelTestApp1.origin, audioChannel1]); | ||
assert.ok(!isPlaying); | ||
|
||
// Pause the new audio channel in Test App 2, | ||
// and ensure the current audio channel is still paused. | ||
client.switchToFrame(testApp2); | ||
audioChannelTestApp2[audioChannel2 + 'Pause'].click(); | ||
|
||
client.switchToFrame(); | ||
isPlaying = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isPlaying(); | ||
}, [audioChannelTestApp1.origin, audioChannel1]); | ||
assert.ok(!isPlaying); | ||
|
||
// Open Test App 1, and ensure the current audio channel is played. | ||
sys.waitForLaunch(audioChannelTestApp1.origin); | ||
|
||
isPlaying = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isPlaying(); | ||
}, [audioChannelTestApp1.origin, audioChannel1]); | ||
assert.ok(isPlaying); | ||
} | ||
|
||
// Ensure the two audio channels can pass the policy 3 in the spec. | ||
// Policy 3: Volume down the current channel. | ||
function assertPolicy3(audioChannel1, audioChannel2) { | ||
var testApp = sys.waitForLaunch(audioChannelTestApp1.origin); | ||
client.switchToFrame(testApp); | ||
audioChannelTestApp1[audioChannel1 + 'Play'].click(); | ||
audioChannelTestApp1[audioChannel2 + 'Play'].click(); | ||
|
||
client.switchToFrame(); | ||
var isFadingOut = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isFadingOut(); | ||
}, [audioChannelTestApp1.origin, audioChannel1]); | ||
assert.ok(isFadingOut); | ||
var isPlaying = client.executeScript(function(url, type) { | ||
return window.wrappedJSObject.core.appCore.appWindowManager | ||
.getApp(url).audioChannels.get(type).isPlaying(); | ||
}, [audioChannelTestApp1.origin, audioChannel2]); | ||
assert.ok(isPlaying); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
'use strict'; | ||
|
||
function AudioChannelTestApp(client, origin) { | ||
this.client = client; | ||
this.origin = origin; | ||
} | ||
|
||
module.exports = AudioChannelTestApp; | ||
|
||
AudioChannelTestApp.Selector = Object.freeze({ | ||
normalPlay: '#normal .play', | ||
normalPause: '#normal .pause', | ||
contentPlay: '#content .play', | ||
contentPause: '#content .pause', | ||
alarmPlay: '#alarm .play', | ||
alarmPause: '#alarm .pause', | ||
systemPlay: '#system .play', | ||
systemPause: '#system .pause', | ||
ringerPlay: '#ringer .play', | ||
ringerPause: '#ringer .pause', | ||
telephonyPlay: '#telephony .play', | ||
telephonyPause: '#telephony .pause', | ||
notificationPlay: '#notification .play', | ||
notificationPause: '#notification .pause', | ||
publicnotificationPlay: '#publicnotification .play', | ||
publicnotificationPause: '#publicnotification .pause', | ||
}); | ||
|
||
AudioChannelTestApp.prototype = { | ||
client: null, | ||
|
||
get normalPlay() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.normalPlay); | ||
}, | ||
|
||
get normalPause() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.normalPause); | ||
}, | ||
|
||
get contentPlay() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.contentPlay); | ||
}, | ||
|
||
get contentPause() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.contentPause); | ||
}, | ||
|
||
get alarmPlay() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.alarmPlay); | ||
}, | ||
|
||
get alarmPause() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.alarmPause); | ||
}, | ||
|
||
get systemPlay() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.systemPlay); | ||
}, | ||
|
||
get systemPause() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.systemPause); | ||
}, | ||
|
||
get ringerPlay() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.ringerPlay); | ||
}, | ||
|
||
get ringerPause() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.ringerPause); | ||
}, | ||
|
||
get telephonyPlay() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.telephonyPlay); | ||
}, | ||
|
||
get telephonyPause() { | ||
return this.client.findElement(AudioChannelTestApp.Selector.telephonyPause); | ||
}, | ||
|
||
get notificationPlay() { | ||
return this.client | ||
.findElement(AudioChannelTestApp.Selector.notificationPlay); | ||
}, | ||
|
||
get notificationPause() { | ||
return this.client | ||
.findElement(AudioChannelTestApp.Selector.notificationPause); | ||
}, | ||
|
||
get publicnotificationPlay() { | ||
return this.client | ||
.findElement(AudioChannelTestApp.Selector.publicnotificationPlay); | ||
}, | ||
|
||
get publicnotificationPause() { | ||
return this.client | ||
.findElement(AudioChannelTestApp.Selector.publicnotificationPause); | ||
}, | ||
}; |