summaryrefslogtreecommitdiffstats
path: root/dom/presentation/tests/mochitest/test_presentation_tcp_sender_establish_connection_error.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/presentation/tests/mochitest/test_presentation_tcp_sender_establish_connection_error.html')
-rw-r--r--dom/presentation/tests/mochitest/test_presentation_tcp_sender_establish_connection_error.html514
1 files changed, 0 insertions, 514 deletions
diff --git a/dom/presentation/tests/mochitest/test_presentation_tcp_sender_establish_connection_error.html b/dom/presentation/tests/mochitest/test_presentation_tcp_sender_establish_connection_error.html
deleted file mode 100644
index 557ae71a6..000000000
--- a/dom/presentation/tests/mochitest/test_presentation_tcp_sender_establish_connection_error.html
+++ /dev/null
@@ -1,514 +0,0 @@
-<!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) {
- is(aAvailability.value, false, "Sender: should have no available device after setup");
- aAvailability.onchange = function() {
- aAvailability.onchange = null;
- ok(aAvailability.value, "Device should be available.");
- aResolve();
- }
-
- gScript.sendAsyncMessage('trigger-device-add');
- },
- function(aError) {
- ok(false, "Error occurred when getting availability: " + aError);
- teardown();
- aReject();
- }
- );
- });
-}
-
-function testStartConnectionCancelPrompt() {
- 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.");
- },
- function(aError) {
- is(aError.name, "NotAllowedError", "NotAllowedError is expected when the prompt is canceled.");
- }
- ),
- ]);
-}
-
-function testStartConnectionNoDevice() {
- 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.");
- },
- function(aError) {
- is(aError.name, "NotFoundError", "NotFoundError is expected when no available device.");
- }
- ),
- ]);
-}
-
-function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit() {
- info('--- testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit ---');
- 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-select');
- resolve();
- });
- }),
-
- 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();
- });
- }),
-
- new Promise((resolve) => {
- gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
- gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
- info("The control channel is opened.");
- resolve();
- });
- }),
-
- 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.");
- 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();
- }
- ),
-
- ]);
-}
-
-function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit() {
- info('--- testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit ---');
- 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-select');
- resolve();
- });
- }),
-
- 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();
- });
- }),
-
- new Promise((resolve) => {
- gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
- gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
- info("The control channel is opened.");
- resolve();
- });
- }),
-
- 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.");
- 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();
- }
- ),
-
- ]);
-}
-
-function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady() {
- info('--- testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady ---');
- 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-select');
- resolve();
- });
- }),
-
- 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();
- });
- }),
-
- new Promise((resolve) => {
- gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
- gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
- info("The control channel is opened.");
- resolve();
- });
- }),
-
- 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();
- });
- }),
-
- 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();
- });
- }),
-
- 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.");
- 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();
- }
- ),
-
- ]);
-}
-
-function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady() {
- info('--- testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady -- ');
- 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-select');
- resolve();
- });
- }),
-
- 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();
- });
- }),
-
- new Promise((resolve) => {
- gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
- gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
- info("The control channel is opened.");
- resolve();
- });
- }),
-
- 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-incoming-transport');
- resolve();
- });
- }),
-
- 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.");
- 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();
- }
- ),
-
- ]);
-}
-
-function testStartConnectionUnexpectedDataTransportClose() {
- info('--- testStartConnectionUnexpectedDataTransportClose ---');
- 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-select');
- resolve();
- });
- }),
-
- 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();
- });
- }),
-
- new Promise((resolve) => {
- gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
- gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
- info("The control channel is opened.");
- resolve();
- });
- }),
-
- 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();
- });
- }),
-
- 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();
- });
- }),
-
- 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.");
- 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();
- }
- ),
-
- ]);
-}
-
-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.");
-
- setup().
- then(testStartConnectionCancelPrompt).
- then(testStartConnectionNoDevice).
- then(testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit).
- then(testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit).
- then(testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady).
- then(testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady).
- then(testStartConnectionUnexpectedDataTransportClose).
- then(teardown);
-}
-
-SimpleTest.waitForExplicitFinish();
-SpecialPowers.pushPermissions([
- {type: 'presentation-device-manage', allow: false, context: document},
-], function() {
- SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
- ["dom.presentation.controller.enabled", true],
- ["dom.presentation.session_transport.data_channel.enable", false]]},
- runTests);
-});
-
-</script>
-</body>
-</html>