|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for audio controller in windows</title> |
|
5 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
7 </head> |
|
8 <body> |
|
9 <pre id="test"> |
|
10 </pre> |
|
11 |
|
12 <script type="application/javascript"> |
|
13 |
|
14 SimpleTest.waitForExplicitFinish(); |
|
15 |
|
16 var expectedNotification = null; |
|
17 |
|
18 var observer = { |
|
19 observe: function(subject, topic, data) { |
|
20 is(topic, "media-playback", "media-playback received"); |
|
21 is(data, expectedNotification, "This is the right notification"); |
|
22 runTest(); |
|
23 } |
|
24 }; |
|
25 |
|
26 var observerService = SpecialPowers.Cc["@mozilla.org/observer-service;1"] |
|
27 .getService(SpecialPowers.Ci.nsIObserverService); |
|
28 |
|
29 var audio = new Audio(); |
|
30 audio.src = "audio.ogg"; |
|
31 |
|
32 var tests = [ |
|
33 function() { |
|
34 SpecialPowers.pushPrefEnv({"set": [["media.useAudioChannelService", true]]}, runTest); |
|
35 }, |
|
36 |
|
37 function() { |
|
38 observerService.addObserver(observer, "media-playback", false); |
|
39 ok(true, "Observer set"); |
|
40 runTest(); |
|
41 }, |
|
42 |
|
43 function() { |
|
44 expectedNotification = 'active'; |
|
45 audio.play(); |
|
46 }, |
|
47 |
|
48 function() { |
|
49 expectedNotification = 'inactive'; |
|
50 audio.pause(); |
|
51 }, |
|
52 |
|
53 function() { |
|
54 observerService.removeObserver(observer, "media-playback"); |
|
55 ok(true, "Observer removed"); |
|
56 runTest(); |
|
57 } |
|
58 ]; |
|
59 |
|
60 function runTest() { |
|
61 if (!tests.length) { |
|
62 SimpleTest.finish(); |
|
63 return; |
|
64 } |
|
65 |
|
66 var test = tests.shift(); |
|
67 test(); |
|
68 } |
|
69 |
|
70 runTest(); |
|
71 |
|
72 </script> |
|
73 </body> |
|
74 </html> |
|
75 |