mirror of
https://github.com/classilla/tenfourfox.git
synced 2025-01-19 07:31:25 +00:00
116 lines
2.9 KiB
HTML
116 lines
2.9 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test for B2G PresentationReceiver at receiver side (OOP)</title>
|
|
</head>
|
|
<body>
|
|
<div id="content"></div>
|
|
<script type="application/javascript;version=1.7">
|
|
|
|
"use strict";
|
|
|
|
function is(a, b, msg) {
|
|
alert((a === b ? 'OK ' : 'KO ') + msg);
|
|
}
|
|
|
|
function ok(a, msg) {
|
|
alert((a ? 'OK ' : 'KO ') + msg);
|
|
}
|
|
|
|
function info(msg) {
|
|
alert('INFO ' + msg);
|
|
}
|
|
|
|
function command(msg) {
|
|
alert('COMMAND ' + JSON.stringify(msg));
|
|
}
|
|
|
|
function finish() {
|
|
alert('DONE');
|
|
}
|
|
|
|
var connection;
|
|
|
|
function testConnectionAvailable() {
|
|
return new Promise(function(aResolve, aReject) {
|
|
ok(navigator.presentation, "navigator.presentation should be available in OOP receiving pages.");
|
|
ok(navigator.presentation.receiver, "navigator.presentation.receiver should be available in OOP receiving pages.");
|
|
|
|
navigator.presentation.receiver.getConnection().then(
|
|
function(aConnection) {
|
|
connection = aConnection;
|
|
|
|
ok(connection.id, "Connection ID should be set: " + connection.id);
|
|
is(connection.state, "closed", "Connection state at receiver side should be closed by default.");
|
|
aResolve();
|
|
},
|
|
function(aError) {
|
|
ok(false, "Error occurred when getting the connection: " + aError);
|
|
finish();
|
|
aReject();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
function testConnectionAvailableInnerIframe() {
|
|
return new Promise(function(aResolve, aReject) {
|
|
var iframe = document.createElement('iframe');
|
|
iframe.setAttribute('src', './file_presentation_receiver_inner_iframe_oop.html');
|
|
document.body.appendChild(iframe);
|
|
|
|
aResolve();
|
|
});
|
|
}
|
|
|
|
function testConnectionReady() {
|
|
return new Promise(function(aResolve, aReject) {
|
|
connection.onstatechange = function() {
|
|
connection.onstatechange = null;
|
|
is(connection.state, "connected", "Connection state should become connected.");
|
|
aResolve();
|
|
};
|
|
|
|
command({ name: 'trigger-incoming-offer' });
|
|
});
|
|
}
|
|
|
|
function testIncomingMessage() {
|
|
return new Promise(function(aResolve, aReject) {
|
|
const incomingMessage = "test incoming message";
|
|
|
|
connection.addEventListener('message', function messageHandler(aEvent) {
|
|
connection.removeEventListener('message', messageHandler);
|
|
is(aEvent.data, incomingMessage, "An incoming message should be received.");
|
|
aResolve();
|
|
});
|
|
|
|
command({ name: 'trigger-incoming-message',
|
|
data: incomingMessage });
|
|
});
|
|
}
|
|
|
|
function testTerminateConnection() {
|
|
return new Promise(function(aResolve, aReject) {
|
|
connection.onstatechange = function() {
|
|
connection.onstatechange = null;
|
|
is(connection.state, "terminated", "Connection should be terminated.");
|
|
aResolve();
|
|
};
|
|
|
|
connection.terminate();
|
|
});
|
|
}
|
|
|
|
testConnectionAvailable().
|
|
then(testConnectionAvailableInnerIframe).
|
|
then(testConnectionReady).
|
|
then(testIncomingMessage).
|
|
then(testTerminateConnection).
|
|
then(finish);
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|