diff --git a/apps/system/test/apps/audio_channel_test_app/audio/b2g.ogg b/apps/system/test/apps/audio_channel_test_app/audio/b2g.ogg new file mode 100644 index 000000000000..9c143280c8cd Binary files /dev/null and b/apps/system/test/apps/audio_channel_test_app/audio/b2g.ogg differ diff --git a/apps/system/test/apps/audio_channel_test_app/index.html b/apps/system/test/apps/audio_channel_test_app/index.html new file mode 100644 index 000000000000..396d8e5a4c05 --- /dev/null +++ b/apps/system/test/apps/audio_channel_test_app/index.html @@ -0,0 +1,57 @@ + + + + + Audio Channel Test App + + + + +
+ Normal + + +
+
+ Content + + +
+
+ Alarm + + +
+
+ System + + +
+
+ Ringer + + +
+
+ Telephony + + +
+
+ Notification + + +
+
+ Public Notification + + +
+ + diff --git a/apps/system/test/apps/audio_channel_test_app/js/index.js b/apps/system/test/apps/audio_channel_test_app/js/index.js new file mode 100644 index 000000000000..4372fcf34d24 --- /dev/null +++ b/apps/system/test/apps/audio_channel_test_app/js/index.js @@ -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(); + }); + }); +}()); diff --git a/apps/system/test/apps/audio_channel_test_app/manifest.webapp b/apps/system/test/apps/audio_channel_test_app/manifest.webapp new file mode 100644 index 000000000000..92dfd6ee9284 --- /dev/null +++ b/apps/system/test/apps/audio_channel_test_app/manifest.webapp @@ -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": {} + } +} diff --git a/apps/system/test/marionette/audio_channel_competing_test.js b/apps/system/test/marionette/audio_channel_competing_test.js new file mode 100644 index 000000000000..7e3789f950d7 --- /dev/null +++ b/apps/system/test/marionette/audio_channel_competing_test.js @@ -0,0 +1,88 @@ +/* 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() { + // Play normal audio channel in Test App 1, and ensure it is played. + var testApp1 = sys.waitForLaunch(audioChannelTestApp1.origin); + client.switchToFrame(testApp1); + audioChannelTestApp1.normalPlay.click(); + + client.switchToFrame(); + var isPlaying = client.executeScript(function(url) { + return window.wrappedJSObject.core.appCore.appWindowManager + .getApp(url).audioChannels.get('normal').isPlaying(); + }, [audioChannelTestApp1.origin]); + 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.contentPlay.click(); + + client.switchToFrame(); + isPlaying = client.executeScript(function(url) { + return window.wrappedJSObject.core.appCore.appWindowManager + .getApp(url).audioChannels.get('content').isPlaying(); + }, [audioChannelTestApp2.origin]); + assert.ok(isPlaying); + client.helper.wait(1000); + isPlaying = client.executeScript(function(url) { + return window.wrappedJSObject.core.appCore.appWindowManager + .getApp(url).audioChannels.get('normal').isPlaying(); + }, [audioChannelTestApp1.origin]); + assert.ok(!isPlaying); + + // Pause content audio channel in Test App 2, + // and ensure normal audio channel is still paused. + client.switchToFrame(testApp2); + audioChannelTestApp2.contentPause.click(); + + client.switchToFrame(); + isPlaying = client.executeScript(function(url) { + return window.wrappedJSObject.core.appCore.appWindowManager + .getApp(url).audioChannels.get('normal').isPlaying(); + }, [audioChannelTestApp1.origin]); + assert.ok(!isPlaying); + + // Open Test App 1, and ensure normal audio channel is played. + sys.waitForLaunch(audioChannelTestApp1.origin); + + isPlaying = client.executeScript(function(url) { + return window.wrappedJSObject.core.appCore.appWindowManager + .getApp(url).audioChannels.get('normal').isPlaying(); + }, [audioChannelTestApp1.origin]); + assert.ok(isPlaying); + }); + }); +}); diff --git a/apps/system/test/marionette/lib/audio_channel_test_app.js b/apps/system/test/marionette/lib/audio_channel_test_app.js new file mode 100644 index 000000000000..00932bbcbc80 --- /dev/null +++ b/apps/system/test/marionette/lib/audio_channel_test_app.js @@ -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); + }, +};