dom/audiochannel/tests/test_audioChannelChange.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/audiochannel/tests/test_audioChannelChange.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,209 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8">
     1.8 +  <title>Test audio-channel-changed & visible-audio-channel-changed mozChromeEvent</title>
     1.9 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.11 +</head>
    1.12 +<body>
    1.13 +  <div id="content"></div>
    1.14 +  <script type="application/javascript;version=1.7">
    1.15 +  var expectedAudioTypes;
    1.16 +  var expectedVisibleAudioTypes;
    1.17 +  var expectedVisibleAudioType;
    1.18 +  var index;
    1.19 +  var visibleIndex;
    1.20 +  var iframe1;
    1.21 +  var normalAudio;
    1.22 +
    1.23 +  function playWithAudioType(audio, type) {
    1.24 +    audio.mozAudioChannelType = type;
    1.25 +    audio.src = "test.ogg";
    1.26 +    audio.loop = true;
    1.27 +
    1.28 +    audio.play();
    1.29 +  }
    1.30 +
    1.31 +  function fgBgTestListener(message) {
    1.32 +    var type = message.type;
    1.33 +    var channel = message.channel;
    1.34 +
    1.35 +    if (type == 'audio-channel-changed') {
    1.36 +      is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]);
    1.37 +      index++;
    1.38 +    }
    1.39 +
    1.40 +    if (type == 'visible-audio-channel-changed') {
    1.41 +      is(channel, expectedVisibleAudioType, channel + " is received and expected " + expectedVisibleAudioType);
    1.42 +    }
    1.43 +
    1.44 +    // All audio types are playing now so ask to pause them.
    1.45 +    // This call will stop audio from highest to telephony.
    1.46 +    if ('cmd-pause' == expectedAudioTypes[index]) {
    1.47 +      iframe1.src = 'file_audio.html#pauseAudio';
    1.48 +      index++;
    1.49 +    }
    1.50 +
    1.51 +    // According to there is a 1.5 second delay of releasing telephony,
    1.52 +    // we need to wait for it then continue to pause others.
    1.53 +    if ('cmd-secondPause' == expectedAudioTypes[index]) {
    1.54 +      iframe1.src = 'file_audio.html#pauseAudioFollowing';
    1.55 +      index++;
    1.56 +    }
    1.57 +
    1.58 +    if (index == expectedAudioTypes.length) {
    1.59 +      document.body.removeChild(iframe1);
    1.60 +      script.removeMessageListener('chrome-event', fgBgTestListener);
    1.61 +      normalAudio.pause();
    1.62 +      SimpleTest.finish();
    1.63 +    }
    1.64 +  }
    1.65 +
    1.66 +  // Channel of visible-audio-channel-changed event should be always normal.
    1.67 +  // Audios in background should not effect visible-audio-channel-changed.
    1.68 +  function runFgBgTest() {
    1.69 +    expectedAudioTypes = ["normal", "content", "notification",
    1.70 +                          "alarm", "telephony", "ringer", "publicnotification", "cmd-pause",
    1.71 +                          "ringer", "telephony", "alarm", "cmd-secondPause", "notification",
    1.72 +                          "content", "normal"];
    1.73 +    expectedVisibleAudioType = "normal";
    1.74 +    index = 0;
    1.75 +
    1.76 +    script.addMessageListener('chrome-event', fgBgTestListener);
    1.77 +
    1.78 +    // To play a audio with normal channel in the foreground.
    1.79 +    normalAudio = new Audio();
    1.80 +    playWithAudioType(normalAudio, 'normal');
    1.81 +
    1.82 +    iframe1.src = 'file_audio.html#bg';
    1.83 +    document.body.appendChild(iframe1);
    1.84 +    iframe1.setVisible(false);
    1.85 +  }
    1.86 +
    1.87 +  function bgTestListener(message) {
    1.88 +    var type = message.type;
    1.89 +    var channel = message.channel;
    1.90 +
    1.91 +    if (type == 'audio-channel-changed') {
    1.92 +      is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]);
    1.93 +      index++;
    1.94 +    }
    1.95 +
    1.96 +    if (type == 'visible-audio-channel-changed') {
    1.97 +      is(channel, expectedVisibleAudioType, channel + " is received and expected " + expectedVisibleAudioType);
    1.98 +    }
    1.99 +
   1.100 +    // All audio types are playing now so ask to pause them.
   1.101 +    if ('cmd-pause' == expectedAudioTypes[index]) {
   1.102 +      iframe1.src = 'file_audio.html#pauseAudio';
   1.103 +      index++;
   1.104 +    }
   1.105 +
   1.106 +    if ('cmd-secondPause' == expectedAudioTypes[index]) {
   1.107 +      iframe1.src = 'file_audio.html#pauseAudioFollowing';
   1.108 +      index++;
   1.109 +    }
   1.110 +
   1.111 +    if (index == expectedAudioTypes.length) {
   1.112 +      document.body.removeChild(iframe1);
   1.113 +      script.removeMessageListener('chrome-event', bgTestListener);
   1.114 +      runFgBgTest();
   1.115 +    }
   1.116 +  }
   1.117 +
   1.118 +  // 1. Channel of visible-audio-channel-changed event should be always none.
   1.119 +  // 2. normal is not allowed to be played in the background.
   1.120 +  function runBgTest() {
   1.121 +    expectedAudioTypes = ["content", "notification",
   1.122 +                          "alarm", "telephony", "ringer", "publicnotification", "cmd-pause",
   1.123 +                         "ringer", "telephony", "alarm", "cmd-secondPause", "notification",
   1.124 +                          "content", "none"];
   1.125 +    expectedVisibleAudioType = "none";
   1.126 +    index = 0;
   1.127 +
   1.128 +    script.addMessageListener('chrome-event', bgTestListener);
   1.129 +
   1.130 +    iframe1.src = 'file_audio.html#bg';
   1.131 +    document.body.appendChild(iframe1);
   1.132 +    iframe1.setVisible(false);
   1.133 +  }
   1.134 +
   1.135 +  function fgTestListener(message) {
   1.136 +    var type = message.type;
   1.137 +    var channel = message.channel;
   1.138 +
   1.139 +    if (type == 'audio-channel-changed') {
   1.140 +      is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]);
   1.141 +      index++;
   1.142 +    }
   1.143 +
   1.144 +    if (type == 'visible-audio-channel-changed') {
   1.145 +      is(channel, expectedAudioTypes[visibleIndex], channel + " is received and expected " + expectedAudioTypes[visibleIndex]);
   1.146 +      visibleIndex++;
   1.147 +    }
   1.148 +
   1.149 +    // All audio types are playing now so ask to pause them.
   1.150 +    if ('cmd-pause' == expectedAudioTypes[visibleIndex] &&
   1.151 +        'cmd-pause' == expectedAudioTypes[index]) {
   1.152 +      iframe1.src = 'file_audio.html#pauseAudio';
   1.153 +      visibleIndex++;
   1.154 +      index++;
   1.155 +    }
   1.156 +
   1.157 +    if ('cmd-secondPause' == expectedAudioTypes[visibleIndex] &&
   1.158 +        'cmd-secondPause' == expectedAudioTypes[index]) {
   1.159 +      iframe1.src = 'file_audio.html#pauseAudioFollowing';
   1.160 +      visibleIndex++;
   1.161 +      index++;
   1.162 +    }
   1.163 +
   1.164 +    if (index == expectedAudioTypes.length && visibleIndex == expectedAudioTypes.length) {
   1.165 +      document.body.removeChild(iframe1);
   1.166 +      script.removeMessageListener('chrome-event', fgTestListener);
   1.167 +      runBgTest();
   1.168 +    }
   1.169 +  }
   1.170 +
   1.171 +  // The foreground audio will effect both of audio-channel-changed and
   1.172 +  // visible-audio-channel-changed.
   1.173 +  function runFgTest() {
   1.174 +    expectedAudioTypes = ["normal", "content", "notification",
   1.175 +                          "alarm", "telephony", "ringer", "publicnotification",
   1.176 +                          "cmd-pause", "ringer", "telephony", "alarm",
   1.177 +                          "cmd-secondPause", "notification", "content",
   1.178 +                          "normal", "none"];
   1.179 +
   1.180 +    index = 0;
   1.181 +    visibleIndex = 0;
   1.182 +
   1.183 +    script.addMessageListener('chrome-event', fgTestListener);
   1.184 +
   1.185 +    iframe1 = document.createElement('iframe');
   1.186 +    iframe1.setAttribute('mozbrowser', true);
   1.187 +    iframe1.src = 'file_audio.html#fg';
   1.188 +    document.body.appendChild(iframe1);
   1.189 +  }
   1.190 +
   1.191 +  var url = SimpleTest.getTestFileURL("AudioChannelChromeScript.js")
   1.192 +  var script = SpecialPowers.loadChromeScript(url);
   1.193 +  script.sendAsyncMessage("init-chrome-event", {
   1.194 +    type: 'audio-channel-changed'
   1.195 +  });
   1.196 +  script.sendAsyncMessage("init-chrome-event", {
   1.197 +    type: 'visible-audio-channel-changed'
   1.198 +  });
   1.199 +
   1.200 +  SimpleTest.waitForExplicitFinish();
   1.201 +
   1.202 +  SpecialPowers.pushPermissions(
   1.203 +    [{ "type": "browser", "allow": 1, "context": document },
   1.204 +     { "type": "embed-apps", "allow": 1, "context": document },
   1.205 +     { "type": "webapps-manage", "allow": 1, "context": document }], function() {
   1.206 +    SpecialPowers.pushPrefEnv({"set": [["dom.ipc.browser_frames.oop_by_default", true],
   1.207 +                                       ["media.useAudioChannelService", true],
   1.208 +                                       ["dom.mozBrowserFramesEnabled", true]]}, runFgTest);
   1.209 +  });
   1.210 +  </script>
   1.211 +</body>
   1.212 +</html>

mercurial