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