summaryrefslogtreecommitdiffstats
path: root/dom/speakermanager/tests/test_speakermanager.html
blob: 509df5e84a0cdb4254564c475da8ba5917e6aaa9 (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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test MozSpeakerManager API</title>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
  <script type="application/javascript">

  "use strict";

  function testObject() {
    var mgr = new MozSpeakerManager();
    var spkforced = false;
    mgr.onspeakerforcedchange = function() {
      if (spkforced) {
        is(mgr.speakerforced, true, 'speaker should be true');
        spkforced = false;
        mgr.forcespeaker = false;
      } else {
        is(mgr.speakerforced, false, 'speaker should be false');
        SimpleTest.finish();
      }
    }
    spkforced = true;
    mgr.forcespeaker = true;
  }

  function startTests() {
    // Currently applicable only on FxOS
    if (navigator.userAgent.indexOf("Mobile") != -1 &&
        navigator.appVersion.indexOf("Android") == -1) {
      testObject();
    } else {
      ok(true, "MozSpeakerManager on Firefox OS only.");
      SimpleTest.finish();
    }
  }

  SimpleTest.waitForExplicitFinish();
  SpecialPowers.pushPermissions(
    [{ "type": "speaker-control", "allow": 1, "context": document }],
    startTests);

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