mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-06-25 20:29:33 +00:00
362 lines
15 KiB
HTML
362 lines
15 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!-- Any copyright is dedicated to the Public Domain.
|
|
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test for connection establishing errors of B2G Presentation API at sender side</title>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for connection establishing errors of B2G Presentation API at sender side</a>
|
|
<script type="application/javascript;version=1.8">
|
|
|
|
'use strict';
|
|
|
|
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
|
|
var request;
|
|
|
|
function setup() {
|
|
return new Promise(function(aResolve, aReject) {
|
|
request = new PresentationRequest("http://example.com");
|
|
|
|
request.getAvailability().then(
|
|
function(aAvailability) {
|
|
aAvailability.onchange = function() {
|
|
aAvailability.onchange = null;
|
|
ok(aAvailability.value, "Device should be available.");
|
|
aResolve();
|
|
}
|
|
},
|
|
function(aError) {
|
|
ok(false, "Error occurred when getting availability: " + aError);
|
|
teardown();
|
|
aReject();
|
|
}
|
|
);
|
|
|
|
gScript.sendAsyncMessage('trigger-device-add');
|
|
});
|
|
}
|
|
|
|
function testCreateRequestWithEmptyURL() {
|
|
return new Promise(function(aResolve, aReject) {
|
|
try {
|
|
request = new PresentationRequest("");
|
|
} catch (aError) {
|
|
is(aError.name, "SyntaxError", "SyntaxError is expected when using an empty URL.");
|
|
aResolve();
|
|
}
|
|
});
|
|
}
|
|
|
|
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');
|
|
});
|
|
|
|
request.start().then(
|
|
function(aConnection) {
|
|
ok(false, "|start| shouldn't succeed in this case.");
|
|
aReject();
|
|
},
|
|
function(aError) {
|
|
is(aError.name, "AbortError", "AbortError is expected when the prompt is canceled.");
|
|
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');
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
|
info("The control channel is opened.");
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
|
info("The control channel is closed. " + aReason);
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
request.start().then(
|
|
function(aConnection) {
|
|
ok(false, "|start| shouldn't succeed in this case.");
|
|
aReject();
|
|
},
|
|
function(aError) {
|
|
is(aError.name, "OperationError", "OperationError is expected when a connection error happens during establishing a connection.");
|
|
aResolve();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
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');
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
|
info("The control channel is opened.");
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
|
info("The control channel is closed. " + aReason);
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
request.start().then(
|
|
function(aConnection) {
|
|
ok(false, "|start| shouldn't succeed in this case.");
|
|
aReject();
|
|
},
|
|
function(aError) {
|
|
is(aError.name, "OperationError", "OperationError is expected when a connection closed during establishing a connection.");
|
|
aResolve();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
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');
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
|
info("The control channel is opened.");
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
|
info("The control channel is closed. " + aReason);
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
|
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
|
info("The data transport is closed. " + aReason);
|
|
});
|
|
|
|
request.start().then(
|
|
function(aConnection) {
|
|
ok(false, "|start| shouldn't succeed in this case.");
|
|
aReject();
|
|
},
|
|
function(aError) {
|
|
is(aError.name, "OperationError", "OperationError is expected when a connection error happens during establishing a connection.");
|
|
aResolve();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
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');
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
|
info("The control channel is opened.");
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
|
info("The control channel is closed. " + aReason);
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
|
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
|
info("The data transport is closed. " + aReason);
|
|
});
|
|
|
|
request.start().then(
|
|
function(aConnection) {
|
|
ok(false, "|start| shouldn't succeed in this case.");
|
|
aReject();
|
|
},
|
|
function(aError) {
|
|
is(aError.name, "OperationError", "OperationError is expected when a connection closed during establishing a connection.");
|
|
aResolve();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
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');
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
|
|
info("The control channel is opened.");
|
|
});
|
|
|
|
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
|
|
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
|
|
info("The control channel is closed. " + aReason);
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
|
|
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
|
|
info("The data transport is closed. " + aReason);
|
|
});
|
|
|
|
request.start().then(
|
|
function(aConnection) {
|
|
ok(false, "|start| shouldn't succeed in this case.");
|
|
aReject();
|
|
},
|
|
function(aError) {
|
|
is(aError.name, "OperationError", "OperationError is expected when a connection error happens during establishing a connection.");
|
|
aResolve();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
function teardown() {
|
|
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
|
|
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
|
|
gScript.destroy();
|
|
SimpleTest.finish();
|
|
});
|
|
|
|
gScript.sendAsyncMessage('teardown');
|
|
}
|
|
|
|
function runTests() {
|
|
ok(window.PresentationRequest, "PresentationRequest should be available.");
|
|
|
|
testCreateRequestWithEmptyURL().
|
|
then(setup).
|
|
then(testStartConnectionCancelPrompt).
|
|
then(testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit).
|
|
then(testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit).
|
|
then(testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady).
|
|
then(testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady).
|
|
then(testStartConnectionUnexpectedDataTransportClose).
|
|
then(teardown);
|
|
}
|
|
|
|
SimpleTest.expectAssertions(0, 5);
|
|
SimpleTest.waitForExplicitFinish();
|
|
SpecialPowers.pushPermissions([
|
|
{type: 'presentation-device-manage', allow: false, context: document},
|
|
{type: 'presentation', allow: true, context: document},
|
|
], function() {
|
|
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
|
|
["dom.presentation.test.enabled", true],
|
|
["dom.presentation.test.stage", 0]]},
|
|
runTests);
|
|
});
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|