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

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

Issue 1984133002: Move web-platform-tests to wpt (part 2 of 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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 type="text/javascript">
21 var test = async_test('Can send empty strings across a WebRTC data channel.');
22
23 var gFirstConnection = null;
24 var gSecondConnection = null;
25 var sendChannel = null;
26 var receiveChannel = null;
27
28 var onReceiveChannel = function (event) {
29 receiveChannel = event.channel;
30 receiveChannel.onmessage = onReceiveMessage;
31 };
32
33
34 // When the data channel is open, send an empty string message
35 // followed by a message that contains the string "done".
36 var onSendChannelOpen = function (event) {
37 var msgEl = document.getElementById('msg');
38 sendChannel.send('');
39 msgEl.innerHTML += 'Sent: [empty string]<br>';
40 sendChannel.send('done');
41 msgEl.innerHTML += 'Sent: "done"<br>';
42 };
43
44 // Check the messages received on the other side.
45 // There should be an empty string message followed by a message that
46 // contains the string "done".
47 // Pass/Fail the test according to the messages received
48 var emptyMessageReceived = false;
49 var onReceiveMessage = test.step_func(function (event) {
50 var msgEl = document.getElementById('msg');
51 msgEl.innerHTML += 'Received: ' +
52 (event.data ? '"' + event.data + '"' : '[empty string]') + '<br>';
53 if (emptyMessageReceived) {
54 assert_equals(event.data, 'done', 'The "done" message was not received');
55 test.done();
56 }
57 else {
58 assert_equals(event.data, '', 'Empty message not received');
59 emptyMessageReceived = true;
60 }
61 });
62
63 function exchangeIce(pc) {
64 return function(e) {
65 if (e.candidate) {
66 pc.addIceCandidate(e.candidate);
67 }
68 };
69 }
70
71 function exchangeDescription(pc1, pc2) {
72 return function() {
73 return pc1.setRemoteDescription(pc2.localDescription);
74 };
75 }
76
77 test.step(function() {
78 gFirstConnection = new RTCPeerConnection(null);
79
80 gSecondConnection = new RTCPeerConnection(null);
81
82 gFirstConnection.onicecandidate = exchangeIce(gSecondConnection);
83 gSecondConnection.onicecandidate = exchangeIce(gFirstConnection);
84
85 gSecondConnection.ondatachannel = onReceiveChannel;
86
87 // Note the data channel will preserve the order of messages
88 // exchanged over it by default.
89 sendChannel = gFirstConnection.createDataChannel('sendDataChannel');
90 sendChannel.onopen = onSendChannelOpen;
91
92 gFirstConnection.createOffer()
93 .then(gFirstConnection.setLocalDescription.bind(gFirstConnection))
94 .then(exchangeDescription(gSecondConnection, gFirstConnection))
95 .then(function() {
96 return gSecondConnection.createAnswer();
97 })
98 .then(gSecondConnection.setLocalDescription.bind(gSecondConnection))
99 .then(exchangeDescription(gFirstConnection, gSecondConnection))
100 .catch(test.step_func(function(e) {
101 assert_unreached('Error ' + e.name + ': ' + e.message);
102 }));
103 });
104 </script>
105
106 </body>
107 </html>
108
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698