2013-01-16 05:34:07 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-02-25 00:55:24 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2013-01-16 05:34:07 -08:00
|
|
|
|
|
|
|
#include "TestHarness.h"
|
|
|
|
|
2013-04-03 13:35:05 -07:00
|
|
|
// Work around the fact that the nsWeakPtr, used by AudioChannelService.h, is
|
|
|
|
// not exposed to consumers outside the internal API.
|
|
|
|
#include "nsIWeakReference.h"
|
|
|
|
typedef nsCOMPtr<nsIWeakReference> nsWeakPtr;
|
|
|
|
|
2013-01-16 05:34:07 -08:00
|
|
|
#include "AudioChannelService.h"
|
|
|
|
#include "AudioChannelAgent.h"
|
|
|
|
|
|
|
|
#define TEST_ENSURE_BASE(_test, _msg) \
|
|
|
|
PR_BEGIN_MACRO \
|
2013-09-02 02:45:44 -07:00
|
|
|
if (!(_test)) { \
|
2013-01-16 05:34:07 -08:00
|
|
|
fail(_msg); \
|
|
|
|
return NS_ERROR_FAILURE; \
|
|
|
|
} else { \
|
|
|
|
passed(_msg); \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
class Agent : public nsIAudioChannelAgentCallback
|
2013-01-16 05:34:07 -08:00
|
|
|
{
|
|
|
|
public:
|
2013-02-25 00:55:24 -08:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2013-01-16 05:34:07 -08:00
|
|
|
Agent(AudioChannelType aType)
|
|
|
|
: mType(aType)
|
2013-02-25 00:55:24 -08:00
|
|
|
, mWaitCallback(false)
|
2013-01-16 05:34:07 -08:00
|
|
|
, mRegistered(false)
|
2013-09-02 02:45:44 -07:00
|
|
|
, mCanPlay(AUDIO_CHANNEL_STATE_MUTED)
|
2013-01-16 05:34:07 -08:00
|
|
|
{
|
|
|
|
mAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1");
|
|
|
|
}
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
virtual ~Agent() {}
|
|
|
|
|
2013-01-16 05:34:07 -08:00
|
|
|
nsresult Init()
|
|
|
|
{
|
2013-02-25 00:55:24 -08:00
|
|
|
nsresult rv = mAgent->Init(mType, this);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return mAgent->SetVisibilityState(false);
|
|
|
|
}
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
nsresult StartPlaying(AudioChannelState *_ret)
|
2013-01-16 05:34:07 -08:00
|
|
|
{
|
|
|
|
if (mRegistered)
|
|
|
|
StopPlaying();
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
nsresult rv = mAgent->StartPlaying((int32_t *)_ret);
|
2013-01-16 05:34:07 -08:00
|
|
|
mRegistered = true;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult StopPlaying()
|
|
|
|
{
|
|
|
|
mRegistered = false;
|
2013-02-25 00:55:24 -08:00
|
|
|
int loop = 0;
|
|
|
|
while (mWaitCallback) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
Sleep(1000);
|
|
|
|
#else
|
|
|
|
sleep(1);
|
|
|
|
#endif
|
|
|
|
if (loop++ == 5) {
|
|
|
|
TEST_ENSURE_BASE(false, "StopPlaying timeout");
|
|
|
|
}
|
|
|
|
}
|
2013-01-16 05:34:07 -08:00
|
|
|
return mAgent->StopPlaying();
|
|
|
|
}
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
nsresult SetVisibilityState(bool visible)
|
|
|
|
{
|
|
|
|
if (mRegistered) {
|
|
|
|
mWaitCallback = true;
|
|
|
|
}
|
|
|
|
return mAgent->SetVisibilityState(visible);
|
|
|
|
}
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
NS_IMETHODIMP CanPlayChanged(int32_t canPlay)
|
2013-02-25 00:55:24 -08:00
|
|
|
{
|
2013-09-02 02:45:44 -07:00
|
|
|
mCanPlay = static_cast<AudioChannelState>(canPlay);
|
2013-02-25 00:55:24 -08:00
|
|
|
mWaitCallback = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
nsresult GetCanPlay(AudioChannelState *_ret)
|
2013-02-25 00:55:24 -08:00
|
|
|
{
|
|
|
|
int loop = 0;
|
|
|
|
while (mWaitCallback) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
Sleep(1000);
|
|
|
|
#else
|
|
|
|
sleep(1);
|
|
|
|
#endif
|
|
|
|
if (loop++ == 5) {
|
|
|
|
TEST_ENSURE_BASE(false, "GetCanPlay timeout");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*_ret = mCanPlay;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-16 05:34:07 -08:00
|
|
|
nsCOMPtr<AudioChannelAgent> mAgent;
|
|
|
|
AudioChannelType mType;
|
2013-02-25 00:55:24 -08:00
|
|
|
bool mWaitCallback;
|
2013-01-16 05:34:07 -08:00
|
|
|
bool mRegistered;
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState mCanPlay;
|
2013-01-16 05:34:07 -08:00
|
|
|
};
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
NS_IMPL_ISUPPORTS1(Agent, nsIAudioChannelAgentCallback)
|
|
|
|
|
2013-01-16 05:34:07 -08:00
|
|
|
nsresult
|
|
|
|
TestDoubleStartPlaying()
|
|
|
|
{
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> agent = new Agent(AUDIO_CHANNEL_NORMAL);
|
|
|
|
|
|
|
|
nsresult rv = agent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState playable;
|
|
|
|
rv = agent->mAgent->StartPlaying((int32_t *)&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent->mAgent->StartPlaying((int32_t *)&playable);
|
|
|
|
TEST_ENSURE_BASE(NS_FAILED(rv),
|
|
|
|
"Test0: StartPlaying calling twice must return error");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
agent->mAgent->StopPlaying();
|
2013-01-16 05:34:07 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TestOneNormalChannel()
|
|
|
|
{
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> agent = new Agent(AUDIO_CHANNEL_NORMAL);
|
|
|
|
nsresult rv = agent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState playable;
|
|
|
|
rv = agent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED,
|
|
|
|
"Test1: A normal channel unvisible agent must be muted");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent->SetVisibilityState(true);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent->GetCanPlay(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test1: A normal channel visible agent must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
agent->StopPlaying();
|
2013-01-16 05:34:07 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TestTwoNormalChannels()
|
|
|
|
{
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> agent1 = new Agent(AUDIO_CHANNEL_NORMAL);
|
|
|
|
nsresult rv = agent1->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> agent2 = new Agent(AUDIO_CHANNEL_NORMAL);
|
|
|
|
rv = agent2->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState playable;
|
|
|
|
rv = agent1->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED,
|
|
|
|
"Test2: A normal channel unvisible agent1 must be muted");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent2->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED,
|
|
|
|
"Test2: A normal channel unvisible agent2 must be muted");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent1->SetVisibilityState(true);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent2->SetVisibilityState(true);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent1->GetCanPlay(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test2: A normal channel visible agent1 must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent2->GetCanPlay(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test2: A normal channel visible agent2 must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
agent1->StopPlaying();
|
|
|
|
agent2->StopPlaying();
|
2013-01-16 05:34:07 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TestContentChannels()
|
|
|
|
{
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> agent1 = new Agent(AUDIO_CHANNEL_CONTENT);
|
|
|
|
nsresult rv = agent1->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> agent2 = new Agent(AUDIO_CHANNEL_CONTENT);
|
|
|
|
rv = agent2->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// All content channels in the foreground can be allowed to play
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent1->SetVisibilityState(true);
|
2013-01-25 07:12:17 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent2->SetVisibilityState(true);
|
2013-01-25 07:12:17 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState playable;
|
|
|
|
rv = agent1->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test3: A content channel visible agent1 must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent2->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test3: A content channel visible agent2 must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Test the transition state of one content channel tried to set non-visible
|
|
|
|
// state first when app is going to background.
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent1->SetVisibilityState(false);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent1->GetCanPlay(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test3: A content channel unvisible agent1 must be playable from "
|
|
|
|
"foreground to background");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Test all content channels set non-visible already
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent2->SetVisibilityState(false);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent2->GetCanPlay(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test3: A content channel unvisible agent2 must be playable from "
|
|
|
|
"foreground to background");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Clear the content channels & mActiveContentChildIDs in AudioChannelService.
|
|
|
|
// If agent stop playable in the background, we will reserve it's childID in
|
|
|
|
// mActiveContentChildIDs, then it can allow to play next song. So we set agents
|
|
|
|
// to foreground first then stopping to play
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent1->SetVisibilityState(true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = agent2->SetVisibilityState(true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = agent1->StopPlaying();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = agent2->StopPlaying();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-17 00:46:06 -07:00
|
|
|
// Test that content channels can be allow to play when they starts from
|
2013-09-02 02:45:44 -07:00
|
|
|
// the background state
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = agent1->SetVisibilityState(false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = agent2->SetVisibilityState(false);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent1->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-17 00:46:06 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test3: A content channel unvisible agent1 must be playable "
|
2013-09-02 02:45:44 -07:00
|
|
|
"from background state");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = agent2->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-17 00:46:06 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test3: A content channel unvisible agent2 must be playable "
|
2013-09-02 02:45:44 -07:00
|
|
|
"from background state");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
agent1->StopPlaying();
|
|
|
|
agent2->StopPlaying();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TestFadedState()
|
|
|
|
{
|
|
|
|
nsCOMPtr<Agent> normalAgent = new Agent(AUDIO_CHANNEL_NORMAL);
|
|
|
|
nsresult rv = normalAgent->Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<Agent> contentAgent = new Agent(AUDIO_CHANNEL_CONTENT);
|
|
|
|
rv = contentAgent->Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<Agent> notificationAgent = new Agent(AUDIO_CHANNEL_NOTIFICATION);
|
|
|
|
rv = notificationAgent->Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = normalAgent->SetVisibilityState(true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = contentAgent->SetVisibilityState(true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = notificationAgent->SetVisibilityState(true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
AudioChannelState playable;
|
|
|
|
rv = normalAgent->StartPlaying(&playable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test4: A normal channel visible agent must be playable");
|
|
|
|
|
|
|
|
rv = contentAgent->StartPlaying(&playable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test4: A content channel visible agent must be playable");
|
|
|
|
|
|
|
|
rv = notificationAgent->StartPlaying(&playable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test4: A notification channel visible agent must be playable");
|
|
|
|
|
|
|
|
rv = contentAgent->GetCanPlay(&playable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_FADED,
|
|
|
|
"Test4: A content channel unvisible agent must be faded because of "
|
|
|
|
"notification channel is playing");
|
|
|
|
|
|
|
|
rv = contentAgent->SetVisibilityState(false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = contentAgent->GetCanPlay(&playable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_FADED,
|
|
|
|
"Test4: A content channel unvisible agent must be faded because of "
|
|
|
|
"notification channel is playing");
|
|
|
|
|
|
|
|
rv = notificationAgent->SetVisibilityState(false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = notificationAgent->GetCanPlay(&playable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test4: A notification channel unvisible agent must be playable from "
|
|
|
|
"foreground to background");
|
|
|
|
|
|
|
|
rv = notificationAgent->StopPlaying();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = contentAgent->GetCanPlay(&playable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test4: A content channel unvisible agent must be playable "
|
|
|
|
"because of notification channel is stopped");
|
|
|
|
|
|
|
|
rv = contentAgent->SetVisibilityState(true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
normalAgent->StopPlaying();
|
|
|
|
contentAgent->StopPlaying();
|
2013-01-16 05:34:07 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TestPriorities()
|
|
|
|
{
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> normalAgent = new Agent(AUDIO_CHANNEL_NORMAL);
|
|
|
|
nsresult rv = normalAgent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> contentAgent = new Agent(AUDIO_CHANNEL_CONTENT);
|
|
|
|
rv = contentAgent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> notificationAgent = new Agent(AUDIO_CHANNEL_NOTIFICATION);
|
|
|
|
rv = notificationAgent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> alarmAgent = new Agent(AUDIO_CHANNEL_ALARM);
|
|
|
|
rv = alarmAgent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> telephonyAgent = new Agent(AUDIO_CHANNEL_TELEPHONY);
|
|
|
|
rv = telephonyAgent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-02-25 00:55:24 -08:00
|
|
|
nsCOMPtr<Agent> ringerAgent = new Agent(AUDIO_CHANNEL_RINGER);
|
|
|
|
rv = ringerAgent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
nsCOMPtr<Agent> pNotificationAgent =
|
|
|
|
new Agent(AUDIO_CHANNEL_PUBLICNOTIFICATION);
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = pNotificationAgent->Init();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState playable;
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = normalAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED,
|
|
|
|
"Test5: A normal channel unvisible agent must be muted");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = contentAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-17 00:46:06 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A content channel unvisible agent must be playable while "
|
2013-09-02 02:45:44 -07:00
|
|
|
"playing from background state");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = notificationAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A notification channel unvisible agent must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = alarmAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: An alarm channel unvisible agent must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = notificationAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED,
|
|
|
|
"Test5: A notification channel unvisible agent must be muted when an "
|
|
|
|
"alarm is playing");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = telephonyAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A telephony channel unvisible agent must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = alarmAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED,
|
|
|
|
"Test5: An alarm channel unvisible agent must be muted when a telephony "
|
|
|
|
"is playing");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = ringerAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A ringer channel unvisible agent must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = telephonyAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED,
|
|
|
|
"Test5: A telephony channel unvisible agent must be muted when a ringer "
|
|
|
|
"is playing");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = pNotificationAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A pNotification channel unvisible agent must be playable");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = ringerAgent->StartPlaying(&playable);
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_MUTED,
|
|
|
|
"Test5: A ringer channel unvisible agent must be muted when a public "
|
|
|
|
"notification is playing");
|
2013-01-16 05:34:07 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Stop to play notification channel or normal/content will be faded.
|
|
|
|
// Which already be tested on Test 4.
|
|
|
|
rv = notificationAgent->StopPlaying();
|
2013-01-16 05:34:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-01-16 05:38:51 -08:00
|
|
|
// Settings visible the normal channel.
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = normalAgent->SetVisibilityState(true);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = normalAgent->GetCanPlay(&playable);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A normal channel visible agent must be playable");
|
2013-01-16 05:38:51 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Set the content channel as visible .
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = contentAgent->SetVisibilityState(true);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Content must be playable because visible.
|
|
|
|
rv = contentAgent->GetCanPlay(&playable);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A content channel visible agent must be playable");
|
2013-01-16 05:38:51 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Set the alarm channel as visible.
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = alarmAgent->SetVisibilityState(true);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = alarmAgent->GetCanPlay(&playable);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: An alarm channel visible agent must be playable");
|
2013-01-16 05:38:51 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Set the telephony channel as visible.
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = telephonyAgent->SetVisibilityState(true);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = telephonyAgent->GetCanPlay(&playable);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A telephony channel visible agent must be playable");
|
2013-01-16 05:38:51 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Set the ringer channel as visible.
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = ringerAgent->SetVisibilityState(true);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = ringerAgent->GetCanPlay(&playable);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A ringer channel visible agent must be playable");
|
2013-01-16 05:38:51 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
// Set the public notification channel as visible.
|
2013-02-25 00:55:24 -08:00
|
|
|
rv = pNotificationAgent->SetVisibilityState(true);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
rv = pNotificationAgent->GetCanPlay(&playable);
|
2013-01-16 05:38:51 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-09-02 02:45:44 -07:00
|
|
|
TEST_ENSURE_BASE(playable == AUDIO_CHANNEL_STATE_NORMAL,
|
|
|
|
"Test5: A pNotification channel visible agent must be playable");
|
2013-01-16 05:38:51 -08:00
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
normalAgent->StopPlaying();
|
|
|
|
contentAgent->StopPlaying();
|
|
|
|
alarmAgent->StopPlaying();
|
|
|
|
telephonyAgent->StopPlaying();
|
|
|
|
ringerAgent->StopPlaying();
|
|
|
|
pNotificationAgent->StopPlaying();
|
2013-01-16 05:34:07 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
ScopedXPCOM xpcom("AudioChannelService");
|
|
|
|
if (xpcom.failed())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (NS_FAILED(TestDoubleStartPlaying()))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (NS_FAILED(TestOneNormalChannel()))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (NS_FAILED(TestTwoNormalChannels()))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (NS_FAILED(TestContentChannels()))
|
|
|
|
return 1;
|
|
|
|
|
2013-09-02 02:45:44 -07:00
|
|
|
if (NS_FAILED(TestFadedState()))
|
|
|
|
return 1;
|
|
|
|
|
2013-01-16 05:34:07 -08:00
|
|
|
if (NS_FAILED(TestPriorities()))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|