Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1227824 - Normal audio channels compete with all kinds of audio c…
Browse files Browse the repository at this point in the history
…hannels r=lchang
  • Loading branch information
evanxd committed Nov 30, 2015
1 parent 1c29975 commit 0f94474
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 0 deletions.
Binary file not shown.
57 changes: 57 additions & 0 deletions apps/system/test/apps/audio_channel_test_app/index.html
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>
21 changes: 21 additions & 0 deletions apps/system/test/apps/audio_channel_test_app/js/index.js
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 apps/system/test/apps/audio_channel_test_app/manifest.webapp
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": {}
}
}
186 changes: 186 additions & 0 deletions apps/system/test/marionette/audio_channel_competing_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/* 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[1].
* Policy 0: Play both the current and the new channels.
* [1]: https://bug1096163.bmoattachments.org/attachment.cgi?id=8691714#12
*
* @param {String} audioChannel1 An audio channel type.
* @param {String} audioChannel2 An audio channel type.
*/
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[1].
* Policy 1: Pause the current channel,
* resume the current channel after the new channel ends and
* when app comes to foreground.
* [1]: https://bug1096163.bmoattachments.org/attachment.cgi?id=8691714#12
*
* @param {String} audioChannel1 An audio channel type.
* @param {String} audioChannel2 An audio channel type.
*/
function assertPolicy1(audioChannel1, audioChannel2) {
// Play an audio channel in Test App 1, and ensure it can be 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 can be 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 can be 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[1].
* Policy 3: Volume down the current channel.
* [1]: https://bug1096163.bmoattachments.org/attachment.cgi?id=8691714#12
*
* @param {String} audioChannel1 An audio channel type.
* @param {String} audioChannel2 An audio channel type.
*/
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);
}
});
99 changes: 99 additions & 0 deletions apps/system/test/marionette/lib/audio_channel_test_app.js
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);
},
};

0 comments on commit 0f94474

Please sign in to comment.