Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: LayoutTests/imported/web-platform-tests/webrtc/datachannel-emptystring.html

Issue 1188583004: update-w3c-deps import using blink 9d3793ee56e5bb1aa1eef078d848e1b0e6e4d355: (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!doctype html>
2 <!--
3 This test creates a data channel between two local PeerConnection instances
4 and ensures that an empty string sent by one is received by the second.
5 -->
6
7 <html>
8 <head>
9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
10 <title>RTCPeerConnection Data Channel Empty String Test</title>
11 </head>
12 <body>
13 <div id="log"></div>
14 <h2>Messages exchanged</h2>
15 <div id="msg"></div>
16
17 <!-- These files are in place when executing on W3C. -->
18 <script src="../../../resources/testharness.js"></script>
19 <script src="../../../resources/testharnessreport.js"></script>
20 <script src="../../../resources/vendor-prefix.js"
21 data-prefixed-objects=
22 '[{"ancestors":["window"], "name":"RTCPeerConnection"}]'
23 >
24 </script>
25 <script type="text/javascript">
26 var test = async_test('Can send empty strings across a WebRTC data channel.');
27
28 var gFirstConnection = null;
29 var gSecondConnection = null;
30 var sendChannel = null;
31 var receiveChannel = null;
32
33 var onReceiveChannel = function (event) {
34 receiveChannel = event.channel;
35 receiveChannel.onmessage = onReceiveMessage;
36 };
37
38
39 // When the data channel is open, send an empty string message
40 // followed by a message that contains the string "done".
41 var onSendChannelOpen = function (event) {
42 var msgEl = document.getElementById('msg');
43 sendChannel.send('');
44 msgEl.innerHTML += 'Sent: [empty string]<br>';
45 sendChannel.send('done');
46 msgEl.innerHTML += 'Sent: "done"<br>';
47 };
48
49 // Check the messages received on the other side.
50 // There should be an empty string message followed by a message that
51 // contains the string "done".
52 // Pass/Fail the test according to the messages received
53 var emptyMessageReceived = false;
54 var onReceiveMessage = test.step_func(function (event) {
55 var msgEl = document.getElementById('msg');
56 msgEl.innerHTML += 'Received: ' +
57 (event.data ? '"' + event.data + '"' : '[empty string]') + '<br>';
58 if (emptyMessageReceived) {
59 assert_equals(event.data, 'done', 'The "done" message was not received');
60 test.done();
61 }
62 else {
63 assert_equals(event.data, '', 'Empty message not received');
64 emptyMessageReceived = true;
65 }
66 });
67
68 function exchangeIce(pc) {
69 return function(e) {
70 if (e.candidate) {
71 pc.addIceCandidate(e.candidate);
72 }
73 };
74 }
75
76 function exchangeDescription(pc1, pc2) {
77 return function() {
78 return pc1.setRemoteDescription(pc2.localDescription);
79 };
80 }
81
82 test.step(function() {
83 gFirstConnection = new RTCPeerConnection(null);
84
85 gSecondConnection = new RTCPeerConnection(null);
86
87 gFirstConnection.onicecandidate = exchangeIce(gSecondConnection);
88 gSecondConnection.onicecandidate = exchangeIce(gFirstConnection);
89
90 gSecondConnection.ondatachannel = onReceiveChannel;
91
92 // Note the data channel will preserve the order of messages
93 // exchanged over it by default.
94 sendChannel = gFirstConnection.createDataChannel('sendDataChannel');
95 sendChannel.onopen = onSendChannelOpen;
96
97 gFirstConnection.createOffer()
98 .then(gFirstConnection.setLocalDescription.bind(gFirstConnection))
99 .then(exchangeDescription(gSecondConnection, gFirstConnection))
100 .then(function() {
101 return gSecondConnection.createAnswer();
102 })
103 .then(gSecondConnection.setLocalDescription.bind(gSecondConnection))
104 .then(exchangeDescription(gFirstConnection, gSecondConnection))
105 .catch(test.step_func(function(e) {
106 assert_unreached('Error ' + e.name + ': ' + e.message);
107 }));
108 });
109 </script>
110
111 </body>
112 </html>
113
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698