|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 #ifdef XP_WIN |
|
5 #include <windows.h> |
|
6 #else |
|
7 #include <unistd.h> |
|
8 #endif |
|
9 |
|
10 #include "TestHarness.h" |
|
11 |
|
12 #include "nsWeakReference.h" |
|
13 #include "AudioChannelService.h" |
|
14 #include "AudioChannelAgent.h" |
|
15 |
|
16 #define TEST_ENSURE_BASE(_test, _msg) \ |
|
17 PR_BEGIN_MACRO \ |
|
18 if (!(_test)) { \ |
|
19 fail(_msg); \ |
|
20 return NS_ERROR_FAILURE; \ |
|
21 } else { \ |
|
22 passed(_msg); \ |
|
23 } \ |
|
24 PR_END_MACRO |
|
25 |
|
26 using namespace mozilla::dom; |
|
27 |
|
28 class Agent : public nsIAudioChannelAgentCallback, |
|
29 public nsSupportsWeakReference |
|
30 { |
|
31 public: |
|
32 NS_DECL_ISUPPORTS |
|
33 |
|
34 Agent(AudioChannel aChannel) |
|
35 : mChannel(aChannel) |
|
36 , mWaitCallback(false) |
|
37 , mRegistered(false) |
|
38 , mCanPlay(AUDIO_CHANNEL_STATE_MUTED) |
|
39 { |
|
40 mAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1"); |
|
41 } |
|
42 |
|
43 virtual ~Agent() |
|
44 { |
|
45 if (mRegistered) { |
|
46 StopPlaying(); |
|
47 } |
|
48 } |
|
49 |
|
50 nsresult Init(bool video=false) |
|
51 { |
|
52 nsresult rv = NS_OK; |
|
53 if (video) { |
|
54 rv = mAgent->InitWithVideo(nullptr, static_cast<int32_t>(mChannel), |
|
55 this, true); |
|
56 } |
|
57 else { |
|
58 rv = mAgent->InitWithWeakCallback(nullptr, static_cast<int32_t>(mChannel), |
|
59 this); |
|
60 } |
|
61 NS_ENSURE_SUCCESS(rv, rv); |
|
62 |
|
63 return mAgent->SetVisibilityState(false); |
|
64 } |
|
65 |
|
66 nsresult StartPlaying(AudioChannelState *_ret) |
|
67 { |
|
68 if (mRegistered) { |
|
69 StopPlaying(); |
|
70 } |
|
71 |
|
72 nsresult rv = mAgent->StartPlaying((int32_t *)_ret); |
|
73 mRegistered = true; |
|
74 return rv; |
|
75 } |
|
76 |
|
77 nsresult StopPlaying() |
|
78 { |
|
79 mRegistered = false; |
|
80 int loop = 0; |
|
81 while (mWaitCallback) { |
|
82 #ifdef XP_WIN |
|
83 Sleep(1000); |
|
84 #else |
|
85 sleep(1); |
|
86 #endif |
|
87 if (loop++ == 5) { |
|
88 TEST_ENSURE_BASE(false, "StopPlaying timeout"); |
|
89 } |
|
90 } |
|
91 return mAgent->StopPlaying(); |
|
92 } |
|
93 |
|
94 nsresult SetVisibilityState(bool visible) |
|
95 { |
|
96 if (mRegistered) { |
|
97 mWaitCallback = true; |
|
98 } |
|
99 return mAgent->SetVisibilityState(visible); |
|
100 } |
|
101 |
|
102 NS_IMETHODIMP CanPlayChanged(int32_t canPlay) |
|
103 { |
|
104 mCanPlay = static_cast<AudioChannelState>(canPlay); |
|
105 mWaitCallback = false; |
|
106 return NS_OK; |
|
107 } |
|
108 |
|
109 NS_IMETHODIMP WindowVolumeChanged() |
|
110 { |
|
111 return NS_OK; |
|
112 } |
|
113 |
|
114 nsresult GetCanPlay(AudioChannelState *_ret) |
|
115 { |
|
116 int loop = 0; |
|
117 while (mWaitCallback) { |
|
118 #ifdef XP_WIN |
|
119 Sleep(1000); |
|
120 #else |
|
121 sleep(1); |
|
122 #endif |
|
123 if (loop++ == 5) { |
|
124 TEST_ENSURE_BASE(false, "GetCanPlay timeout"); |
|
125 } |
|
126 } |
|
127 *_ret = mCanPlay; |
|
128 return NS_OK; |
|
129 } |
|
130 |
|
131 nsCOMPtr<nsIAudioChannelAgent> mAgent; |
|
132 AudioChannel mChannel; |
|
133 bool mWaitCallback; |
|
134 bool mRegistered; |
|
135 AudioChannelState mCanPlay; |
|
136 }; |
|
137 |
|
138 NS_IMPL_ISUPPORTS(Agent, nsIAudioChannelAgentCallback, |
|
139 nsISupportsWeakReference) |
|
140 |
|
141 nsresult |
|
142 TestDoubleStartPlaying() |
|
143 { |
|
144 nsRefPtr<Agent> agent = new Agent(AudioChannel::Normal); |
|
145 |
|
146 nsresult rv = agent->Init(); |
|
147 NS_ENSURE_SUCCESS(rv, rv); |
|
148 |
|
149 AudioChannelState playable; |
|
150 rv = agent->mAgent->StartPlaying((int32_t *)&playable); |
|
151 NS_ENSURE_SUCCESS(rv, rv); |
|
152 |
|
153 rv = agent->mAgent->StartPlaying((int32_t *)&playable); |
|
154 TEST_ENSURE_BASE(NS_FAILED(rv), |
|
155 "Test0: StartPlaying calling twice must return error"); |
|
156 |
|
157 return NS_OK; |
|
158 } |
|
159 |
|
160 nsresult |
|
161 TestOneNormalChannel() |
|
162 { |
|
163 nsRefPtr<Agent> agent = new Agent(AudioChannel::Normal); |
|
164 nsresult rv = agent->Init(); |
|
165 NS_ENSURE_SUCCESS(rv, rv); |
|
166 |
|
167 AudioChannelState playable; |
|
168 rv = agent->StartPlaying(&playable); |
|
169 NS_ENSURE_SUCCESS(rv, rv); |
|
170 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
171 "Test1: A normal channel unvisible agent must be muted"); |
|
172 |
|
173 rv = agent->SetVisibilityState(true); |
|
174 NS_ENSURE_SUCCESS(rv, rv); |
|
175 |
|
176 rv = agent->GetCanPlay(&playable); |
|
177 NS_ENSURE_SUCCESS(rv, rv); |
|
178 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
179 "Test1: A normal channel visible agent must be playable"); |
|
180 |
|
181 return rv; |
|
182 } |
|
183 |
|
184 nsresult |
|
185 TestTwoNormalChannels() |
|
186 { |
|
187 nsRefPtr<Agent> agent1 = new Agent(AudioChannel::Normal); |
|
188 nsresult rv = agent1->Init(); |
|
189 NS_ENSURE_SUCCESS(rv, rv); |
|
190 |
|
191 nsRefPtr<Agent> agent2 = new Agent(AudioChannel::Normal); |
|
192 rv = agent2->Init(); |
|
193 NS_ENSURE_SUCCESS(rv, rv); |
|
194 |
|
195 AudioChannelState playable; |
|
196 rv = agent1->StartPlaying(&playable); |
|
197 NS_ENSURE_SUCCESS(rv, rv); |
|
198 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
199 "Test2: A normal channel unvisible agent1 must be muted"); |
|
200 |
|
201 rv = agent2->StartPlaying(&playable); |
|
202 NS_ENSURE_SUCCESS(rv, rv); |
|
203 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
204 "Test2: A normal channel unvisible agent2 must be muted"); |
|
205 |
|
206 rv = agent1->SetVisibilityState(true); |
|
207 NS_ENSURE_SUCCESS(rv, rv); |
|
208 |
|
209 rv = agent2->SetVisibilityState(true); |
|
210 NS_ENSURE_SUCCESS(rv, rv); |
|
211 |
|
212 rv = agent1->GetCanPlay(&playable); |
|
213 NS_ENSURE_SUCCESS(rv, rv); |
|
214 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
215 "Test2: A normal channel visible agent1 must be playable"); |
|
216 |
|
217 rv = agent2->GetCanPlay(&playable); |
|
218 NS_ENSURE_SUCCESS(rv, rv); |
|
219 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
220 "Test2: A normal channel visible agent2 must be playable"); |
|
221 |
|
222 return rv; |
|
223 } |
|
224 |
|
225 nsresult |
|
226 TestContentChannels() |
|
227 { |
|
228 nsRefPtr<Agent> agent1 = new Agent(AudioChannel::Content); |
|
229 nsresult rv = agent1->Init(); |
|
230 NS_ENSURE_SUCCESS(rv, rv); |
|
231 |
|
232 nsRefPtr<Agent> agent2 = new Agent(AudioChannel::Content); |
|
233 rv = agent2->Init(); |
|
234 NS_ENSURE_SUCCESS(rv, rv); |
|
235 |
|
236 // All content channels in the foreground can be allowed to play |
|
237 rv = agent1->SetVisibilityState(true); |
|
238 NS_ENSURE_SUCCESS(rv, rv); |
|
239 |
|
240 rv = agent2->SetVisibilityState(true); |
|
241 NS_ENSURE_SUCCESS(rv, rv); |
|
242 |
|
243 AudioChannelState playable; |
|
244 rv = agent1->StartPlaying(&playable); |
|
245 NS_ENSURE_SUCCESS(rv, rv); |
|
246 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
247 "Test3: A content channel visible agent1 must be playable"); |
|
248 |
|
249 rv = agent2->StartPlaying(&playable); |
|
250 NS_ENSURE_SUCCESS(rv, rv); |
|
251 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
252 "Test3: A content channel visible agent2 must be playable"); |
|
253 |
|
254 // Test the transition state of one content channel tried to set non-visible |
|
255 // state first when app is going to background. |
|
256 rv = agent1->SetVisibilityState(false); |
|
257 NS_ENSURE_SUCCESS(rv, rv); |
|
258 |
|
259 rv = agent1->GetCanPlay(&playable); |
|
260 NS_ENSURE_SUCCESS(rv, rv); |
|
261 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
262 "Test3: A content channel unvisible agent1 must be playable from " |
|
263 "foreground to background"); |
|
264 |
|
265 // Test all content channels set non-visible already |
|
266 rv = agent2->SetVisibilityState(false); |
|
267 NS_ENSURE_SUCCESS(rv, rv); |
|
268 |
|
269 rv = agent2->GetCanPlay(&playable); |
|
270 NS_ENSURE_SUCCESS(rv, rv); |
|
271 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
272 "Test3: A content channel unvisible agent2 must be playable from " |
|
273 "foreground to background"); |
|
274 |
|
275 // Clear the content channels & mActiveContentChildIDs in AudioChannelService. |
|
276 // If agent stop playable in the background, we will reserve it's childID in |
|
277 // mActiveContentChildIDs, then it can allow to play next song. So we set agents |
|
278 // to foreground first then stopping to play |
|
279 rv = agent1->SetVisibilityState(true); |
|
280 NS_ENSURE_SUCCESS(rv, rv); |
|
281 rv = agent2->SetVisibilityState(true); |
|
282 NS_ENSURE_SUCCESS(rv, rv); |
|
283 rv = agent1->StopPlaying(); |
|
284 NS_ENSURE_SUCCESS(rv, rv); |
|
285 rv = agent2->StopPlaying(); |
|
286 NS_ENSURE_SUCCESS(rv, rv); |
|
287 |
|
288 // Test that content channels can be allow to play when they starts from |
|
289 // the background state |
|
290 rv = agent1->SetVisibilityState(false); |
|
291 NS_ENSURE_SUCCESS(rv, rv); |
|
292 rv = agent2->SetVisibilityState(false); |
|
293 NS_ENSURE_SUCCESS(rv, rv); |
|
294 |
|
295 rv = agent1->StartPlaying(&playable); |
|
296 NS_ENSURE_SUCCESS(rv, rv); |
|
297 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
298 "Test3: A content channel unvisible agent1 must be playable " |
|
299 "from background state"); |
|
300 |
|
301 rv = agent2->StartPlaying(&playable); |
|
302 NS_ENSURE_SUCCESS(rv, rv); |
|
303 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
304 "Test3: A content channel unvisible agent2 must be playable " |
|
305 "from background state"); |
|
306 |
|
307 return rv; |
|
308 } |
|
309 |
|
310 nsresult |
|
311 TestFadedState() |
|
312 { |
|
313 nsRefPtr<Agent> normalAgent = new Agent(AudioChannel::Normal); |
|
314 nsresult rv = normalAgent->Init(); |
|
315 NS_ENSURE_SUCCESS(rv, rv); |
|
316 |
|
317 nsRefPtr<Agent> contentAgent = new Agent(AudioChannel::Content); |
|
318 rv = contentAgent->Init(); |
|
319 NS_ENSURE_SUCCESS(rv, rv); |
|
320 |
|
321 nsRefPtr<Agent> notificationAgent = new Agent(AudioChannel::Notification); |
|
322 rv = notificationAgent->Init(); |
|
323 NS_ENSURE_SUCCESS(rv, rv); |
|
324 |
|
325 rv = normalAgent->SetVisibilityState(true); |
|
326 NS_ENSURE_SUCCESS(rv, rv); |
|
327 |
|
328 rv = contentAgent->SetVisibilityState(true); |
|
329 NS_ENSURE_SUCCESS(rv, rv); |
|
330 |
|
331 rv = notificationAgent->SetVisibilityState(true); |
|
332 NS_ENSURE_SUCCESS(rv, rv); |
|
333 |
|
334 AudioChannelState playable; |
|
335 rv = normalAgent->StartPlaying(&playable); |
|
336 NS_ENSURE_SUCCESS(rv, rv); |
|
337 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
338 "Test4: A normal channel visible agent must be playable"); |
|
339 |
|
340 rv = contentAgent->StartPlaying(&playable); |
|
341 NS_ENSURE_SUCCESS(rv, rv); |
|
342 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
343 "Test4: A content channel visible agent must be playable"); |
|
344 |
|
345 rv = notificationAgent->StartPlaying(&playable); |
|
346 NS_ENSURE_SUCCESS(rv, rv); |
|
347 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
348 "Test4: A notification channel visible agent must be playable"); |
|
349 |
|
350 rv = contentAgent->GetCanPlay(&playable); |
|
351 NS_ENSURE_SUCCESS(rv, rv); |
|
352 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_FADED, |
|
353 "Test4: A content channel unvisible agent must be faded because of " |
|
354 "notification channel is playing"); |
|
355 |
|
356 rv = contentAgent->SetVisibilityState(false); |
|
357 NS_ENSURE_SUCCESS(rv, rv); |
|
358 |
|
359 rv = contentAgent->GetCanPlay(&playable); |
|
360 NS_ENSURE_SUCCESS(rv, rv); |
|
361 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_FADED, |
|
362 "Test4: A content channel unvisible agent must be faded because of " |
|
363 "notification channel is playing"); |
|
364 |
|
365 rv = notificationAgent->SetVisibilityState(false); |
|
366 NS_ENSURE_SUCCESS(rv, rv); |
|
367 |
|
368 rv = notificationAgent->GetCanPlay(&playable); |
|
369 NS_ENSURE_SUCCESS(rv, rv); |
|
370 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
371 "Test4: A notification channel unvisible agent must be playable from " |
|
372 "foreground to background"); |
|
373 |
|
374 rv = notificationAgent->StopPlaying(); |
|
375 NS_ENSURE_SUCCESS(rv, rv); |
|
376 |
|
377 rv = contentAgent->GetCanPlay(&playable); |
|
378 NS_ENSURE_SUCCESS(rv, rv); |
|
379 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
380 "Test4: A content channel unvisible agent must be playable " |
|
381 "because of notification channel is stopped"); |
|
382 |
|
383 rv = contentAgent->SetVisibilityState(true); |
|
384 NS_ENSURE_SUCCESS(rv, rv); |
|
385 |
|
386 return rv; |
|
387 } |
|
388 |
|
389 nsresult |
|
390 TestPriorities() |
|
391 { |
|
392 nsRefPtr<Agent> normalAgent = new Agent(AudioChannel::Normal); |
|
393 nsresult rv = normalAgent->Init(); |
|
394 NS_ENSURE_SUCCESS(rv, rv); |
|
395 |
|
396 nsRefPtr<Agent> contentAgent = new Agent(AudioChannel::Content); |
|
397 rv = contentAgent->Init(); |
|
398 NS_ENSURE_SUCCESS(rv, rv); |
|
399 |
|
400 nsRefPtr<Agent> notificationAgent = new Agent(AudioChannel::Notification); |
|
401 rv = notificationAgent->Init(); |
|
402 NS_ENSURE_SUCCESS(rv, rv); |
|
403 |
|
404 nsRefPtr<Agent> alarmAgent = new Agent(AudioChannel::Alarm); |
|
405 rv = alarmAgent->Init(); |
|
406 NS_ENSURE_SUCCESS(rv, rv); |
|
407 |
|
408 nsRefPtr<Agent> telephonyAgent = new Agent(AudioChannel::Telephony); |
|
409 rv = telephonyAgent->Init(); |
|
410 NS_ENSURE_SUCCESS(rv, rv); |
|
411 |
|
412 nsRefPtr<Agent> ringerAgent = new Agent(AudioChannel::Ringer); |
|
413 rv = ringerAgent->Init(); |
|
414 NS_ENSURE_SUCCESS(rv, rv); |
|
415 |
|
416 nsRefPtr<Agent> pNotificationAgent = |
|
417 new Agent(AudioChannel::Publicnotification); |
|
418 rv = pNotificationAgent->Init(); |
|
419 NS_ENSURE_SUCCESS(rv, rv); |
|
420 |
|
421 AudioChannelState playable; |
|
422 |
|
423 rv = normalAgent->StartPlaying(&playable); |
|
424 NS_ENSURE_SUCCESS(rv, rv); |
|
425 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
426 "Test5: A normal channel unvisible agent must be muted"); |
|
427 |
|
428 rv = contentAgent->StartPlaying(&playable); |
|
429 NS_ENSURE_SUCCESS(rv, rv); |
|
430 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
431 "Test5: A content channel unvisible agent must be playable while " |
|
432 "playing from background state"); |
|
433 |
|
434 rv = notificationAgent->StartPlaying(&playable); |
|
435 NS_ENSURE_SUCCESS(rv, rv); |
|
436 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
437 "Test5: A notification channel unvisible agent must be playable"); |
|
438 |
|
439 rv = alarmAgent->StartPlaying(&playable); |
|
440 NS_ENSURE_SUCCESS(rv, rv); |
|
441 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
442 "Test5: An alarm channel unvisible agent must be playable"); |
|
443 |
|
444 rv = notificationAgent->StartPlaying(&playable); |
|
445 NS_ENSURE_SUCCESS(rv, rv); |
|
446 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
447 "Test5: A notification channel unvisible agent must be muted when an " |
|
448 "alarm is playing"); |
|
449 |
|
450 rv = telephonyAgent->StartPlaying(&playable); |
|
451 NS_ENSURE_SUCCESS(rv, rv); |
|
452 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
453 "Test5: A telephony channel unvisible agent must be playable"); |
|
454 |
|
455 rv = alarmAgent->StartPlaying(&playable); |
|
456 NS_ENSURE_SUCCESS(rv, rv); |
|
457 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
458 "Test5: An alarm channel unvisible agent must be muted when a telephony " |
|
459 "is playing"); |
|
460 |
|
461 rv = ringerAgent->StartPlaying(&playable); |
|
462 NS_ENSURE_SUCCESS(rv, rv); |
|
463 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
464 "Test5: A ringer channel unvisible agent must be playable"); |
|
465 |
|
466 rv = telephonyAgent->StartPlaying(&playable); |
|
467 NS_ENSURE_SUCCESS(rv, rv); |
|
468 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
469 "Test5: A telephony channel unvisible agent must be muted when a ringer " |
|
470 "is playing"); |
|
471 |
|
472 rv = pNotificationAgent->StartPlaying(&playable); |
|
473 NS_ENSURE_SUCCESS(rv, rv); |
|
474 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
475 "Test5: A pNotification channel unvisible agent must be playable"); |
|
476 |
|
477 rv = ringerAgent->StartPlaying(&playable); |
|
478 NS_ENSURE_SUCCESS(rv, rv); |
|
479 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
480 "Test5: A ringer channel unvisible agent must be muted when a public " |
|
481 "notification is playing"); |
|
482 |
|
483 // Stop to play notification channel or normal/content will be faded. |
|
484 // Which already be tested on Test 4. |
|
485 rv = notificationAgent->StopPlaying(); |
|
486 NS_ENSURE_SUCCESS(rv, rv); |
|
487 |
|
488 // Settings visible the normal channel. |
|
489 rv = normalAgent->SetVisibilityState(true); |
|
490 NS_ENSURE_SUCCESS(rv, rv); |
|
491 |
|
492 rv = normalAgent->GetCanPlay(&playable); |
|
493 NS_ENSURE_SUCCESS(rv, rv); |
|
494 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
495 "Test5: A normal channel visible agent must be playable"); |
|
496 |
|
497 // Set the content channel as visible . |
|
498 rv = contentAgent->SetVisibilityState(true); |
|
499 NS_ENSURE_SUCCESS(rv, rv); |
|
500 |
|
501 // Content must be playable because visible. |
|
502 rv = contentAgent->GetCanPlay(&playable); |
|
503 NS_ENSURE_SUCCESS(rv, rv); |
|
504 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
505 "Test5: A content channel visible agent must be playable"); |
|
506 |
|
507 // Set the alarm channel as visible. |
|
508 rv = alarmAgent->SetVisibilityState(true); |
|
509 NS_ENSURE_SUCCESS(rv, rv); |
|
510 |
|
511 rv = alarmAgent->GetCanPlay(&playable); |
|
512 NS_ENSURE_SUCCESS(rv, rv); |
|
513 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
514 "Test5: An alarm channel visible agent must be playable"); |
|
515 |
|
516 // Set the telephony channel as visible. |
|
517 rv = telephonyAgent->SetVisibilityState(true); |
|
518 NS_ENSURE_SUCCESS(rv, rv); |
|
519 |
|
520 rv = telephonyAgent->GetCanPlay(&playable); |
|
521 NS_ENSURE_SUCCESS(rv, rv); |
|
522 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
523 "Test5: A telephony channel visible agent must be playable"); |
|
524 |
|
525 // Set the ringer channel as visible. |
|
526 rv = ringerAgent->SetVisibilityState(true); |
|
527 NS_ENSURE_SUCCESS(rv, rv); |
|
528 |
|
529 rv = ringerAgent->GetCanPlay(&playable); |
|
530 NS_ENSURE_SUCCESS(rv, rv); |
|
531 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
532 "Test5: A ringer channel visible agent must be playable"); |
|
533 |
|
534 // Set the public notification channel as visible. |
|
535 rv = pNotificationAgent->SetVisibilityState(true); |
|
536 NS_ENSURE_SUCCESS(rv, rv); |
|
537 |
|
538 rv = pNotificationAgent->GetCanPlay(&playable); |
|
539 NS_ENSURE_SUCCESS(rv, rv); |
|
540 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
541 "Test5: A pNotification channel visible agent must be playable"); |
|
542 |
|
543 return rv; |
|
544 } |
|
545 |
|
546 nsresult |
|
547 TestOneVideoNormalChannel() |
|
548 { |
|
549 nsRefPtr<Agent> agent1 = new Agent(AudioChannel::Normal); |
|
550 nsresult rv = agent1->Init(true); |
|
551 NS_ENSURE_SUCCESS(rv, rv); |
|
552 |
|
553 nsRefPtr<Agent> agent2 = new Agent(AudioChannel::Content); |
|
554 rv = agent2->Init(false); |
|
555 NS_ENSURE_SUCCESS(rv, rv); |
|
556 |
|
557 AudioChannelState playable; |
|
558 rv = agent1->StartPlaying(&playable); |
|
559 NS_ENSURE_SUCCESS(rv, rv); |
|
560 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
561 "Test6: A video normal channel invisible agent1 must be muted"); |
|
562 |
|
563 rv = agent2->StartPlaying(&playable); |
|
564 NS_ENSURE_SUCCESS(rv, rv); |
|
565 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
566 "Test6: A content channel invisible agent2 must be playable"); |
|
567 |
|
568 // one video normal channel in foreground and one content channel in background |
|
569 rv = agent1->SetVisibilityState(true); |
|
570 NS_ENSURE_SUCCESS(rv, rv); |
|
571 |
|
572 rv = agent1->GetCanPlay(&playable); |
|
573 NS_ENSURE_SUCCESS(rv, rv); |
|
574 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
575 "Test6: A video normal channel visible agent1 must be playable"); |
|
576 |
|
577 rv = agent2->GetCanPlay(&playable); |
|
578 NS_ENSURE_SUCCESS(rv, rv); |
|
579 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
580 "Test6: A content channel invisible agent2 must be muted"); |
|
581 |
|
582 // both one video normal channel and one content channel in foreground |
|
583 rv = agent2->SetVisibilityState(true); |
|
584 NS_ENSURE_SUCCESS(rv, rv); |
|
585 |
|
586 rv = agent1->GetCanPlay(&playable); |
|
587 NS_ENSURE_SUCCESS(rv, rv); |
|
588 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
589 "Test6: A video normal channel visible agent1 must be playable"); |
|
590 |
|
591 rv = agent2->GetCanPlay(&playable); |
|
592 NS_ENSURE_SUCCESS(rv, rv); |
|
593 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
594 "Test6: A content channel visible agent2 must be playable"); |
|
595 |
|
596 // one video normal channel in background and one content channel in foreground |
|
597 rv = agent1->SetVisibilityState(false); |
|
598 NS_ENSURE_SUCCESS(rv, rv); |
|
599 |
|
600 rv = agent1->GetCanPlay(&playable); |
|
601 NS_ENSURE_SUCCESS(rv, rv); |
|
602 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
603 "Test6: A video normal channel invisible agent1 must be muted"); |
|
604 |
|
605 rv = agent2->GetCanPlay(&playable); |
|
606 NS_ENSURE_SUCCESS(rv, rv); |
|
607 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
608 "Test6: A content channel visible agent2 must be playable"); |
|
609 |
|
610 // both one video normal channel and one content channel in background |
|
611 rv = agent2->SetVisibilityState(false); |
|
612 NS_ENSURE_SUCCESS(rv, rv); |
|
613 |
|
614 rv = agent1->GetCanPlay(&playable); |
|
615 NS_ENSURE_SUCCESS(rv, rv); |
|
616 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED, |
|
617 "Test6: A video normal channel invisible agent1 must be muted"); |
|
618 |
|
619 rv = agent2->GetCanPlay(&playable); |
|
620 NS_ENSURE_SUCCESS(rv, rv); |
|
621 TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL, |
|
622 "Test6: A content channel invisible agent2 must be playable"); |
|
623 |
|
624 return rv; |
|
625 } |
|
626 |
|
627 int main(int argc, char** argv) |
|
628 { |
|
629 ScopedXPCOM xpcom("AudioChannelService"); |
|
630 if (xpcom.failed()) { |
|
631 return 1; |
|
632 } |
|
633 |
|
634 if (NS_FAILED(TestDoubleStartPlaying())) { |
|
635 return 1; |
|
636 } |
|
637 |
|
638 if (NS_FAILED(TestOneNormalChannel())) { |
|
639 return 1; |
|
640 } |
|
641 |
|
642 if (NS_FAILED(TestTwoNormalChannels())) { |
|
643 return 1; |
|
644 } |
|
645 |
|
646 if (NS_FAILED(TestContentChannels())) { |
|
647 return 1; |
|
648 } |
|
649 |
|
650 if (NS_FAILED(TestFadedState())) { |
|
651 return 1; |
|
652 } |
|
653 |
|
654 // Channel type with AudioChannel::Telephony cannot be unregistered until the |
|
655 // main thread has chances to process 1500 millisecond timer. In order to |
|
656 // skip ambiguous return value of ChannelsActiveWithHigherPriorityThan(), new |
|
657 // test cases are added before any test case that registers the channel type |
|
658 // with AudioChannel::Telephony channel. |
|
659 if (NS_FAILED(TestOneVideoNormalChannel())) { |
|
660 return 1; |
|
661 } |
|
662 |
|
663 if (NS_FAILED(TestPriorities())) { |
|
664 return 1; |
|
665 } |
|
666 |
|
667 return 0; |
|
668 } |
|
669 |