Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="utf-8"> |
michael@0 | 5 | <title>Test audio-channel-changed & visible-audio-channel-changed mozChromeEvent</title> |
michael@0 | 6 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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 | <div id="content"></div> |
michael@0 | 11 | <script type="application/javascript;version=1.7"> |
michael@0 | 12 | var expectedAudioTypes; |
michael@0 | 13 | var expectedVisibleAudioTypes; |
michael@0 | 14 | var expectedVisibleAudioType; |
michael@0 | 15 | var index; |
michael@0 | 16 | var visibleIndex; |
michael@0 | 17 | var iframe1; |
michael@0 | 18 | var normalAudio; |
michael@0 | 19 | |
michael@0 | 20 | function playWithAudioType(audio, type) { |
michael@0 | 21 | audio.mozAudioChannelType = type; |
michael@0 | 22 | audio.src = "test.ogg"; |
michael@0 | 23 | audio.loop = true; |
michael@0 | 24 | |
michael@0 | 25 | audio.play(); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function fgBgTestListener(message) { |
michael@0 | 29 | var type = message.type; |
michael@0 | 30 | var channel = message.channel; |
michael@0 | 31 | |
michael@0 | 32 | if (type == 'audio-channel-changed') { |
michael@0 | 33 | is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]); |
michael@0 | 34 | index++; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | if (type == 'visible-audio-channel-changed') { |
michael@0 | 38 | is(channel, expectedVisibleAudioType, channel + " is received and expected " + expectedVisibleAudioType); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | // All audio types are playing now so ask to pause them. |
michael@0 | 42 | // This call will stop audio from highest to telephony. |
michael@0 | 43 | if ('cmd-pause' == expectedAudioTypes[index]) { |
michael@0 | 44 | iframe1.src = 'file_audio.html#pauseAudio'; |
michael@0 | 45 | index++; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | // According to there is a 1.5 second delay of releasing telephony, |
michael@0 | 49 | // we need to wait for it then continue to pause others. |
michael@0 | 50 | if ('cmd-secondPause' == expectedAudioTypes[index]) { |
michael@0 | 51 | iframe1.src = 'file_audio.html#pauseAudioFollowing'; |
michael@0 | 52 | index++; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | if (index == expectedAudioTypes.length) { |
michael@0 | 56 | document.body.removeChild(iframe1); |
michael@0 | 57 | script.removeMessageListener('chrome-event', fgBgTestListener); |
michael@0 | 58 | normalAudio.pause(); |
michael@0 | 59 | SimpleTest.finish(); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // Channel of visible-audio-channel-changed event should be always normal. |
michael@0 | 64 | // Audios in background should not effect visible-audio-channel-changed. |
michael@0 | 65 | function runFgBgTest() { |
michael@0 | 66 | expectedAudioTypes = ["normal", "content", "notification", |
michael@0 | 67 | "alarm", "telephony", "ringer", "publicnotification", "cmd-pause", |
michael@0 | 68 | "ringer", "telephony", "alarm", "cmd-secondPause", "notification", |
michael@0 | 69 | "content", "normal"]; |
michael@0 | 70 | expectedVisibleAudioType = "normal"; |
michael@0 | 71 | index = 0; |
michael@0 | 72 | |
michael@0 | 73 | script.addMessageListener('chrome-event', fgBgTestListener); |
michael@0 | 74 | |
michael@0 | 75 | // To play a audio with normal channel in the foreground. |
michael@0 | 76 | normalAudio = new Audio(); |
michael@0 | 77 | playWithAudioType(normalAudio, 'normal'); |
michael@0 | 78 | |
michael@0 | 79 | iframe1.src = 'file_audio.html#bg'; |
michael@0 | 80 | document.body.appendChild(iframe1); |
michael@0 | 81 | iframe1.setVisible(false); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function bgTestListener(message) { |
michael@0 | 85 | var type = message.type; |
michael@0 | 86 | var channel = message.channel; |
michael@0 | 87 | |
michael@0 | 88 | if (type == 'audio-channel-changed') { |
michael@0 | 89 | is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]); |
michael@0 | 90 | index++; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | if (type == 'visible-audio-channel-changed') { |
michael@0 | 94 | is(channel, expectedVisibleAudioType, channel + " is received and expected " + expectedVisibleAudioType); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | // All audio types are playing now so ask to pause them. |
michael@0 | 98 | if ('cmd-pause' == expectedAudioTypes[index]) { |
michael@0 | 99 | iframe1.src = 'file_audio.html#pauseAudio'; |
michael@0 | 100 | index++; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | if ('cmd-secondPause' == expectedAudioTypes[index]) { |
michael@0 | 104 | iframe1.src = 'file_audio.html#pauseAudioFollowing'; |
michael@0 | 105 | index++; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | if (index == expectedAudioTypes.length) { |
michael@0 | 109 | document.body.removeChild(iframe1); |
michael@0 | 110 | script.removeMessageListener('chrome-event', bgTestListener); |
michael@0 | 111 | runFgBgTest(); |
michael@0 | 112 | } |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | // 1. Channel of visible-audio-channel-changed event should be always none. |
michael@0 | 116 | // 2. normal is not allowed to be played in the background. |
michael@0 | 117 | function runBgTest() { |
michael@0 | 118 | expectedAudioTypes = ["content", "notification", |
michael@0 | 119 | "alarm", "telephony", "ringer", "publicnotification", "cmd-pause", |
michael@0 | 120 | "ringer", "telephony", "alarm", "cmd-secondPause", "notification", |
michael@0 | 121 | "content", "none"]; |
michael@0 | 122 | expectedVisibleAudioType = "none"; |
michael@0 | 123 | index = 0; |
michael@0 | 124 | |
michael@0 | 125 | script.addMessageListener('chrome-event', bgTestListener); |
michael@0 | 126 | |
michael@0 | 127 | iframe1.src = 'file_audio.html#bg'; |
michael@0 | 128 | document.body.appendChild(iframe1); |
michael@0 | 129 | iframe1.setVisible(false); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | function fgTestListener(message) { |
michael@0 | 133 | var type = message.type; |
michael@0 | 134 | var channel = message.channel; |
michael@0 | 135 | |
michael@0 | 136 | if (type == 'audio-channel-changed') { |
michael@0 | 137 | is(channel, expectedAudioTypes[index], channel + " is received and expected " + expectedAudioTypes[index]); |
michael@0 | 138 | index++; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | if (type == 'visible-audio-channel-changed') { |
michael@0 | 142 | is(channel, expectedAudioTypes[visibleIndex], channel + " is received and expected " + expectedAudioTypes[visibleIndex]); |
michael@0 | 143 | visibleIndex++; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | // All audio types are playing now so ask to pause them. |
michael@0 | 147 | if ('cmd-pause' == expectedAudioTypes[visibleIndex] && |
michael@0 | 148 | 'cmd-pause' == expectedAudioTypes[index]) { |
michael@0 | 149 | iframe1.src = 'file_audio.html#pauseAudio'; |
michael@0 | 150 | visibleIndex++; |
michael@0 | 151 | index++; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | if ('cmd-secondPause' == expectedAudioTypes[visibleIndex] && |
michael@0 | 155 | 'cmd-secondPause' == expectedAudioTypes[index]) { |
michael@0 | 156 | iframe1.src = 'file_audio.html#pauseAudioFollowing'; |
michael@0 | 157 | visibleIndex++; |
michael@0 | 158 | index++; |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | if (index == expectedAudioTypes.length && visibleIndex == expectedAudioTypes.length) { |
michael@0 | 162 | document.body.removeChild(iframe1); |
michael@0 | 163 | script.removeMessageListener('chrome-event', fgTestListener); |
michael@0 | 164 | runBgTest(); |
michael@0 | 165 | } |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | // The foreground audio will effect both of audio-channel-changed and |
michael@0 | 169 | // visible-audio-channel-changed. |
michael@0 | 170 | function runFgTest() { |
michael@0 | 171 | expectedAudioTypes = ["normal", "content", "notification", |
michael@0 | 172 | "alarm", "telephony", "ringer", "publicnotification", |
michael@0 | 173 | "cmd-pause", "ringer", "telephony", "alarm", |
michael@0 | 174 | "cmd-secondPause", "notification", "content", |
michael@0 | 175 | "normal", "none"]; |
michael@0 | 176 | |
michael@0 | 177 | index = 0; |
michael@0 | 178 | visibleIndex = 0; |
michael@0 | 179 | |
michael@0 | 180 | script.addMessageListener('chrome-event', fgTestListener); |
michael@0 | 181 | |
michael@0 | 182 | iframe1 = document.createElement('iframe'); |
michael@0 | 183 | iframe1.setAttribute('mozbrowser', true); |
michael@0 | 184 | iframe1.src = 'file_audio.html#fg'; |
michael@0 | 185 | document.body.appendChild(iframe1); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | var url = SimpleTest.getTestFileURL("AudioChannelChromeScript.js") |
michael@0 | 189 | var script = SpecialPowers.loadChromeScript(url); |
michael@0 | 190 | script.sendAsyncMessage("init-chrome-event", { |
michael@0 | 191 | type: 'audio-channel-changed' |
michael@0 | 192 | }); |
michael@0 | 193 | script.sendAsyncMessage("init-chrome-event", { |
michael@0 | 194 | type: 'visible-audio-channel-changed' |
michael@0 | 195 | }); |
michael@0 | 196 | |
michael@0 | 197 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 198 | |
michael@0 | 199 | SpecialPowers.pushPermissions( |
michael@0 | 200 | [{ "type": "browser", "allow": 1, "context": document }, |
michael@0 | 201 | { "type": "embed-apps", "allow": 1, "context": document }, |
michael@0 | 202 | { "type": "webapps-manage", "allow": 1, "context": document }], function() { |
michael@0 | 203 | SpecialPowers.pushPrefEnv({"set": [["dom.ipc.browser_frames.oop_by_default", true], |
michael@0 | 204 | ["media.useAudioChannelService", true], |
michael@0 | 205 | ["dom.mozBrowserFramesEnabled", true]]}, runFgTest); |
michael@0 | 206 | }); |
michael@0 | 207 | </script> |
michael@0 | 208 | </body> |
michael@0 | 209 | </html> |