summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_audioWindowUtils.html
blob: a6067cfd6b7a6a759580d3c5cbd85f7b6ad74822 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for audio controller in windows</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<iframe src="about:blank" id="iframe"></iframe>
<script type="application/javascript">

function runTest() {
  var utils = SpecialPowers.wrap(window).
        QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
        getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
  ok(utils, "nsIDOMWindowUtils");

  is(utils.audioMuted, false, "By default utils.audioMuted is false");
  utils.audioMuted = true;
  is(utils.audioMuted, true, "utils.audioMuted is true");
  utils.audioMuted = false;
  is(utils.audioMuted, false, "utils.audioMuted is true");

  is(utils.audioVolume, 1.0, "By default utils.audioVolume is 1.0");
  utils.audioVolume = 0.4;
  is(utils.audioVolume.toFixed(2), "0.40", "utils.audioVolume is ok");
  utils.audioMuted = true;
  is(utils.audioMuted, true, "utils.audioMuted is true");
  is(utils.audioVolume.toFixed(2), "0.40", "utils.audioVolume is ok");
  utils.audioMuted = false;

  utils.audioVolume = 2.0;
  is(utils.audioVolume, 2.0, "utils.audioVolume is ok");

  try {
    utils.audioVolume = -42;
    ok(false, "This should throw");
  } catch(e) {
    ok(true, "This should throw");
  }

  utils.audioVolume = 0;
  is(utils.audioVolume, 0.0, "utils.audioVolume is ok");
  utils.audioVolume = 1.0;
  is(utils.audioVolume, 1.0, "utils.audioVolume is ok");

  var iframe = document.getElementById("iframe");
  ok(iframe, "IFrame exists");

  utils = SpecialPowers.wrap(iframe.contentWindow).
        QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
        getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
  ok(utils, "nsIDOMWindowUtils");

  is(utils.audioMuted, false, "By default utils.audioMuted is false");
  utils.audioMuted = true;
  is(utils.audioMuted, true, "utils.audioMuted is true");
  utils.audioMuted = false;
  is(utils.audioMuted, false, "utils.audioMuted is true");

  is(utils.audioVolume, 1.0, "By default utils.audioVolume is 1.0");
  utils.audioVolume = 0.4;
  is(utils.audioVolume.toFixed(2), "0.40", "utils.audioVolume is ok");
  utils.audioMuted = true;
  is(utils.audioMuted, true, "utils.audioMuted is true");
  is(utils.audioVolume.toFixed(2), "0.40", "utils.audioVolume is ok");
  utils.audioMuted = false;

  utils.audioVolume = 2.0;
  is(utils.audioVolume, 2.0, "utils.audioVolume is ok");

  try {
    utils.audioVolume = -42;
    ok(false, "This should throw");
  } catch(e) {
    ok(true, "This should throw");
  }

  utils.audioVolume = 0;
  is(utils.audioVolume, 0.0, "utils.audioVolume is ok");
  utils.audioVolume = 0.6;
  is(utils.audioVolume.toFixed(2), "0.60", "utils.audioVolume is ok");
  utils.audioMuted = true;

  // Navigate the iframe to another URL, and verify that the volume and muted
  // information is preserved.
  iframe.onload = function() {
    utils = SpecialPowers.wrap(iframe.contentWindow).
          QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor).
          getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
    ok(utils, "nsIDOMWindowUtils");

    ok(utils.audioMuted, "Audio should still be muted");
    utils.audioMuted = false;
    ok(utils.audioVolume.toFixed(2), "0.60", "Volume should be preserved");

    SimpleTest.finish();
  };
  iframe.src = "data:text/html,page";
}

onload = runTest;
SimpleTest.waitForExplicitFinish();

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