mirror of
https://github.com/servo/servo.git
synced 2025-08-11 08:25:32 +01:00
Update web-platform-tests to revision 4d96cccabc2feacd48e1dab9afc22b8af2225572
This commit is contained in:
parent
0d236288cc
commit
c66c6af0ba
1067 changed files with 63768 additions and 10900 deletions
113
tests/wpt/web-platform-tests/webrtc/datachannel-emptystring.html
Normal file
113
tests/wpt/web-platform-tests/webrtc/datachannel-emptystring.html
Normal file
|
@ -0,0 +1,113 @@
|
|||
<!doctype html>
|
||||
<!--
|
||||
This test creates a data channel between two local PeerConnection instances
|
||||
and ensures that an empty string sent by one is received by the second.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>RTCPeerConnection Data Channel Empty String Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="log"></div>
|
||||
<h2>Messages exchanged</h2>
|
||||
<div id="msg"></div>
|
||||
|
||||
<!-- These files are in place when executing on W3C. -->
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/vendor-prefix.js"
|
||||
data-prefixed-objects=
|
||||
'[{"ancestors":["window"], "name":"RTCPeerConnection"}]'
|
||||
>
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var test = async_test('Can send empty strings across a WebRTC data channel.');
|
||||
|
||||
var gFirstConnection = null;
|
||||
var gSecondConnection = null;
|
||||
var sendChannel = null;
|
||||
var receiveChannel = null;
|
||||
|
||||
var onReceiveChannel = function (event) {
|
||||
receiveChannel = event.channel;
|
||||
receiveChannel.onmessage = onReceiveMessage;
|
||||
};
|
||||
|
||||
|
||||
// When the data channel is open, send an empty string message
|
||||
// followed by a message that contains the string "done".
|
||||
var onSendChannelOpen = function (event) {
|
||||
var msgEl = document.getElementById('msg');
|
||||
sendChannel.send('');
|
||||
msgEl.innerHTML += 'Sent: [empty string]<br>';
|
||||
sendChannel.send('done');
|
||||
msgEl.innerHTML += 'Sent: "done"<br>';
|
||||
};
|
||||
|
||||
// Check the messages received on the other side.
|
||||
// There should be an empty string message followed by a message that
|
||||
// contains the string "done".
|
||||
// Pass/Fail the test according to the messages received
|
||||
var emptyMessageReceived = false;
|
||||
var onReceiveMessage = test.step_func(function (event) {
|
||||
var msgEl = document.getElementById('msg');
|
||||
msgEl.innerHTML += 'Received: ' +
|
||||
(event.data ? '"' + event.data + '"' : '[empty string]') + '<br>';
|
||||
if (emptyMessageReceived) {
|
||||
assert_equals(event.data, 'done', 'The "done" message was not received');
|
||||
test.done();
|
||||
}
|
||||
else {
|
||||
assert_equals(event.data, '', 'Empty message not received');
|
||||
emptyMessageReceived = true;
|
||||
}
|
||||
});
|
||||
|
||||
function exchangeIce(pc) {
|
||||
return function(e) {
|
||||
if (e.candidate) {
|
||||
pc.addIceCandidate(e.candidate);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function exchangeDescription(pc1, pc2) {
|
||||
return function() {
|
||||
return pc1.setRemoteDescription(pc2.localDescription);
|
||||
};
|
||||
}
|
||||
|
||||
test.step(function() {
|
||||
gFirstConnection = new RTCPeerConnection(null);
|
||||
|
||||
gSecondConnection = new RTCPeerConnection(null);
|
||||
|
||||
gFirstConnection.onicecandidate = exchangeIce(gSecondConnection);
|
||||
gSecondConnection.onicecandidate = exchangeIce(gFirstConnection);
|
||||
|
||||
gSecondConnection.ondatachannel = onReceiveChannel;
|
||||
|
||||
// Note the data channel will preserve the order of messages
|
||||
// exchanged over it by default.
|
||||
sendChannel = gFirstConnection.createDataChannel('sendDataChannel');
|
||||
sendChannel.onopen = onSendChannelOpen;
|
||||
|
||||
gFirstConnection.createOffer()
|
||||
.then(gFirstConnection.setLocalDescription.bind(gFirstConnection))
|
||||
.then(exchangeDescription(gSecondConnection, gFirstConnection))
|
||||
.then(function() {
|
||||
return gSecondConnection.createAnswer();
|
||||
})
|
||||
.then(gSecondConnection.setLocalDescription.bind(gSecondConnection))
|
||||
.then(exchangeDescription(gFirstConnection, gSecondConnection))
|
||||
.catch(test.step_func(function(e) {
|
||||
assert_unreached('Error ' + e.name + ': ' + e.message);
|
||||
}));
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue