summaryrefslogtreecommitdiff
path: root/dom/base/test/test_audioNotificationSilent_webAudio.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/test/test_audioNotificationSilent_webAudio.html')
-rw-r--r--dom/base/test/test_audioNotificationSilent_webAudio.html103
1 files changed, 103 insertions, 0 deletions
diff --git a/dom/base/test/test_audioNotificationSilent_webAudio.html b/dom/base/test/test_audioNotificationSilent_webAudio.html
new file mode 100644
index 0000000000..de4165f8e4
--- /dev/null
+++ b/dom/base/test/test_audioNotificationSilent_webAudio.html
@@ -0,0 +1,103 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Audio-playback should be inactive when web-audio is silent</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<script type="application/javascript;version=1.7">
+
+SimpleTest.waitForExplicitFinish();
+
+var generator = runTest();
+var expectedPlaybackActive = null;
+var expectedPlaying = null;
+
+var ac = new AudioContext();
+var audibleDuration = 3;
+
+var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
+ .getService(SpecialPowers.Ci.nsIObserverService);
+
+var observer = {
+ observe: function(subject, topic, data) {
+ is(topic, "audio-playback", "audio-playback received");
+ is(data, expectedPlaybackActive, "Corrrect audible state");
+ is(ac.state, expectedPlaying, "Corrrect playing state");
+ continueTest();
+ }
+};
+
+function continueTest() {
+ try {
+ generator.next();
+ } catch (e if e instanceof StopIteration) {
+ error("Stop test because of exception!");
+ }
+}
+
+function playOscillatorNode() {
+ var dest = ac.destination;
+ var osc = ac.createOscillator();
+ osc.connect(dest);
+ osc.start(0);
+ osc.stop(ac.currentTime + audibleDuration);
+}
+
+function audioPlayingStart() {
+ observerService.addObserver(observer, "audio-playback", false);
+ ok(true, "Observer set");
+
+ expectedPlaybackActive = 'active';
+ expectedPlaying = "running";
+
+ info("Audio playing start");
+ playOscillatorNode();
+}
+
+function audioBecomeSilentDuringPlaying() {
+ info("Audio would become silent during playing");
+
+ expectedPlaybackActive = 'inactive-pause';
+ expectedPlaying = "running";
+}
+
+function finish() {
+ observerService.removeObserver(observer, "audio-playback");
+ ok(true, "Observer removed");
+
+ SimpleTest.finish();
+}
+
+function startAudioContext() {
+ if (ac.state != "running") {
+ ac.resume();
+ ac.onstatechange = function() {
+ if (ac.state == "running") {
+ ok(true, "AudioContext starts running!");
+ ac.onstatechange = null;
+ continueTest();
+ }
+ }
+ } else {
+ ok(true, "AudioContext is running!");
+ continueTest();
+ }
+}
+
+function runTest() {
+ yield startAudioContext();
+
+ yield audioPlayingStart();
+
+ yield audioBecomeSilentDuringPlaying();
+
+ yield finish();
+}
+
+continueTest();
+
+</script>
+</body>
+</html> \ No newline at end of file