content/media/webaudio/test/test_mozaudiochannel.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for mozaudiochannel</title>
     5   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     8 </head>
     9 <body>
    10 <p id="display"></p>
    11 <pre id="test">
    12 <script type="application/javascript">
    14 function test_basic() {
    15   var ac = new AudioContext();
    16   ok(ac, "AudioContext created");
    18   // Default
    19   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    21   // random wrong channel
    22   ac.mozAudioChannelType = "foo";
    23   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    25   // Unpermitted channels
    26   ac.mozAudioChannelType = "content";
    27   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    29   ac.mozAudioChannelType = "notification";
    30   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    32   ac.mozAudioChannelType = "alarm";
    33   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    35   ac.mozAudioChannelType = "telephony";
    36   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    38   ac.mozAudioChannelType = "ringer";
    39   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    41   ac.mozAudioChannelType = "publicnotification";
    42   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    44   runTest();
    45 }
    47 function test_permission(aChannel) {
    48   var ac = new AudioContext();
    49   ok(ac, "AudioContext created");
    51   is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'");
    53   SpecialPowers.pushPermissions(
    54     [{ "type": "audio-channel-" + aChannel, "allow": true, "context": document }],
    55     function() {
    56       ac.mozAudioChannelType = aChannel;
    57       is(ac.mozAudioChannelType, aChannel, "Default ac channel == '" + aChannel + "'");
    58       runTest();
    59     }
    60   );
    61 }
    63 function test_preferences(aChannel) {
    64   SpecialPowers.pushPrefEnv({"set": [["media.defaultAudioChannel", aChannel ]]},
    65     function() {
    66       SpecialPowers.pushPermissions(
    67         [{ "type": "audio-channel-" + aChannel, "allow": false, "context": document }],
    68         function() {
    69           var ac = new AudioContext(aChannel);
    70           ok(ac, "AudioContext created");
    71           is(ac.mozAudioChannelType, aChannel, "Default ac channel == '" + aChannel + "'");
    72           runTest();
    73         }
    74       );
    75     }
    76   );
    77 }
    79 function test_wrong_preferences() {
    80   SpecialPowers.pushPrefEnv({"set": [["media.defaultAudioChannel", 'foobar' ]]},
    81     function() {
    82       var ac = new AudioContext();
    83       ok(ac, "AudioContext created");
    84       is(ac.mozAudioChannelType, 'normal', "Default ac channel == 'normal'");
    85       runTest();
    86     }
    87   );
    88 }
    90 var tests = [
    91   test_basic,
    93   function() { test_permission("content"); },
    94   function() { test_permission("notification"); },
    95   function() { test_permission("alarm"); },
    96   function() { test_permission("telephony"); },
    97   function() { test_permission("ringer"); },
    98   function() { test_permission("publicnotification"); },
   100   function() { test_preferences("content"); },
   101   function() { test_preferences("notification"); },
   102   function() { test_preferences("alarm"); },
   103   function() { test_preferences("telephony"); },
   104   function() { test_preferences("ringer"); },
   105   function() { test_preferences("publicnotification"); },
   107   test_wrong_preferences,
   108 ];
   110 function runTest() {
   111   if (!tests.length) {
   112     SimpleTest.finish();
   113     return;
   114   }
   116   var test = tests.shift();
   117   test();
   118 }
   120 SpecialPowers.pushPrefEnv({"set": [["media.useAudioChannelService", true ]]}, runTest);
   121 SimpleTest.waitForExplicitFinish();
   123 </script>
   124 </pre>
   125 </body>
   126 </html>

mercurial