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.
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
10 #include "TestHarness.h"
12 #include "nsWeakReference.h"
13 #include "AudioChannelService.h"
14 #include "AudioChannelAgent.h"
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
26 using namespace mozilla::dom;
28 class Agent : public nsIAudioChannelAgentCallback,
29 public nsSupportsWeakReference
30 {
31 public:
32 NS_DECL_ISUPPORTS
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 }
43 virtual ~Agent()
44 {
45 if (mRegistered) {
46 StopPlaying();
47 }
48 }
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);
63 return mAgent->SetVisibilityState(false);
64 }
66 nsresult StartPlaying(AudioChannelState *_ret)
67 {
68 if (mRegistered) {
69 StopPlaying();
70 }
72 nsresult rv = mAgent->StartPlaying((int32_t *)_ret);
73 mRegistered = true;
74 return rv;
75 }
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 }
94 nsresult SetVisibilityState(bool visible)
95 {
96 if (mRegistered) {
97 mWaitCallback = true;
98 }
99 return mAgent->SetVisibilityState(visible);
100 }
102 NS_IMETHODIMP CanPlayChanged(int32_t canPlay)
103 {
104 mCanPlay = static_cast<AudioChannelState>(canPlay);
105 mWaitCallback = false;
106 return NS_OK;
107 }
109 NS_IMETHODIMP WindowVolumeChanged()
110 {
111 return NS_OK;
112 }
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 }
131 nsCOMPtr<nsIAudioChannelAgent> mAgent;
132 AudioChannel mChannel;
133 bool mWaitCallback;
134 bool mRegistered;
135 AudioChannelState mCanPlay;
136 };
138 NS_IMPL_ISUPPORTS(Agent, nsIAudioChannelAgentCallback,
139 nsISupportsWeakReference)
141 nsresult
142 TestDoubleStartPlaying()
143 {
144 nsRefPtr<Agent> agent = new Agent(AudioChannel::Normal);
146 nsresult rv = agent->Init();
147 NS_ENSURE_SUCCESS(rv, rv);
149 AudioChannelState playable;
150 rv = agent->mAgent->StartPlaying((int32_t *)&playable);
151 NS_ENSURE_SUCCESS(rv, rv);
153 rv = agent->mAgent->StartPlaying((int32_t *)&playable);
154 TEST_ENSURE_BASE(NS_FAILED(rv),
155 "Test0: StartPlaying calling twice must return error");
157 return NS_OK;
158 }
160 nsresult
161 TestOneNormalChannel()
162 {
163 nsRefPtr<Agent> agent = new Agent(AudioChannel::Normal);
164 nsresult rv = agent->Init();
165 NS_ENSURE_SUCCESS(rv, rv);
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");
173 rv = agent->SetVisibilityState(true);
174 NS_ENSURE_SUCCESS(rv, rv);
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");
181 return rv;
182 }
184 nsresult
185 TestTwoNormalChannels()
186 {
187 nsRefPtr<Agent> agent1 = new Agent(AudioChannel::Normal);
188 nsresult rv = agent1->Init();
189 NS_ENSURE_SUCCESS(rv, rv);
191 nsRefPtr<Agent> agent2 = new Agent(AudioChannel::Normal);
192 rv = agent2->Init();
193 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
206 rv = agent1->SetVisibilityState(true);
207 NS_ENSURE_SUCCESS(rv, rv);
209 rv = agent2->SetVisibilityState(true);
210 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
222 return rv;
223 }
225 nsresult
226 TestContentChannels()
227 {
228 nsRefPtr<Agent> agent1 = new Agent(AudioChannel::Content);
229 nsresult rv = agent1->Init();
230 NS_ENSURE_SUCCESS(rv, rv);
232 nsRefPtr<Agent> agent2 = new Agent(AudioChannel::Content);
233 rv = agent2->Init();
234 NS_ENSURE_SUCCESS(rv, rv);
236 // All content channels in the foreground can be allowed to play
237 rv = agent1->SetVisibilityState(true);
238 NS_ENSURE_SUCCESS(rv, rv);
240 rv = agent2->SetVisibilityState(true);
241 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
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);
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");
265 // Test all content channels set non-visible already
266 rv = agent2->SetVisibilityState(false);
267 NS_ENSURE_SUCCESS(rv, rv);
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");
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);
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);
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");
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");
307 return rv;
308 }
310 nsresult
311 TestFadedState()
312 {
313 nsRefPtr<Agent> normalAgent = new Agent(AudioChannel::Normal);
314 nsresult rv = normalAgent->Init();
315 NS_ENSURE_SUCCESS(rv, rv);
317 nsRefPtr<Agent> contentAgent = new Agent(AudioChannel::Content);
318 rv = contentAgent->Init();
319 NS_ENSURE_SUCCESS(rv, rv);
321 nsRefPtr<Agent> notificationAgent = new Agent(AudioChannel::Notification);
322 rv = notificationAgent->Init();
323 NS_ENSURE_SUCCESS(rv, rv);
325 rv = normalAgent->SetVisibilityState(true);
326 NS_ENSURE_SUCCESS(rv, rv);
328 rv = contentAgent->SetVisibilityState(true);
329 NS_ENSURE_SUCCESS(rv, rv);
331 rv = notificationAgent->SetVisibilityState(true);
332 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
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");
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");
356 rv = contentAgent->SetVisibilityState(false);
357 NS_ENSURE_SUCCESS(rv, rv);
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");
365 rv = notificationAgent->SetVisibilityState(false);
366 NS_ENSURE_SUCCESS(rv, rv);
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");
374 rv = notificationAgent->StopPlaying();
375 NS_ENSURE_SUCCESS(rv, rv);
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");
383 rv = contentAgent->SetVisibilityState(true);
384 NS_ENSURE_SUCCESS(rv, rv);
386 return rv;
387 }
389 nsresult
390 TestPriorities()
391 {
392 nsRefPtr<Agent> normalAgent = new Agent(AudioChannel::Normal);
393 nsresult rv = normalAgent->Init();
394 NS_ENSURE_SUCCESS(rv, rv);
396 nsRefPtr<Agent> contentAgent = new Agent(AudioChannel::Content);
397 rv = contentAgent->Init();
398 NS_ENSURE_SUCCESS(rv, rv);
400 nsRefPtr<Agent> notificationAgent = new Agent(AudioChannel::Notification);
401 rv = notificationAgent->Init();
402 NS_ENSURE_SUCCESS(rv, rv);
404 nsRefPtr<Agent> alarmAgent = new Agent(AudioChannel::Alarm);
405 rv = alarmAgent->Init();
406 NS_ENSURE_SUCCESS(rv, rv);
408 nsRefPtr<Agent> telephonyAgent = new Agent(AudioChannel::Telephony);
409 rv = telephonyAgent->Init();
410 NS_ENSURE_SUCCESS(rv, rv);
412 nsRefPtr<Agent> ringerAgent = new Agent(AudioChannel::Ringer);
413 rv = ringerAgent->Init();
414 NS_ENSURE_SUCCESS(rv, rv);
416 nsRefPtr<Agent> pNotificationAgent =
417 new Agent(AudioChannel::Publicnotification);
418 rv = pNotificationAgent->Init();
419 NS_ENSURE_SUCCESS(rv, rv);
421 AudioChannelState playable;
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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);
488 // Settings visible the normal channel.
489 rv = normalAgent->SetVisibilityState(true);
490 NS_ENSURE_SUCCESS(rv, rv);
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");
497 // Set the content channel as visible .
498 rv = contentAgent->SetVisibilityState(true);
499 NS_ENSURE_SUCCESS(rv, rv);
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");
507 // Set the alarm channel as visible.
508 rv = alarmAgent->SetVisibilityState(true);
509 NS_ENSURE_SUCCESS(rv, rv);
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");
516 // Set the telephony channel as visible.
517 rv = telephonyAgent->SetVisibilityState(true);
518 NS_ENSURE_SUCCESS(rv, rv);
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");
525 // Set the ringer channel as visible.
526 rv = ringerAgent->SetVisibilityState(true);
527 NS_ENSURE_SUCCESS(rv, rv);
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");
534 // Set the public notification channel as visible.
535 rv = pNotificationAgent->SetVisibilityState(true);
536 NS_ENSURE_SUCCESS(rv, rv);
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");
543 return rv;
544 }
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);
553 nsRefPtr<Agent> agent2 = new Agent(AudioChannel::Content);
554 rv = agent2->Init(false);
555 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
568 // one video normal channel in foreground and one content channel in background
569 rv = agent1->SetVisibilityState(true);
570 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
582 // both one video normal channel and one content channel in foreground
583 rv = agent2->SetVisibilityState(true);
584 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
596 // one video normal channel in background and one content channel in foreground
597 rv = agent1->SetVisibilityState(false);
598 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
610 // both one video normal channel and one content channel in background
611 rv = agent2->SetVisibilityState(false);
612 NS_ENSURE_SUCCESS(rv, rv);
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");
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");
624 return rv;
625 }
627 int main(int argc, char** argv)
628 {
629 ScopedXPCOM xpcom("AudioChannelService");
630 if (xpcom.failed()) {
631 return 1;
632 }
634 if (NS_FAILED(TestDoubleStartPlaying())) {
635 return 1;
636 }
638 if (NS_FAILED(TestOneNormalChannel())) {
639 return 1;
640 }
642 if (NS_FAILED(TestTwoNormalChannels())) {
643 return 1;
644 }
646 if (NS_FAILED(TestContentChannels())) {
647 return 1;
648 }
650 if (NS_FAILED(TestFadedState())) {
651 return 1;
652 }
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 }
663 if (NS_FAILED(TestPriorities())) {
664 return 1;
665 }
667 return 0;
668 }