зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1264110 - fix timing issue in test cases. r=kershaw.
MozReview-Commit-ID: 2Ia4L7EizrA --HG-- extra : rebase_source : dda92d84e51a124d5820176d36cada7c20bfad2e
This commit is contained in:
Родитель
b3b4096aa2
Коммит
db74baa4e1
|
@ -463,7 +463,7 @@ PresentationService::HandleSessionRequest(nsIPresentationSessionRequest* aReques
|
|||
info->SetControlChannel(ctrlChannel);
|
||||
info->SetDevice(device);
|
||||
return static_cast<PresentationPresentingInfo*>(
|
||||
info.get())->NotifyResponderReady();
|
||||
info.get())->DoReconnect();
|
||||
}
|
||||
|
||||
// This is the case for a new session.
|
||||
|
|
|
@ -405,11 +405,16 @@ PresentationSessionInfo::ContinueTermination()
|
|||
NS_IMETHODIMP
|
||||
PresentationSessionInfo::NotifyTransportReady()
|
||||
{
|
||||
PRES_DEBUG("%s:id[%s], role[%d]\n", __func__,
|
||||
NS_ConvertUTF16toUTF8(mSessionId).get(), mRole);
|
||||
PRES_DEBUG("%s:id[%s], role[%d], state[%d]\n", __func__,
|
||||
NS_ConvertUTF16toUTF8(mSessionId).get(), mRole, mState);
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (mState != nsIPresentationSessionListener::STATE_CONNECTING &&
|
||||
mState != nsIPresentationSessionListener::STATE_CONNECTED) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mIsTransportReady = true;
|
||||
|
||||
// Established RTCDataChannel implies responder is ready.
|
||||
|
@ -484,11 +489,15 @@ PresentationSessionInfo::NotifyData(const nsACString& aData)
|
|||
NS_IMETHODIMP
|
||||
PresentationSessionInfo::OnSessionTransport(nsIPresentationSessionTransport* transport)
|
||||
{
|
||||
PRES_DEBUG("%s:id[%s], role[%d]\n", __func__,
|
||||
NS_ConvertUTF16toUTF8(mSessionId).get(), mRole);
|
||||
PRES_DEBUG("%s:id[%s], role[%d], state[%d]\n", __func__,
|
||||
NS_ConvertUTF16toUTF8(mSessionId).get(), mRole, mState);
|
||||
|
||||
SetBuilder(nullptr);
|
||||
|
||||
if (mState != nsIPresentationSessionListener::STATE_CONNECTING) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// The session transport is managed by content process
|
||||
if (!transport) {
|
||||
return NS_OK;
|
||||
|
@ -1195,6 +1204,7 @@ nsresult
|
|||
PresentationPresentingInfo::InitTransportAndSendAnswer()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mState == nsIPresentationSessionListener::STATE_CONNECTING);
|
||||
|
||||
uint8_t type = 0;
|
||||
nsresult rv = mRequesterDescription->GetType(&type);
|
||||
|
@ -1308,8 +1318,8 @@ PresentationPresentingInfo::IsAccessible(base::ProcessId aProcessId)
|
|||
nsresult
|
||||
PresentationPresentingInfo::NotifyResponderReady()
|
||||
{
|
||||
PRES_DEBUG("%s:id[%s], role[%d]\n", __func__,
|
||||
NS_ConvertUTF16toUTF8(mSessionId).get(), mRole);
|
||||
PRES_DEBUG("%s:id[%s], role[%d], state[%d]\n", __func__,
|
||||
NS_ConvertUTF16toUTF8(mSessionId).get(), mRole, mState);
|
||||
|
||||
if (mTimer) {
|
||||
mTimer->Cancel();
|
||||
|
@ -1344,6 +1354,19 @@ PresentationPresentingInfo::NotifyResponderFailure()
|
|||
return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
|
||||
}
|
||||
|
||||
nsresult
|
||||
PresentationPresentingInfo::DoReconnect()
|
||||
{
|
||||
PRES_DEBUG("%s:id[%s], role[%d]\n", __func__,
|
||||
NS_ConvertUTF16toUTF8(mSessionId).get(), mRole);
|
||||
|
||||
MOZ_ASSERT(mState == nsIPresentationSessionListener::STATE_CLOSED);
|
||||
|
||||
SetStateWithReason(nsIPresentationSessionListener::STATE_CONNECTING, NS_OK);
|
||||
|
||||
return NotifyResponderReady();
|
||||
}
|
||||
|
||||
// nsIPresentationControlChannelListener
|
||||
NS_IMETHODIMP
|
||||
PresentationPresentingInfo::OnOffer(nsIPresentationChannelDescription* aDescription)
|
||||
|
|
|
@ -254,6 +254,8 @@ public:
|
|||
|
||||
bool IsAccessible(base::ProcessId aProcessId) override;
|
||||
|
||||
nsresult DoReconnect();
|
||||
|
||||
private:
|
||||
~PresentationPresentingInfo()
|
||||
{
|
||||
|
|
|
@ -240,19 +240,19 @@ const mockedSessionTransport = {
|
|||
return this._selfAddress;
|
||||
},
|
||||
buildTCPSenderTransport: function(transport, listener) {
|
||||
sendAsyncMessage('data-transport-initialized');
|
||||
this._listener = listener;
|
||||
this._role = Ci.nsIPresentationService.ROLE_CONTROLLER;
|
||||
this._listener.onSessionTransport(this);
|
||||
this._listener = null;
|
||||
sendAsyncMessage('data-transport-initialized');
|
||||
|
||||
setTimeout(()=>{
|
||||
this._listener.onSessionTransport(this);
|
||||
this._listener = null;
|
||||
this.simulateTransportReady();
|
||||
}, 0);
|
||||
},
|
||||
buildTCPReceiverTransport: function(description, listener) {
|
||||
this._listener = listener;
|
||||
this._role = Ci.nsIPresentationService.ROLE_CONTROLLER;
|
||||
this._role = Ci.nsIPresentationService.ROLE_RECEIVER;
|
||||
|
||||
var addresses = description.QueryInterface(Ci.nsIPresentationChannelDescription).tcpAddress;
|
||||
this._selfAddress = {
|
||||
|
@ -269,7 +269,6 @@ const mockedSessionTransport = {
|
|||
},
|
||||
// in-process case
|
||||
buildDataChannelTransport: function(role, window, listener) {
|
||||
dump("PresentationSessionChromeScript: build data channel transport\n");
|
||||
this._listener = listener;
|
||||
this._role = role;
|
||||
|
||||
|
|
|
@ -42,318 +42,437 @@ function setup() {
|
|||
}
|
||||
|
||||
function testStartConnectionCancelPrompt() {
|
||||
return new Promise(function(aResolve, aReject) {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-cancel', SpecialPowers.Cr.NS_ERROR_DOM_NOT_ALLOWED_ERR);
|
||||
});
|
||||
|
||||
info('--- testStartConnectionCancelPrompt ---');
|
||||
return Promise.all([
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-cancel', SpecialPowers.Cr.NS_ERROR_DOM_NOT_ALLOWED_ERR);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
request.start().then(
|
||||
function(aConnection) {
|
||||
ok(false, "|start| shouldn't succeed in this case.");
|
||||
aReject();
|
||||
},
|
||||
function(aError) {
|
||||
is(aError.name, "NotAllowedError", "NotAllowedError is expected when the prompt is canceled.");
|
||||
aResolve();
|
||||
}
|
||||
);
|
||||
});
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
function testStartConnectionNoDevice() {
|
||||
return new Promise(function(aResolve, aReject) {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-cancel', SpecialPowers.Cr.NS_ERROR_DOM_NOT_FOUND_ERR);
|
||||
});
|
||||
|
||||
info('--- testStartConnectionNoDevice ---');
|
||||
return Promise.all([
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-cancel', SpecialPowers.Cr.NS_ERROR_DOM_NOT_FOUND_ERR);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
request.start().then(
|
||||
function(aConnection) {
|
||||
ok(false, "|start| shouldn't succeed in this case.");
|
||||
aReject();
|
||||
},
|
||||
function(aError) {
|
||||
is(aError.name, "NotFoundError", "NotFoundError is expected when no available device.");
|
||||
aResolve();
|
||||
}
|
||||
);
|
||||
});
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit() {
|
||||
return new Promise(function(aResolve, aReject) {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
});
|
||||
info('--- testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit ---');
|
||||
return Promise.all([
|
||||
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_ERROR_FAILURE);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
is(aReason, SpecialPowers.Cr.NS_ERROR_FAILURE, "The control channel is closed with NS_ERROR_FAILURE");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_ERROR_FAILURE);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
request.start().then(
|
||||
function(aConnection) {
|
||||
is(aConnection.state, "connecting", "The initial state should be connecting.");
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
aResolve();
|
||||
};
|
||||
return new Promise((resolve) => {
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
},
|
||||
function(aError) {
|
||||
ok(false, "Error occurred when establishing a connection: " + aError);
|
||||
teardown();
|
||||
aReject();
|
||||
}
|
||||
);
|
||||
});
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit() {
|
||||
return new Promise(function(aResolve, aReject) {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
});
|
||||
info('--- testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit ---');
|
||||
return Promise.all([
|
||||
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_OK);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed with NS_OK");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_OK);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
request.start().then(
|
||||
function(aConnection) {
|
||||
is(aConnection.state, "connecting", "The initial state should be connecting.");
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
aResolve();
|
||||
};
|
||||
return new Promise((resolve) => {
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
},
|
||||
function(aError) {
|
||||
ok(false, "Error occurred when establishing a connection: " + aError);
|
||||
teardown();
|
||||
aReject();
|
||||
}
|
||||
);
|
||||
});
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady() {
|
||||
return new Promise(function(aResolve, aReject) {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
});
|
||||
info('--- testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady ---');
|
||||
return Promise.all([
|
||||
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-incoming-transport');
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
is(aReason, SpecialPowers.Cr.NS_ERROR_ABORT, "The control channel is closed with NS_ERROR_ABORT");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
|
||||
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
|
||||
info("Data transport channel is initialized.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_ERROR_ABORT);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-incoming-transport');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
||||
info("The data transport is closed. " + aReason);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
|
||||
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
|
||||
info("Data transport channel is initialized.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_ERROR_ABORT);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
||||
info("The data transport is closed. " + aReason);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
request.start().then(
|
||||
function(aConnection) {
|
||||
is(aConnection.state, "connecting", "The initial state should be connecting.");
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
aResolve();
|
||||
};
|
||||
return new Promise((resolve) => {
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
},
|
||||
function(aError) {
|
||||
ok(false, "Error occurred when establishing a connection: " + aError);
|
||||
teardown();
|
||||
aReject();
|
||||
}
|
||||
);
|
||||
});
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady() {
|
||||
return new Promise(function(aResolve, aReject) {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
});
|
||||
info('--- testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady -- ');
|
||||
return Promise.all([
|
||||
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-incoming-transport');
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed with NS_OK");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
|
||||
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
|
||||
info("Data transport channel is initialized.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_OK);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-incoming-transport');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
||||
info("The data transport is closed. " + aReason);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
|
||||
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
|
||||
info("Data transport channel is initialized.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_OK);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
||||
info("The data transport is closed. " + aReason);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
request.start().then(
|
||||
function(aConnection) {
|
||||
is(aConnection.state, "connecting", "The initial state should be connecting.");
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
aResolve();
|
||||
};
|
||||
return new Promise((resolve) => {
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
},
|
||||
function(aError) {
|
||||
ok(false, "Error occurred when establishing a connection: " + aError);
|
||||
teardown();
|
||||
aReject();
|
||||
}
|
||||
);
|
||||
});
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
function testStartConnectionUnexpectedDataTransportClose() {
|
||||
return new Promise(function(aResolve, aReject) {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
});
|
||||
info('--- testStartConnectionUnexpectedDataTransportClose ---');
|
||||
return Promise.all([
|
||||
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
|
||||
gScript.removeMessageListener('device-prompt', devicePromptHandler);
|
||||
info("Device prompt is triggered.");
|
||||
gScript.sendAsyncMessage('trigger-device-prompt-select');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
|
||||
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
|
||||
info("A control channel is established.");
|
||||
gScript.sendAsyncMessage('trigger-control-channel-open');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
|
||||
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
||||
info("The control channel is opened.");
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
gScript.sendAsyncMessage('trigger-incoming-transport');
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
||||
info("The control channel is closed. " + aReason);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
|
||||
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
|
||||
info("Data transport channel is initialized.");
|
||||
gScript.sendAsyncMessage('trigger-data-transport-close', SpecialPowers.Cr.NS_ERROR_UNEXPECTED);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
|
||||
gScript.removeMessageListener('offer-sent', offerSentHandler);
|
||||
ok(aIsValid, "A valid offer is sent out.");
|
||||
info("recv offer-sent.");
|
||||
gScript.sendAsyncMessage('trigger-incoming-transport');
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
||||
info("The data transport is closed. " + aReason);
|
||||
});
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
|
||||
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
|
||||
info("Data transport channel is initialized.");
|
||||
gScript.sendAsyncMessage('trigger-data-transport-close', SpecialPowers.Cr.NS_ERROR_UNEXPECTED);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
new Promise((resolve) => {
|
||||
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
||||
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
||||
info("The data transport is closed. " + aReason);
|
||||
resolve();
|
||||
});
|
||||
}),
|
||||
|
||||
request.start().then(
|
||||
function(aConnection) {
|
||||
is(aConnection.state, "connecting", "The initial state should be connecting.");
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
aResolve();
|
||||
};
|
||||
return new Promise((resolve) => {
|
||||
aConnection.onclose = function() {
|
||||
aConnection.onclose = null;
|
||||
is(aConnection.state, "closed", "Connection should be closed.");
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
},
|
||||
function(aError) {
|
||||
ok(false, "Error occurred when establishing a connection: " + aError);
|
||||
teardown();
|
||||
aReject();
|
||||
}
|
||||
);
|
||||
});
|
||||
),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче