dom/audiochannel/tests/test_audioChannelChange.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   <meta charset="utf-8">
     5   <title>Test audio-channel-changed & visible-audio-channel-changed mozChromeEvent</title>
     6   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     7   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     8 </head>
     9 <body>
    10   <div id="content"></div>
    11   <script type="application/javascript;version=1.7">
    12   var expectedAudioTypes;
    13   var expectedVisibleAudioTypes;
    14   var expectedVisibleAudioType;
    15   var index;
    16   var visibleIndex;
    17   var iframe1;
    18   var normalAudio;
    20   function playWithAudioType(audio, type) {
    21     audio.mozAudioChannelType = type;
    22     audio.src = "test.ogg";
    23     audio.loop = true;
    25     audio.play();
    26   }
    28   function fgBgTestListener(message) {
    29     var type = message.type;
    30     var channel = message.channel;
    32     if (type == 'audio-channel-changed') {
    33       is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]);
    34       index++;
    35     }
    37     if (type == 'visible-audio-channel-changed') {
    38       is(channel, expectedVisibleAudioType, channel + " is received and expected " + expectedVisibleAudioType);
    39     }
    41     // All audio types are playing now so ask to pause them.
    42     // This call will stop audio from highest to telephony.
    43     if ('cmd-pause' == expectedAudioTypes[index]) {
    44       iframe1.src = 'file_audio.html#pauseAudio';
    45       index++;
    46     }
    48     // According to there is a 1.5 second delay of releasing telephony,
    49     // we need to wait for it then continue to pause others.
    50     if ('cmd-secondPause' == expectedAudioTypes[index]) {
    51       iframe1.src = 'file_audio.html#pauseAudioFollowing';
    52       index++;
    53     }
    55     if (index == expectedAudioTypes.length) {
    56       document.body.removeChild(iframe1);
    57       script.removeMessageListener('chrome-event', fgBgTestListener);
    58       normalAudio.pause();
    59       SimpleTest.finish();
    60     }
    61   }
    63   // Channel of visible-audio-channel-changed event should be always normal.
    64   // Audios in background should not effect visible-audio-channel-changed.
    65   function runFgBgTest() {
    66     expectedAudioTypes = ["normal", "content", "notification",
    67                           "alarm", "telephony", "ringer", "publicnotification", "cmd-pause",
    68                           "ringer", "telephony", "alarm", "cmd-secondPause", "notification",
    69                           "content", "normal"];
    70     expectedVisibleAudioType = "normal";
    71     index = 0;
    73     script.addMessageListener('chrome-event', fgBgTestListener);
    75     // To play a audio with normal channel in the foreground.
    76     normalAudio = new Audio();
    77     playWithAudioType(normalAudio, 'normal');
    79     iframe1.src = 'file_audio.html#bg';
    80     document.body.appendChild(iframe1);
    81     iframe1.setVisible(false);
    82   }
    84   function bgTestListener(message) {
    85     var type = message.type;
    86     var channel = message.channel;
    88     if (type == 'audio-channel-changed') {
    89       is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]);
    90       index++;
    91     }
    93     if (type == 'visible-audio-channel-changed') {
    94       is(channel, expectedVisibleAudioType, channel + " is received and expected " + expectedVisibleAudioType);
    95     }
    97     // All audio types are playing now so ask to pause them.
    98     if ('cmd-pause' == expectedAudioTypes[index]) {
    99       iframe1.src = 'file_audio.html#pauseAudio';
   100       index++;
   101     }
   103     if ('cmd-secondPause' == expectedAudioTypes[index]) {
   104       iframe1.src = 'file_audio.html#pauseAudioFollowing';
   105       index++;
   106     }
   108     if (index == expectedAudioTypes.length) {
   109       document.body.removeChild(iframe1);
   110       script.removeMessageListener('chrome-event', bgTestListener);
   111       runFgBgTest();
   112     }
   113   }
   115   // 1. Channel of visible-audio-channel-changed event should be always none.
   116   // 2. normal is not allowed to be played in the background.
   117   function runBgTest() {
   118     expectedAudioTypes = ["content", "notification",
   119                           "alarm", "telephony", "ringer", "publicnotification", "cmd-pause",
   120                          "ringer", "telephony", "alarm", "cmd-secondPause", "notification",
   121                           "content", "none"];
   122     expectedVisibleAudioType = "none";
   123     index = 0;
   125     script.addMessageListener('chrome-event', bgTestListener);
   127     iframe1.src = 'file_audio.html#bg';
   128     document.body.appendChild(iframe1);
   129     iframe1.setVisible(false);
   130   }
   132   function fgTestListener(message) {
   133     var type = message.type;
   134     var channel = message.channel;
   136     if (type == 'audio-channel-changed') {
   137       is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]);
   138       index++;
   139     }
   141     if (type == 'visible-audio-channel-changed') {
   142       is(channel, expectedAudioTypes[visibleIndex], channel + " is received and expected " + expectedAudioTypes[visibleIndex]);
   143       visibleIndex++;
   144     }
   146     // All audio types are playing now so ask to pause them.
   147     if ('cmd-pause' == expectedAudioTypes[visibleIndex] &&
   148         'cmd-pause' == expectedAudioTypes[index]) {
   149       iframe1.src = 'file_audio.html#pauseAudio';
   150       visibleIndex++;
   151       index++;
   152     }
   154     if ('cmd-secondPause' == expectedAudioTypes[visibleIndex] &&
   155         'cmd-secondPause' == expectedAudioTypes[index]) {
   156       iframe1.src = 'file_audio.html#pauseAudioFollowing';
   157       visibleIndex++;
   158       index++;
   159     }
   161     if (index == expectedAudioTypes.length && visibleIndex == expectedAudioTypes.length) {
   162       document.body.removeChild(iframe1);
   163       script.removeMessageListener('chrome-event', fgTestListener);
   164       runBgTest();
   165     }
   166   }
   168   // The foreground audio will effect both of audio-channel-changed and
   169   // visible-audio-channel-changed.
   170   function runFgTest() {
   171     expectedAudioTypes = ["normal", "content", "notification",
   172                           "alarm", "telephony", "ringer", "publicnotification",
   173                           "cmd-pause", "ringer", "telephony", "alarm",
   174                           "cmd-secondPause", "notification", "content",
   175                           "normal", "none"];
   177     index = 0;
   178     visibleIndex = 0;
   180     script.addMessageListener('chrome-event', fgTestListener);
   182     iframe1 = document.createElement('iframe');
   183     iframe1.setAttribute('mozbrowser', true);
   184     iframe1.src = 'file_audio.html#fg';
   185     document.body.appendChild(iframe1);
   186   }
   188   var url = SimpleTest.getTestFileURL("AudioChannelChromeScript.js")
   189   var script = SpecialPowers.loadChromeScript(url);
   190   script.sendAsyncMessage("init-chrome-event", {
   191     type: 'audio-channel-changed'
   192   });
   193   script.sendAsyncMessage("init-chrome-event", {
   194     type: 'visible-audio-channel-changed'
   195   });
   197   SimpleTest.waitForExplicitFinish();
   199   SpecialPowers.pushPermissions(
   200     [{ "type": "browser", "allow": 1, "context": document },
   201      { "type": "embed-apps", "allow": 1, "context": document },
   202      { "type": "webapps-manage", "allow": 1, "context": document }], function() {
   203     SpecialPowers.pushPrefEnv({"set": [["dom.ipc.browser_frames.oop_by_default", true],
   204                                        ["media.useAudioChannelService", true],
   205                                        ["dom.mozBrowserFramesEnabled", true]]}, runFgTest);
   206   });
   207   </script>
   208 </body>
   209 </html>

mercurial