content/media/webaudio/test/test_mozaudiochannel.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_mozaudiochannel.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for mozaudiochannel</title>
     1.8 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.11 +</head>
    1.12 +<body>
    1.13 +<p id="display"></p>
    1.14 +<pre id="test">
    1.15 +<script type="application/javascript">
    1.16 +
    1.17 +function test_basic() {
    1.18 +  var ac = new AudioContext();
    1.19 +  ok(ac, "AudioContext created");
    1.20 +
    1.21 +  // Default
    1.22 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.23 +
    1.24 +  // random wrong channel
    1.25 +  ac.mozAudioChannelType = "foo";
    1.26 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.27 +
    1.28 +  // Unpermitted channels
    1.29 +  ac.mozAudioChannelType = "content";
    1.30 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.31 +
    1.32 +  ac.mozAudioChannelType = "notification";
    1.33 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.34 +
    1.35 +  ac.mozAudioChannelType = "alarm";
    1.36 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.37 +
    1.38 +  ac.mozAudioChannelType = "telephony";
    1.39 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.40 +
    1.41 +  ac.mozAudioChannelType = "ringer";
    1.42 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.43 +
    1.44 +  ac.mozAudioChannelType = "publicnotification";
    1.45 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.46 +
    1.47 +  runTest();
    1.48 +}
    1.49 +
    1.50 +function test_permission(aChannel) {
    1.51 +  var ac = new AudioContext();
    1.52 +  ok(ac, "AudioContext created");
    1.53 +
    1.54 +  is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    1.55 +
    1.56 +  SpecialPowers.pushPermissions(
    1.57 +    [{ "type": "audio-channel-" + aChannel, "allow": true, "context": document }],
    1.58 +    function() {
    1.59 +      ac.mozAudioChannelType = aChannel;
    1.60 +      is(ac.mozAudioChannelType, aChannel, "Default ac channel == '" + aChannel + "'");
    1.61 +      runTest();
    1.62 +    }
    1.63 +  );
    1.64 +}
    1.65 +
    1.66 +function test_preferences(aChannel) {
    1.67 +  SpecialPowers.pushPrefEnv({"set": [["media.defaultAudioChannel", aChannel ]]},
    1.68 +    function() {
    1.69 +      SpecialPowers.pushPermissions(
    1.70 +        [{ "type": "audio-channel-" + aChannel, "allow": false, "context": document }],
    1.71 +        function() {
    1.72 +          var ac = new AudioContext(aChannel);
    1.73 +          ok(ac, "AudioContext created");
    1.74 +          is(ac.mozAudioChannelType, aChannel, "Default ac channel == '" + aChannel + "'");
    1.75 +          runTest();
    1.76 +        }
    1.77 +      );
    1.78 +    }
    1.79 +  );
    1.80 +}
    1.81 +
    1.82 +function test_wrong_preferences() {
    1.83 +  SpecialPowers.pushPrefEnv({"set": [["media.defaultAudioChannel", 'foobar' ]]},
    1.84 +    function() {
    1.85 +      var ac = new AudioContext();
    1.86 +      ok(ac, "AudioContext created");
    1.87 +      is(ac.mozAudioChannelType, 'normal', "Default ac channel == 'normal'");
    1.88 +      runTest();
    1.89 +    }
    1.90 +  );
    1.91 +}
    1.92 +
    1.93 +var tests = [
    1.94 +  test_basic,
    1.95 +
    1.96 +  function() { test_permission("content"); },
    1.97 +  function() { test_permission("notification"); },
    1.98 +  function() { test_permission("alarm"); },
    1.99 +  function() { test_permission("telephony"); },
   1.100 +  function() { test_permission("ringer"); },
   1.101 +  function() { test_permission("publicnotification"); },
   1.102 +
   1.103 +  function() { test_preferences("content"); },
   1.104 +  function() { test_preferences("notification"); },
   1.105 +  function() { test_preferences("alarm"); },
   1.106 +  function() { test_preferences("telephony"); },
   1.107 +  function() { test_preferences("ringer"); },
   1.108 +  function() { test_preferences("publicnotification"); },
   1.109 +
   1.110 +  test_wrong_preferences,
   1.111 +];
   1.112 +
   1.113 +function runTest() {
   1.114 +  if (!tests.length) {
   1.115 +    SimpleTest.finish();
   1.116 +    return;
   1.117 +  }
   1.118 +
   1.119 +  var test = tests.shift();
   1.120 +  test();
   1.121 +}
   1.122 +
   1.123 +SpecialPowers.pushPrefEnv({"set": [["media.useAudioChannelService", true ]]}, runTest);
   1.124 +SimpleTest.waitForExplicitFinish();
   1.125 +
   1.126 +</script>
   1.127 +</pre>
   1.128 +</body>
   1.129 +</html>

mercurial