Skip to content

Commit

Permalink
Bug 1549041 - Test that documents receive the right audio notificatio…
Browse files Browse the repository at this point in the history
…n events when playback is done using the Web Audio API. r=karlt

Differential Revision: https://phabricator.services.mozilla.com/D30657

--HG--
extra : moz-landing-system : lando
  • Loading branch information
padenot committed May 17, 2019
1 parent cadd6ec commit ee6b47d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dom/base/test/file_webAudioAudible.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<meta charset=utf-8>
<script>
var ac = new AudioContext();
var osc = ac.createOscillator();
osc.connect(ac.destination);
osc.start();
</script>
4 changes: 4 additions & 0 deletions dom/base/test/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ support-files =
file_webaudioLoop.html
file_webaudioLoop2.html
file_webaudio_startstop.html
file_webAudioAudible.html
file_pluginAudio.html
file_pluginAudioNonAutoStart.html
noaudio.webm
Expand Down Expand Up @@ -272,6 +273,9 @@ skip-if = (os == "win" && processor == "aarch64") # bug 1535775
[test_audioNotificationStopOnNavigation.html]
tags = audiochannel
skip-if = (os == "win" && processor == "aarch64") # bug 1535775
[test_audioNotificationNavigationWebAudio.html]
tags = audiochannel
skip-if = (os == "win" && processor == "aarch64") # bug 1535775
[test_audioNotificationWithEarlyPlay.html]
tags = audiochannel
skip-if = (os == "win" && processor == "aarch64") # bug 1535775
Expand Down
75 changes: 75 additions & 0 deletions dom/base/test/test_audioNotificationNavigationWebAudio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for audio controller in windows, when using the Web Audio API</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<pre id="test">
</pre>
<iframe></iframe>

<script type="application/javascript">

SimpleTest.waitForExplicitFinish();

// playback starts, stops when the page is reloaded, and starts again.
var expectedNotification = ["active", "inactive-pause", "active"];
var iframe = null;

var observer = {
observe: function(subject, topic, data) {
is(topic, "audio-playback", "audio-playback received");
var expected = expectedNotification.shift();
is(data, expected, "This is the right notification");
if (expected != "inactive-pause") {
runTest();
}
}
};

var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);

var tests = [
function() {
iframe = document.querySelector("iframe");
observerService.addObserver(observer, "audio-playback");
ok(true, "Observer set");
runTest();
},

function() {
iframe.src = "file_webAudioAudible.html";
},

function() {
// Reload
iframe.src = "file_webAudioAudible.html";
},
function() {
// Wait for the "active" notification, that is expected after the previous
// load of "file_webAudioAudible.html".
runTest();
}
];

function runTest() {
if (!tests.length) {
observerService.removeObserver(observer, "audio-playback");
ok(true, "Observer removed");
SimpleTest.finish();
return;
}

var test = tests.shift();
test();
}

onload = runTest;

</script>
</body>
</html>

0 comments on commit ee6b47d

Please sign in to comment.