Backed out changeset c9cfbe159b26 (bug 1200133) for failing it's own tests

This commit is contained in:
Nigel Babu 2015-11-24 17:23:47 +05:30
parent e516665f2c
commit 8e17dab54a
12 changed files with 677 additions and 178 deletions

View File

@ -561,9 +561,6 @@
@RESPATH@/components/SlowScriptDebug.manifest
@RESPATH@/components/SlowScriptDebug.js
@RESPATH@/components/TVSimulatorService.js
@RESPATH@/components/TVSimulatorService.manifest
#ifndef RELEASE_BUILD
@RESPATH@/components/InterAppComm.manifest
@RESPATH@/components/InterAppCommService.js

532
dom/tv/FakeTVService.cpp Normal file
View File

@ -0,0 +1,532 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "mozilla/dom/TVServiceRunnables.h"
#include "mozilla/dom/TVTypes.h"
#include "nsCOMPtr.h"
#include "nsIMutableArray.h"
#include "nsITimer.h"
#include "nsServiceManagerUtils.h"
#include "prtime.h"
#include "FakeTVService.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(FakeTVService)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(FakeTVService)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTuners)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChannels)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrograms)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEITBroadcastedTimer)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScanCompleteTimer)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(FakeTVService)
tmp->Shutdown();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTuners)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChannels)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrograms)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEITBroadcastedTimer)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mScanCompleteTimer)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(FakeTVService)
NS_IMPL_CYCLE_COLLECTING_RELEASE(FakeTVService)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FakeTVService)
NS_INTERFACE_MAP_ENTRY(nsITVService)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
FakeTVService::FakeTVService()
{
Init();
}
FakeTVService::~FakeTVService()
{
Shutdown();
}
void
FakeTVService::Init()
{
const char* sourceTypes1[2] = {"dvb-t", "dvb-c"};
nsCOMPtr<nsITVTunerData> tunerData1 = MockTuner(NS_LITERAL_STRING("1"), 2, sourceTypes1);
mTuners.AppendElement(tunerData1);
const char* sourceTypes2[1] = {"dvb-s"};
nsCOMPtr<nsITVTunerData> tunerData2 = MockTuner(NS_LITERAL_STRING("2"), 1, sourceTypes2);
mTuners.AppendElement(tunerData2);
nsCOMPtr<nsITVChannelData> channelData1 =
MockChannel(NS_LITERAL_STRING("networkId1"), NS_LITERAL_STRING("transportStreamId1"),
NS_LITERAL_STRING("serviceId1"), NS_LITERAL_STRING("tv"),
NS_LITERAL_STRING("1"), NS_LITERAL_STRING("name1"), true, true);
mChannels.AppendElement(channelData1);
nsCOMPtr<nsITVChannelData> channelData2 =
MockChannel(NS_LITERAL_STRING("networkId2"), NS_LITERAL_STRING("transportStreamId2"),
NS_LITERAL_STRING("serviceId2"), NS_LITERAL_STRING("radio"),
NS_LITERAL_STRING("2"), NS_LITERAL_STRING("name2"), true, true);
mChannels.AppendElement(channelData2);
uint64_t now = PR_Now();
const char* audioLanguages1[2] = {"eng", "jpn"};
const char* subtitleLanguages1[2] = {"fre", "spa"};
nsCOMPtr<nsITVProgramData> programData1 =
MockProgram(NS_LITERAL_STRING("eventId1"), NS_LITERAL_STRING("title1"),
now - 1, 3600000,
NS_LITERAL_STRING("description1"), NS_LITERAL_STRING("rating1"),
2, audioLanguages1, 2, subtitleLanguages1);
mPrograms.AppendElement(programData1);
nsCOMPtr<nsITVProgramData> programData2 =
MockProgram(NS_LITERAL_STRING("eventId2"), NS_LITERAL_STRING("title2"),
now + 3600000 , 3600000,
NS_LITERAL_STRING(""), NS_LITERAL_STRING(""),
0, nullptr, 0, nullptr);
mPrograms.AppendElement(programData2);
}
void
FakeTVService::Shutdown()
{
if (mEITBroadcastedTimer) {
mEITBroadcastedTimer->Cancel();
}
if (mScanCompleteTimer) {
mScanCompleteTimer->Cancel();
}
}
/* virtual */ NS_IMETHODIMP
FakeTVService::GetSourceListener(nsITVSourceListener** aSourceListener)
{
if (!mSourceListener) {
*aSourceListener = nullptr;
return NS_OK;
}
*aSourceListener = mSourceListener;
NS_ADDREF(*aSourceListener);
return NS_OK;
}
/* virtual */ NS_IMETHODIMP
FakeTVService::SetSourceListener(nsITVSourceListener* aSourceListener)
{
mSourceListener = aSourceListener;
return NS_OK;
}
/* virtual */ NS_IMETHODIMP
FakeTVService::GetTuners(nsITVServiceCallback* aCallback)
{
if (!aCallback) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIMutableArray> tunerDataList = do_CreateInstance(NS_ARRAY_CONTRACTID);
if (!tunerDataList) {
return NS_ERROR_OUT_OF_MEMORY;
}
for (uint32_t i = 0; i < mTuners.Length(); i++) {
tunerDataList->AppendElement(mTuners[i], false);
}
nsCOMPtr<nsIRunnable> runnable =
new TVServiceNotifyRunnable(aCallback, tunerDataList);
return NS_DispatchToCurrentThread(runnable);
}
/* virtual */ NS_IMETHODIMP
FakeTVService::SetSource(const nsAString& aTunerId,
const nsAString& aSourceType,
nsITVServiceCallback* aCallback)
{
if (!aCallback) {
return NS_ERROR_INVALID_ARG;
}
for (uint32_t i = 0; i < mTuners.Length(); i++) {
nsString tunerId;
mTuners[i]->GetId(tunerId);
if (aTunerId.Equals(tunerId)) {
uint32_t sourceTypeCount;
char** sourceTypes;
mTuners[i]->GetSupportedSourceTypes(&sourceTypeCount, &sourceTypes);
for (uint32_t j = 0; j < sourceTypeCount; j++) {
nsString sourceType;
sourceType.AssignASCII(sourceTypes[j]);
if (aSourceType.Equals(sourceType)) {
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(sourceTypeCount, sourceTypes);
nsCOMPtr<nsIRunnable> runnable =
new TVServiceNotifyRunnable(aCallback, nullptr);
return NS_DispatchToCurrentThread(runnable);
}
}
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(sourceTypeCount, sourceTypes);
}
}
nsCOMPtr<nsIRunnable> runnable =
new TVServiceNotifyRunnable(aCallback, nullptr, nsITVServiceCallback::TV_ERROR_FAILURE);
return NS_DispatchToCurrentThread(runnable);
}
class EITBroadcastedCallback final : public nsITimerCallback
{
public:
NS_DECL_ISUPPORTS
EITBroadcastedCallback(const nsAString& aTunerId,
const nsAString& aSourceType,
nsITVSourceListener* aSourceListener,
nsITVChannelData* aChannelData)
: mTunerId(aTunerId)
, mSourceType(aSourceType)
, mSourceListener(aSourceListener)
, mChannelData(aChannelData)
{}
NS_IMETHODIMP
Notify(nsITimer* aTimer) override
{
// Notify mock EIT broadcasting.
nsITVProgramData** programDataList =
static_cast<nsITVProgramData **>(moz_xmalloc(1 * sizeof(nsITVProgramData*)));
programDataList[0] = new TVProgramData();
programDataList[0]->SetEventId(NS_LITERAL_STRING("eventId"));
programDataList[0]->SetTitle(NS_LITERAL_STRING("title"));
programDataList[0]->SetStartTime(PR_Now() + 3600000);
programDataList[0]->SetDuration(3600000);
programDataList[0]->SetDescription(NS_LITERAL_STRING("description"));
programDataList[0]->SetRating(NS_LITERAL_STRING("rating"));
programDataList[0]->SetAudioLanguages(0, nullptr);
programDataList[0]->SetSubtitleLanguages(0, nullptr);
nsresult rv = mSourceListener->NotifyEITBroadcasted(mTunerId, mSourceType,
mChannelData,
programDataList, 1);
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(1, programDataList);
return rv;
}
private:
~EITBroadcastedCallback() {}
nsString mTunerId;
nsString mSourceType;
nsCOMPtr<nsITVSourceListener> mSourceListener;
nsCOMPtr<nsITVChannelData> mChannelData;
};
NS_IMPL_ISUPPORTS(EITBroadcastedCallback, nsITimerCallback)
class ScanCompleteCallback final : public nsITimerCallback
{
public:
NS_DECL_ISUPPORTS
ScanCompleteCallback(const nsAString& aTunerId,
const nsAString& aSourceType,
nsITVSourceListener* aSourceListener)
: mTunerId(aTunerId)
, mSourceType(aSourceType)
, mSourceListener(aSourceListener)
{}
NS_IMETHODIMP
Notify(nsITimer* aTimer) override
{
return mSourceListener->NotifyChannelScanComplete(mTunerId, mSourceType);
}
private:
~ScanCompleteCallback() {}
nsString mTunerId;
nsString mSourceType;
nsCOMPtr<nsITVSourceListener> mSourceListener;
};
NS_IMPL_ISUPPORTS(ScanCompleteCallback, nsITimerCallback)
/* virtual */ NS_IMETHODIMP
FakeTVService::StartScanningChannels(const nsAString& aTunerId,
const nsAString& aSourceType,
nsITVServiceCallback* aCallback)
{
if (!aCallback) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIRunnable> runnable =
new TVServiceNotifyRunnable(aCallback, nullptr);
nsresult rv = NS_DispatchToCurrentThread(runnable);
NS_ENSURE_SUCCESS(rv, rv);
if (IsAllowed(aTunerId, aSourceType)) {
rv = mSourceListener->NotifyChannelScanned(aTunerId, aSourceType, mChannels[0]);
NS_ENSURE_SUCCESS(rv, rv);
// Set a timer. |notifyEITBroadcasted| will be called after the timer
// fires (10ms). (The timer could be canceled if |StopScanningChannels| gets
// called before firing.)
mEITBroadcastedTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
NS_ENSURE_TRUE(mEITBroadcastedTimer, NS_ERROR_OUT_OF_MEMORY);
RefPtr<EITBroadcastedCallback> eitBroadcastedCb =
new EITBroadcastedCallback(aTunerId, aSourceType, mSourceListener, mChannels[0]);
rv = mEITBroadcastedTimer->InitWithCallback(eitBroadcastedCb, 10,
nsITimer::TYPE_ONE_SHOT);
NS_ENSURE_SUCCESS(rv, rv);
// Set a timer. |notifyChannelScanComplete| will be called after the timer
// fires (20ms). (The timer could be canceled if |StopScanningChannels| gets
// called before firing.)
mScanCompleteTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
NS_ENSURE_TRUE(mScanCompleteTimer, NS_ERROR_OUT_OF_MEMORY);
RefPtr<ScanCompleteCallback> scanCompleteCb =
new ScanCompleteCallback(aTunerId, aSourceType, mSourceListener);
rv = mScanCompleteTimer->InitWithCallback(scanCompleteCb, 20,
nsITimer::TYPE_ONE_SHOT);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
/* virtual */ NS_IMETHODIMP
FakeTVService::StopScanningChannels(const nsAString& aTunerId,
const nsAString& aSourceType,
nsITVServiceCallback* aCallback)
{
if (!aCallback) {
return NS_ERROR_INVALID_ARG;
}
if (mEITBroadcastedTimer) {
mEITBroadcastedTimer->Cancel();
mEITBroadcastedTimer = nullptr;
}
if (mScanCompleteTimer) {
mScanCompleteTimer->Cancel();
mScanCompleteTimer = nullptr;
}
nsresult rv = mSourceListener->NotifyChannelScanStopped(aTunerId, aSourceType);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRunnable> runnable =
new TVServiceNotifyRunnable(aCallback, nullptr);
return NS_DispatchToCurrentThread(runnable);
}
/* virtual */ NS_IMETHODIMP
FakeTVService::ClearScannedChannelsCache()
{
// Fake service doesn't support channel cache, so there's nothing to do here.
return NS_OK;
}
/* virtual */ NS_IMETHODIMP
FakeTVService::SetChannel(const nsAString& aTunerId,
const nsAString& aSourceType,
const nsAString& aChannelNumber,
nsITVServiceCallback* aCallback)
{
if (!aCallback) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIMutableArray> channelDataList = do_CreateInstance(NS_ARRAY_CONTRACTID);
if (!channelDataList) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (IsAllowed(aTunerId, aSourceType)) {
for (uint32_t i = 0; i < mChannels.Length(); i++) {
nsString channelNumber;
mChannels[i]->GetNumber(channelNumber);
if (aChannelNumber.Equals(channelNumber)) {
channelDataList->AppendElement(mChannels[i], false);
break;
}
}
}
uint32_t length;
nsresult rv = channelDataList->GetLength(&length);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIRunnable> runnable = new TVServiceNotifyRunnable(
aCallback,
(length == 1) ? channelDataList : nullptr,
(length == 1) ? nsITVServiceCallback::TV_ERROR_OK : nsITVServiceCallback::TV_ERROR_FAILURE
);
return NS_DispatchToCurrentThread(runnable);
}
/* virtual */ NS_IMETHODIMP
FakeTVService::GetChannels(const nsAString& aTunerId,
const nsAString& aSourceType,
nsITVServiceCallback* aCallback)
{
if (!aCallback) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIMutableArray> channelDataList = do_CreateInstance(NS_ARRAY_CONTRACTID);
if (!channelDataList) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (IsAllowed(aTunerId, aSourceType)) {
for (uint32_t i = 0; i < mChannels.Length(); i++) {
channelDataList->AppendElement(mChannels[i], false);
}
}
nsCOMPtr<nsIRunnable> runnable =
new TVServiceNotifyRunnable(aCallback, channelDataList);
return NS_DispatchToCurrentThread(runnable);
}
/* virtual */ NS_IMETHODIMP
FakeTVService::GetPrograms(const nsAString& aTunerId,
const nsAString& aSourceType,
const nsAString& aChannelNumber,
uint64_t startTime,
uint64_t endTime,
nsITVServiceCallback* aCallback)
{
if (!aCallback) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIMutableArray> programDataList = do_CreateInstance(NS_ARRAY_CONTRACTID);
if (!programDataList) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Only return mock programs for the first channel.
nsString channelNumber;
mChannels[0]->GetNumber(channelNumber);
if (IsAllowed(aTunerId, aSourceType) && aChannelNumber.Equals(channelNumber)) {
for (uint32_t i = 0; i < mPrograms.Length(); i++) {
programDataList->AppendElement(mPrograms[i], false);
}
}
nsCOMPtr<nsIRunnable> runnable =
new TVServiceNotifyRunnable(aCallback, programDataList);
return NS_DispatchToCurrentThread(runnable);
}
/* virtual */ NS_IMETHODIMP
FakeTVService::GetOverlayId(const nsAString& aTunerId,
nsITVServiceCallback* aCallback)
{
if (!aCallback) {
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIMutableArray> overlayIds = do_CreateInstance(NS_ARRAY_CONTRACTID);
if (!overlayIds) {
return NS_ERROR_OUT_OF_MEMORY;
}
// TODO Implement in follow-up patches.
nsCOMPtr<nsIRunnable> runnable =
new TVServiceNotifyRunnable(aCallback, overlayIds);
return NS_DispatchToCurrentThread(runnable);
}
bool
FakeTVService::IsAllowed(const nsAString& aTunerId,
const nsAString& aSourceType)
{
// Only allow for the first source of the first tuner.
nsString tunerId;
mTuners[0]->GetId(tunerId);
if (!aTunerId.Equals(tunerId)) {
return false;
}
uint32_t sourceTypeCount;
char** sourceTypes;
mTuners[0]->GetSupportedSourceTypes(&sourceTypeCount, &sourceTypes);
nsString sourceType;
sourceType.AssignASCII(sourceTypes[0]);
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(sourceTypeCount, sourceTypes);
if (!aSourceType.Equals(sourceType)) {
return false;
}
return true;
}
already_AddRefed<nsITVTunerData>
FakeTVService::MockTuner(const nsAString& aId,
uint32_t aSupportedSourceTypeCount,
const char** aSupportedSourceTypes)
{
nsCOMPtr<nsITVTunerData> tunerData = new TVTunerData();
tunerData->SetId(aId);
tunerData->SetSupportedSourceTypes(aSupportedSourceTypeCount, aSupportedSourceTypes);
return tunerData.forget();
}
already_AddRefed<nsITVChannelData>
FakeTVService::MockChannel(const nsAString& aNetworkId,
const nsAString& aTransportStreamId,
const nsAString& aServiceId,
const nsAString& aType,
const nsAString& aNumber,
const nsAString& aName,
bool aIsEmergency,
bool aIsFree)
{
nsCOMPtr<nsITVChannelData> channelData = new TVChannelData();
channelData->SetNetworkId(aNetworkId);
channelData->SetTransportStreamId(aTransportStreamId);
channelData->SetServiceId(aServiceId);
channelData->SetType(aType);
channelData->SetNumber(aNumber);
channelData->SetName(aName);
channelData->SetIsEmergency(aIsEmergency);
channelData->SetIsFree(aIsFree);
return channelData.forget();
}
already_AddRefed<nsITVProgramData>
FakeTVService::MockProgram(const nsAString& aEventId,
const nsAString& aTitle,
uint64_t aStartTime,
uint64_t aDuration,
const nsAString& aDescription,
const nsAString& aRating,
uint32_t aAudioLanguageCount,
const char** aAudioLanguages,
uint32_t aSubtitleLanguageCount,
const char** aSubtitleLanguages)
{
nsCOMPtr<nsITVProgramData> programData = new TVProgramData();
programData->SetEventId(aEventId);
programData->SetTitle(aTitle);
programData->SetStartTime(aStartTime);
programData->SetDuration(aDuration);
programData->SetDescription(aDescription);
programData->SetRating(aRating);
programData->SetAudioLanguages(aAudioLanguageCount, aAudioLanguages);
programData->SetSubtitleLanguages(aSubtitleLanguageCount, aSubtitleLanguages);
return programData.forget();
}
} // namespace dom
} // namespace mozilla

84
dom/tv/FakeTVService.h Normal file
View File

@ -0,0 +1,84 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_FakeTVService_h
#define mozilla_dom_FakeTVService_h
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsITVService.h"
#include "nsTArray.h"
#define FAKE_TV_SERVICE_CONTRACTID \
"@mozilla.org/tv/faketvservice;1"
#define FAKE_TV_SERVICE_CID \
{ 0x60fb3c53, 0x017f, 0x4340, { 0x91, 0x1b, 0xd5, 0x5c, 0x31, 0x28, 0x88, 0xb6 } }
class nsITimer;
class nsITVTunerData;
class nsITVChannelData;
class nsITVProgramData;
namespace mozilla {
namespace dom {
class FakeTVService final : public nsITVService
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(FakeTVService)
NS_DECL_NSITVSERVICE
FakeTVService();
private:
~FakeTVService();
void Init();
void Shutdown();
bool IsAllowed(const nsAString& aTunerId,
const nsAString& aSourceType);
already_AddRefed<nsITVTunerData> MockTuner(const nsAString& aId,
uint32_t aSupportedSourceTypeCount,
const char** aSupportedSourceTypes);
already_AddRefed<nsITVChannelData> MockChannel(const nsAString& aNetworkId,
const nsAString& aTransportStreamId,
const nsAString& aServiceId,
const nsAString& aType,
const nsAString& aNumber,
const nsAString& aName,
bool aIsEmergency,
bool aIsFree);
already_AddRefed<nsITVProgramData> MockProgram(const nsAString& aEventId,
const nsAString& aTitle,
uint64_t aStartTime,
uint64_t aDuration,
const nsAString& aDescription,
const nsAString& aRating,
uint32_t aAudioLanguageCount,
const char** aAudioLanguages,
uint32_t aSubtitleLanguageCount,
const char** aSubtitleLanguages);
nsCOMPtr<nsITVSourceListener> mSourceListener;
// The real implementation may want to use more efficient data structures.
nsTArray<nsCOMPtr<nsITVTunerData>> mTuners;
nsTArray<nsCOMPtr<nsITVChannelData>> mChannels;
nsTArray<nsCOMPtr<nsITVProgramData>> mPrograms;
nsCOMPtr<nsITimer> mEITBroadcastedTimer;
nsCOMPtr<nsITimer> mScanCompleteTimer;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_FakeTVService_h

View File

@ -4,6 +4,7 @@
* 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/. */
#include "mozilla/dom/FakeTVService.h"
#include "mozilla/dom/TVListeners.h"
#include "mozilla/Preferences.h"
#include "nsITVService.h"
@ -14,14 +15,26 @@
namespace mozilla {
namespace dom {
/* static */ already_AddRefed<FakeTVService>
TVServiceFactory::CreateFakeTVService()
{
RefPtr<FakeTVService> service = new FakeTVService();
return service.forget();
}
/* static */ already_AddRefed<nsITVService>
TVServiceFactory::AutoCreateTVService()
{
nsresult rv = NS_OK;
nsresult rv;
nsCOMPtr<nsITVService> service = do_CreateInstance(TV_SERVICE_CONTRACTID);
if (!service) {
// Fallback to the TV Simulator Service
service = do_CreateInstance(TV_SIMULATOR_SERVICE_CONTRACTID, &rv);
if (Preferences::GetBool("dom.ignore_webidl_scope_checks", false)) {
// Fallback to the fake service.
service = do_CreateInstance(FAKE_TV_SERVICE_CONTRACTID, &rv);
} else {
// Fallback to the TV Simulator Service
service = do_CreateInstance(TV_SIMULATOR_SERVICE_CONTRACTID, &rv);
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;

View File

@ -14,9 +14,13 @@ class nsITVService;
namespace mozilla {
namespace dom {
class FakeTVService;
class TVServiceFactory
{
public:
static already_AddRefed<FakeTVService> CreateFakeTVService();
static already_AddRefed<nsITVService> AutoCreateTVService();
};

View File

@ -13,11 +13,9 @@ const Ci = Components.interfaces;
const Cr = Components.returnCode;
Cu.importGlobalProperties(["File"]);
Cu.import("resource://gre/modules/Services.jsm");
const TV_SIMULATOR_DUMMY_DIRECTORY = "dummy";
const TV_SIMULATOR_DUMMY_FILE = "settings.json";
const TV_SIMULATOR_MOCK_DATA_PATH = Services.prefs.getCharPref("dom.testing.tv_mock_path");
const TV_SIMULATOR_DUMMY_DIRECTORY = "dummy";
const TV_SIMULATOR_DUMMY_FILE = "settings.json";
// See http://seanyhlin.github.io/TV-Manager-API/#idl-def-TVSourceType
const TV_SOURCE_TYPES = ["dvb-t","dvb-t2","dvb-c","dvb-c2","dvb-s",
@ -51,16 +49,36 @@ TVSimulatorService.prototype = {
return;
}
// Load the setting file from local JSON file.
// Synchrhronous File Reading.
let file = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsILocalFile);
file.initWithPath(this._getFilePath(TV_SIMULATOR_DUMMY_FILE));
let fstream = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(Ci.nsIConverterInputStream);
let settingStr = "";
try {
if (TV_SIMULATOR_MOCK_DATA_PATH) {
settingStr = this._getTestMockData();
} else {
settingStr = this._getDummyData();
fstream.init(file, -1, 0, 0);
cstream.init(fstream,
"UTF-8",
1024,
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
let str = {};
while (cstream.readString(0xffffffff, str) != 0) {
settingStr += str.value;
}
} catch(e) {
debug("Error occurred : " + e );
return;
} finally {
cstream.close();
}
let settingsObj;
@ -263,11 +281,10 @@ TVSimulatorService.prototype = {
}
this._scanCompleteTimer = null;
let notifyResult = this._sourceListener.notifyChannelScanComplete(
this._scanningWrapTunerData.tuner.id,
this._scanningWrapTunerData.sourceType);
this._scanningWrapTunerData = null;
return notifyResult;
return this._sourceListener.notifyChannelScanComplete(
this._scanningWrapTunerData.tuner.id,
this._scanningWrapTunerData.sourceType);
},
stopScanningChannels: function TVSimStopScanningChannels(aTunerId, aSourceType, aCallback) {
@ -417,55 +434,6 @@ TVSimulatorService.prototype = {
return videoBlobURL;
},
_getDummyData : function TVSimGetDummyData() {
// Load the setting file from local JSON file.
// Synchrhronous File Reading.
let file = Cc["@mozilla.org/file/local;1"]
.createInstance(Ci.nsILocalFile);
let fstream = Cc["@mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(Ci.nsIConverterInputStream);
let settingsStr = "";
try {
file.initWithPath(this._getFilePath(TV_SIMULATOR_DUMMY_FILE));
fstream.init(file, -1, 0, 0);
cstream.init(fstream,
"UTF-8",
1024,
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
let str = {};
while (cstream.readString(0xffffffff, str) != 0) {
settingsStr += str.value;
}
} catch(e) {
debug("Catch the Exception when reading the dummy file:" + e );
throw e;
} finally {
cstream.close();
}
return settingsStr;
},
_getTestMockData : function TVSiimGetMockData() {
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
xhr.open("GET", TV_SIMULATOR_MOCK_DATA_PATH, false);
xhr.send(null);
if (xhr.status == 200) {
debug("success response!{" + xhr.responseText + "]\n");
return xhr.responseText;
}
debug("failed to request xmlhttp["+ xhr.status + "]\n");
return "";
},
_getTunerMapKey: function TVSimGetTunerMapKey(aTunerId, aSourceType) {
return JSON.stringify({'tunerId': aTunerId, 'sourceType': aSourceType});
},

View File

@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla.dom += [
'FakeTVService.h',
'TVChannel.h',
'TVListeners.h',
'TVManager.h',
@ -19,6 +20,7 @@ EXPORTS.mozilla.dom += [
]
UNIFIED_SOURCES += [
'FakeTVService.cpp',
'TVChannel.cpp',
'TVListeners.cpp',
'TVManager.cpp',

View File

@ -9,11 +9,8 @@ function setupPrefsAndPermissions(callback) {
}
function setupPrefs(callback) {
SpecialPowers.pushPrefEnv({"set": [
["dom.tv.enabled", true],
["dom.ignore_webidl_scope_checks", true],
["dom.testing.tv_mock_path", SimpleTest.getTestFileURL("mock_data.json")]
]}, function() {
SpecialPowers.pushPrefEnv({"set": [["dom.tv.enabled", true],
["dom.ignore_webidl_scope_checks", true]]}, function() {
callback();
});
}

View File

@ -1,8 +1,6 @@
[DEFAULT]
support-files =
head.js
mock_data.json
support-files = head.js
skip-if = (os == 'mac' && debug) || asan # Bug 1125477
[test_tv_non_permitted_app.html]
[test_tv_permitted_app.html]
[test_tv_get_tuners.html]

View File

@ -1,99 +0,0 @@
{
"tuners": [
{
"id":"1",
"supportedType": ["dvb-t"],
"sources": [
{
"type": "dvb-t",
"channels": [
{
"networkId": "32112",
"transportStreamId": "32112",
"serviceId": "40960",
"type": "tv",
"name": "TV #1",
"number" : 1,
"isEmergency": false,
"isFree" : true,
"videoFilePath": "tv1.ogv",
"programs": [
{"eventId":"734475972", "title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Morning News", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"422158917", "title":"News of Midnight", "startTime":"1431266400", "duration":"3600", "description":"Summary of today news", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"533612446", "title":"Entertainment Program", "startTime":"1431270000", "duration":"7200", "description":"Midnight entertainment program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}
]
},
{
"_comment": "Channel Data",
"networkId": "32122",
"transportStreamId": "32122",
"serviceId": "40990",
"type": "tv",
"name": "TV #2",
"number" : 2,
"isEmergency": false,
"isFree" : true,
"videoFilePath": "tv2.ogv",
"programs": [
{"eventId":"931109607","title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Provide news in morning", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"297834220","title":"Weekly News", "startTime":"1431259200", "duration":"10800", "description":"Poopular Music program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"866886159","title":"Weekly news", "startTime":"1431270000", "duration":"7200", "description":"Information program on Monday", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}
]
},
{
"_comment": "Channel Data",
"networkId": "32132",
"transportStreamId": "32132",
"serviceId": "41020",
"type": "tv",
"name": "TV #3",
"number" : 3,
"isEmergency": false,
"isFree" : true,
"videoFilePath": "tv1.ogv",
"programs": [
{"eventId":"734475972", "title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Morning News", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"586216742", "title":"Information Program", "startTime":"1430697600", "duration":"7200", "description":"Provide program Information.", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"533612446", "title":"Entertainment Program", "startTime":"1431270000", "duration":"7200", "description":"Midnight entertainment program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}
]
},
{
"_comment": "Channel Data",
"networkId": "32142",
"transportStreamId": "32142",
"serviceId": "41040",
"type": "tv",
"name": "TV #5",
"number" : 4,
"isEmergency": false,
"isFree" : true,
"videoFilePath": "tv2.ogv",
"programs": [
{"eventId":"931109607","title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Provide news in morning", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"297834220","title":"Weekly News", "startTime":"1431259200", "duration":"10800", "description":"Poopular Music program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"866886159","title":"Weekly news", "startTime":"1431270000", "duration":"7200", "description":"Information program on Monday", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}
]
},
{
"_comment": "Channel Data",
"networkId": "32152",
"transportStreamId": "32152",
"serviceId": "41060",
"type": "tv",
"name": "TV #5",
"number" : 5,
"isEmergency": false,
"isFree" : true,
"videoFilePath": "tv1.ogv",
"programs": [
{"eventId":"734475972", "title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Morning News", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"586216742", "title":"Information Program", "startTime":"1430697600", "duration":"7200", "description":"Provide program Information.", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]},
{"eventId":"533612446", "title":"Entertainment Program", "startTime":"1431270000", "duration":"7200", "description":"Midnight entertainment program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}
]
}
]
}
]
}
]
}

View File

@ -243,6 +243,7 @@ static void Shutdown();
#include "nsITelephonyService.h"
#include "nsIVoicemailService.h"
#include "mozilla/dom/FakeTVService.h"
#include "mozilla/dom/TVServiceFactory.h"
#include "mozilla/dom/TVTypes.h"
#include "nsITVService.h"
@ -390,6 +391,8 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITelephonyService,
NS_CreateTelephonyService)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIVoicemailService,
NS_CreateVoicemailService)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(FakeTVService,
TVServiceFactory::CreateFakeTVService)
NS_GENERIC_FACTORY_CONSTRUCTOR(TVTunerData)
NS_GENERIC_FACTORY_CONSTRUCTOR(TVChannelData)
NS_GENERIC_FACTORY_CONSTRUCTOR(TVProgramData)
@ -848,6 +851,7 @@ NS_DEFINE_NAMED_CID(NS_SYNTHVOICEREGISTRY_CID);
#ifdef ACCESSIBILITY
NS_DEFINE_NAMED_CID(NS_ACCESSIBILITY_SERVICE_CID);
#endif
NS_DEFINE_NAMED_CID(FAKE_TV_SERVICE_CID);
NS_DEFINE_NAMED_CID(TV_TUNER_DATA_CID);
NS_DEFINE_NAMED_CID(TV_CHANNEL_DATA_CID);
NS_DEFINE_NAMED_CID(TV_PROGRAM_DATA_CID);
@ -1151,6 +1155,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kTELEPHONY_SERVICE_CID, false, nullptr, nsITelephonyServiceConstructor },
{ &kNS_MOBILE_CONNECTION_SERVICE_CID, false, NULL, nsIMobileConnectionServiceConstructor },
{ &kNS_VOICEMAIL_SERVICE_CID, false, nullptr, nsIVoicemailServiceConstructor },
{ &kFAKE_TV_SERVICE_CID, false, nullptr, FakeTVServiceConstructor },
{ &kTV_TUNER_DATA_CID, false, nullptr, TVTunerDataConstructor },
{ &kTV_CHANNEL_DATA_CID, false, nullptr, TVChannelDataConstructor },
{ &kTV_PROGRAM_DATA_CID, false, nullptr, TVProgramDataConstructor },
@ -1316,6 +1321,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ "@mozilla.org/accessibleRetrieval;1", &kNS_ACCESSIBILITY_SERVICE_CID },
#endif
{ TELEPHONY_SERVICE_CONTRACTID, &kTELEPHONY_SERVICE_CID },
{ FAKE_TV_SERVICE_CONTRACTID, &kFAKE_TV_SERVICE_CID },
{ TV_TUNER_DATA_CONTRACTID, &kTV_TUNER_DATA_CID },
{ TV_CHANNEL_DATA_CONTRACTID, &kTV_CHANNEL_DATA_CID },
{ TV_PROGRAM_DATA_CONTRACTID, &kTV_PROGRAM_DATA_CID },

View File

@ -472,9 +472,6 @@
@BINPATH@/components/PACGenerator.js
@BINPATH@/components/PACGenerator.manifest
@BINPATH@/components/TVSimulatorService.js
@BINPATH@/components/TVSimulatorService.manifest
; Modules
@BINPATH@/modules/*