|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for mozaudiochannel</title> |
|
5 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
8 </head> |
|
9 <body> |
|
10 <p id="display"></p> |
|
11 <pre id="test"> |
|
12 <script type="application/javascript"> |
|
13 |
|
14 function test_basic() { |
|
15 var ac = new AudioContext(); |
|
16 ok(ac, "AudioContext created"); |
|
17 |
|
18 // Default |
|
19 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
20 |
|
21 // random wrong channel |
|
22 ac.mozAudioChannelType = "foo"; |
|
23 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
24 |
|
25 // Unpermitted channels |
|
26 ac.mozAudioChannelType = "content"; |
|
27 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
28 |
|
29 ac.mozAudioChannelType = "notification"; |
|
30 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
31 |
|
32 ac.mozAudioChannelType = "alarm"; |
|
33 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
34 |
|
35 ac.mozAudioChannelType = "telephony"; |
|
36 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
37 |
|
38 ac.mozAudioChannelType = "ringer"; |
|
39 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
40 |
|
41 ac.mozAudioChannelType = "publicnotification"; |
|
42 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
43 |
|
44 runTest(); |
|
45 } |
|
46 |
|
47 function test_permission(aChannel) { |
|
48 var ac = new AudioContext(); |
|
49 ok(ac, "AudioContext created"); |
|
50 |
|
51 is(ac.mozAudioChannelType, "normal", "Default ac channel == 'normal'"); |
|
52 |
|
53 SpecialPowers.pushPermissions( |
|
54 [{ "type": "audio-channel-" + aChannel, "allow": true, "context": document }], |
|
55 function() { |
|
56 ac.mozAudioChannelType = aChannel; |
|
57 is(ac.mozAudioChannelType, aChannel, "Default ac channel == '" + aChannel + "'"); |
|
58 runTest(); |
|
59 } |
|
60 ); |
|
61 } |
|
62 |
|
63 function test_preferences(aChannel) { |
|
64 SpecialPowers.pushPrefEnv({"set": [["media.defaultAudioChannel", aChannel ]]}, |
|
65 function() { |
|
66 SpecialPowers.pushPermissions( |
|
67 [{ "type": "audio-channel-" + aChannel, "allow": false, "context": document }], |
|
68 function() { |
|
69 var ac = new AudioContext(aChannel); |
|
70 ok(ac, "AudioContext created"); |
|
71 is(ac.mozAudioChannelType, aChannel, "Default ac channel == '" + aChannel + "'"); |
|
72 runTest(); |
|
73 } |
|
74 ); |
|
75 } |
|
76 ); |
|
77 } |
|
78 |
|
79 function test_wrong_preferences() { |
|
80 SpecialPowers.pushPrefEnv({"set": [["media.defaultAudioChannel", 'foobar' ]]}, |
|
81 function() { |
|
82 var ac = new AudioContext(); |
|
83 ok(ac, "AudioContext created"); |
|
84 is(ac.mozAudioChannelType, 'normal', "Default ac channel == 'normal'"); |
|
85 runTest(); |
|
86 } |
|
87 ); |
|
88 } |
|
89 |
|
90 var tests = [ |
|
91 test_basic, |
|
92 |
|
93 function() { test_permission("content"); }, |
|
94 function() { test_permission("notification"); }, |
|
95 function() { test_permission("alarm"); }, |
|
96 function() { test_permission("telephony"); }, |
|
97 function() { test_permission("ringer"); }, |
|
98 function() { test_permission("publicnotification"); }, |
|
99 |
|
100 function() { test_preferences("content"); }, |
|
101 function() { test_preferences("notification"); }, |
|
102 function() { test_preferences("alarm"); }, |
|
103 function() { test_preferences("telephony"); }, |
|
104 function() { test_preferences("ringer"); }, |
|
105 function() { test_preferences("publicnotification"); }, |
|
106 |
|
107 test_wrong_preferences, |
|
108 ]; |
|
109 |
|
110 function runTest() { |
|
111 if (!tests.length) { |
|
112 SimpleTest.finish(); |
|
113 return; |
|
114 } |
|
115 |
|
116 var test = tests.shift(); |
|
117 test(); |
|
118 } |
|
119 |
|
120 SpecialPowers.pushPrefEnv({"set": [["media.useAudioChannelService", true ]]}, runTest); |
|
121 SimpleTest.waitForExplicitFinish(); |
|
122 |
|
123 </script> |
|
124 </pre> |
|
125 </body> |
|
126 </html> |