dom/base/test/test_audioNotification.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/base/test/test_audioNotification.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test for audio controller in windows</title>
     1.8 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.10 +</head>
    1.11 +<body>
    1.12 +<pre id="test">
    1.13 +</pre>
    1.14 +
    1.15 +<script type="application/javascript">
    1.16 +
    1.17 +SimpleTest.waitForExplicitFinish();
    1.18 +
    1.19 +var expectedNotification = null;
    1.20 +
    1.21 +var observer = {
    1.22 +  observe: function(subject, topic, data) {
    1.23 +    is(topic, "media-playback", "media-playback received");
    1.24 +    is(data, expectedNotification, "This is the right notification");
    1.25 +    runTest();
    1.26 +  }
    1.27 +};
    1.28 +
    1.29 +var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
    1.30 +                                   .getService(SpecialPowers.Ci.nsIObserverService);
    1.31 +
    1.32 +var audio = new Audio();
    1.33 +audio.src = "audio.ogg";
    1.34 +
    1.35 +var tests = [
    1.36 +  function() {
    1.37 +    SpecialPowers.pushPrefEnv({"set": [["media.useAudioChannelService", true]]}, runTest);
    1.38 +  },
    1.39 +
    1.40 +  function() {
    1.41 +    observerService.addObserver(observer, "media-playback", false);
    1.42 +    ok(true, "Observer set");
    1.43 +    runTest();
    1.44 +  },
    1.45 +
    1.46 +  function() {
    1.47 +    expectedNotification = 'active';
    1.48 +    audio.play();
    1.49 +  },
    1.50 +
    1.51 +  function() {
    1.52 +    expectedNotification = 'inactive';
    1.53 +    audio.pause();
    1.54 +  },
    1.55 +
    1.56 +  function() {
    1.57 +    observerService.removeObserver(observer, "media-playback");
    1.58 +    ok(true, "Observer removed");
    1.59 +    runTest();
    1.60 +  }
    1.61 +];
    1.62 +
    1.63 +function runTest() {
    1.64 +  if (!tests.length) {
    1.65 +    SimpleTest.finish();
    1.66 +    return;
    1.67 +  }
    1.68 +
    1.69 +  var test = tests.shift();
    1.70 +  test();
    1.71 +}
    1.72 +
    1.73 +runTest();
    1.74 +
    1.75 +</script>
    1.76 +</body>
    1.77 +</html>
    1.78 +

mercurial