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
- Loading branch information
Showing
6 changed files
with
323 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": {} | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
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,127 @@ | ||
/* 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 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'); | ||
}); | ||
}); | ||
|
||
function assertPolicy0(audioChannel1, audioChannel2) { | ||
var testApp1 = sys.waitForLaunch(audioChannelTestApp1.origin); | ||
client.switchToFrame(testApp1); | ||
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); | ||
} | ||
|
||
function assertPolicy1(audioChannel1, audioChannel2) { | ||
// Play normal 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 content audio channel in Test App 2. | ||
// Ensure content audio channel is played, | ||
// and normal 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); | ||
client.helper.wait(1000); | ||
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 content audio channel in Test App 2, | ||
// and ensure normal 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 normal 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); | ||
} | ||
}); |
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); | ||
}, | ||
}; |