64ecb8090e205041d057627c459fc3fbb73a0ad5
[WebKit-https.git] / LayoutTests / webrtc / datachannel / mdns-ice-candidates.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>Testing basic data channel from offerer to receiver with MDNS ICE Candidates</title>
6     <script src="../../resources/testharness.js"></script>
7     <script src="../../resources/testharnessreport.js"></script>
8   </head>
9   <body>
10     <script src ="../routines.js"></script>
11     <script>
12 if (window.testRunner)
13     testRunner.setWebRTCMDNSICECandidatesEnabled(true);
14 if (window.internals)
15     internals.setICECandidateFiltering(true);
16
17 var localChannel;
18 var remoteChannel;
19
20 function closeDataChannels() {
21     localChannel.close();
22     remoteChannel.close();
23     closeConnections();
24 }
25
26 function receiveMessages(event) {
27 try {
28     if (++counter === 1)
29         assert_equals(event.data, "one");
30     else if (counter === 2)
31         assert_equals(event.data, "two");
32     else if (counter === 3)
33         assert_equals(event.data, "three");
34     else if (counter === 4) {
35         assert_equals(event.data, "four");
36         closeDataChannels();
37         finishTest();
38     } else
39         assert_unreached();
40 } catch(e) {
41     console.log(e);
42 }
43 }
44
45 function sendMessages(channel)
46 {
47     channel.send("one");
48     channel.send("two");
49     channel.send("three");
50     channel.send("four");
51 }
52
53 promise_test((test) => {
54     return new Promise((resolve, reject) => {
55         createConnections((localConnection) => {
56             localConnection.createDataChannel('sendDataChannel');
57         }, () => {
58         }, {
59             filterOutICECandidate: (candidate) => {
60                 if (candidate && candidate.candidate.toLowerCase().indexOf("host") !== -1)
61                     assert_true(candidate.candidate.indexOf(".local") !== -1);
62                 if (!candidate)
63                     resolve();
64                 return false;
65             }
66         });
67         setTimeout(() => { reject("Test timed out"); }, 5000);
68     });
69 }, "Getting some MDNS candidates");
70
71 var finishTest;
72 promise_test((test) => {
73     counter = 0;
74     return new Promise((resolve, reject) => {
75         finishTest = resolve;
76         createConnections((localConnection) => {
77             localChannel = localConnection.createDataChannel('sendDataChannel');
78             localChannel.onopen = () => { sendMessages(localChannel) };
79         }, (remoteConnection) => {
80             remoteConnection.ondatachannel = (event) => {
81                 remoteChannel = event.channel;
82                 remoteChannel.onmessage = receiveMessages;
83             };
84         });
85         setTimeout(() => { reject("Test timed out"); }, 5000);
86     });
87 }, "Basic data channel exchange from offerer to receiver");
88
89 promise_test((test) => {
90     counter = 0;
91     return new Promise((resolve, reject) => {
92         finishTest = resolve;
93         createConnections((localConnection) => {
94             localChannel = localConnection.createDataChannel('sendDataChannel');
95             localChannel.onmessage = receiveMessages;
96         }, (remoteConnection) => {
97             remoteConnection.ondatachannel = (event) => {
98                 remoteChannel = event.channel;
99                 remoteChannel.onopen = () => { sendMessages(remoteChannel) };
100             };
101         });
102         setTimeout(() => { reject("Test timed out"); }, 5000);
103     });
104 }, "Basic data channel exchange from receiver to offerer");
105
106
107 promise_test((test) => {
108     counter = 0;
109     return new Promise((resolve, reject) => {
110         finishTest = resolve;
111         createConnections((localConnection) => {
112             localChannel = localConnection.createDataChannel('sendDataChannel');
113             localChannel.onopen = () => { sendMessages(localChannel) };
114         }, (remoteConnection) => {
115             remoteConnection.ondatachannel = (event) => {
116                 remoteChannel = event.channel;
117                 remoteChannel.onmessage = receiveMessages;
118             };
119         }, { filterOutICECandidate: (candidate) => { return candidate && candidate.candidate.toLowerCase().indexOf("udp") == -1; } });
120         setTimeout(() => { reject("Test timed out"); }, 5000);
121     });
122 }, "Basic data channel exchange from offerer to receiver using UDP only");
123
124 promise_test((test) => {
125     counter = 0;
126     return new Promise((resolve, reject) => {
127         var checkDataChannelOptions = (channel, init) => {
128             assert_equals(channel.ordered, init.ordered, "ordered");
129             assert_equals(channel.maxPacketLifeTime, init.maxPacketLifeTime, "maxPacketLifeTime");
130             assert_equals(channel.maxRetransmitTime, init.maxRetransmitTime, "maxRetransmitTime");
131             assert_equals(channel.maxRetransmits, init.maxRetransmits, "maxRetransmits");
132             assert_equals(channel.protocol, init.protocol, "protocol");
133             assert_equals(channel.negotiated, init.negotiated, "negotiated");
134             assert_equals(channel.id, init.id, "id");
135         };
136
137         finishTest = resolve;
138         createConnections((localConnection) => {
139             var init = { ordered: true, maxPacketLifeTime: 10, maxRetransmitTime: 11, protocol: "whatever", negotiated: false, id: 1 };
140             localChannel = localConnection.createDataChannel('sendDataChannel', init);
141             localChannel.onopen = () => { sendMessages(localChannel) };
142         }, (remoteConnection) => {
143             remoteConnection.ondatachannel = (event) => {
144                 remoteChannel = event.channel;
145                 remoteChannel.onmessage = receiveMessages;
146             };
147         });
148         setTimeout(() => { reject("Test timed out"); }, 5000);
149     });
150 }, "Basic data channel exchange from offerer to receiver");
151
152     </script>
153   </body>
154 </html>