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..0e35e242d944 --- /dev/null +++ b/apps/system/test/marionette/audio_channel_competing_test.js @@ -0,0 +1,158 @@ +/* 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'); + }); + + // test('Normal channel competes with notification channel', function() { + // assertPolicy3('normal', 'notification'); + // }); + + // test('Normal channel competes with' + + // 'public notification channel', function() { + // assertPolicy3('normal', 'publicnotification'); + // }); + }); + + 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); + 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); + } + + // function assertPolicy3(audioChannel1, audioChannel2) { + // var testApp1 = sys.waitForLaunch(audioChannelTestApp1.origin); + // client.switchToFrame(testApp1); + // 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); + // } +}); 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..3d1a066f6fe1 --- /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); + }, +};