summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_audioNotificationSilent_audioFile.html
blob: 0b3b89580101f35ed9d37df81dcd950c2e67b90d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE HTML>
<html>
<head>
  <title>Audio-playback should be inactive when input file is silent</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7">

SimpleTest.waitForExplicitFinish();

var generator = runTest();
var expectedPlaybackActive = null;

var audio = new Audio();
audio.src = "audioEndedDuringPlaying.webm";

var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
                                   .getService(SpecialPowers.Ci.nsIObserverService);

var observer = {
  observe: function(subject, topic, data) {
    is(topic, "audio-playback", "audio-playback received");
    is(data, expectedPlaybackActive, "Corrrect audible state");
    continueTest();
  }
};

function continueTest() {
  try {
    generator.next();
  } catch (e if e instanceof StopIteration) {
    error("Stop test because of exception!");
  }
}

function audioPlayingStart() {
  observerService.addObserver(observer, "audio-playback", false);
  ok(true, "Observer set");

  expectedPlaybackActive = 'active';

  info("Audio playing start");
  audio.play();
}

function audioBecomeSilentDuringPlaying() {
  info("Audio would become silent during playing");

  expectedPlaybackActive = 'inactive-nonaudible';
}

function finish() {
  observerService.removeObserver(observer, "audio-playback");
  ok(true, "Observer removed");

  SimpleTest.finish();
}

function runTest() {
  yield audioPlayingStart();

  yield audioBecomeSilentDuringPlaying();

  yield finish();
}

continueTest();

</script>
</body>
</html>