1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
8 description("Tests RTCDataChannel.");
15 function dc_onclose() {
16 testPassed("dc_onclose was called");
17 shouldBe("dc.readyState", "'closed'");
22 function dc_onmessage_dataview(e
) {
23 testPassed("dc_onmessage_dataview was called");
25 shouldBe("data.byteLength", "10");
26 array
= new Int8Array(e
.data
);
27 shouldBe("array[0]", "1");
28 shouldBe("array[9]", "10");
30 dc
.onclose
= dc_onclose
;
34 function dc_onmessage_arraybuffer(e
) {
35 testPassed("dc_onmessage_arraybuffer was called");
37 shouldBe("data.byteLength", "2");
38 array
= new Int8Array(e
.data
);
39 shouldBe("array[0]", "17");
40 shouldBe("array[1]", "19");
42 data
= new ArrayBuffer(12);
43 array
= new Int8Array(data
);
47 shouldBe("data.byteLength", "12");
49 shrunkView
= new DataView(data
, 1, 10);
51 dc
.onmessage
= dc_onmessage_dataview
;
52 shouldNotThrow("dc.send(shrunkView);");
55 function dc_onmessage_string(e
) {
56 testPassed("dc_onmessage_string was called");
58 shouldBe("data", "'xyzzy'");
60 dc
.binaryType
= "arraybuffer";
61 buffer
= new ArrayBuffer(2);
62 var array
= new Int8Array(buffer
);
65 dc
.onmessage
= dc_onmessage_arraybuffer
;
66 shouldNotThrow("dc.send(buffer);");
69 function dc_onopen() {
70 testPassed("dc_onopen was called");
71 shouldBe("dc.readyState", "'open'");
72 shouldBe("dc.label", "'label'");
74 dc
.onmessage
= dc_onmessage_string
;
75 shouldNotThrow("dc.send('xyzzy');");
78 function pc_ondatachannel(e
) {
79 testPassed("pc_ondatachannel was called");
82 function pc_onicechange() {
83 if (pc
.iceConnectionState
=== "completed") {
84 testPassed("pc is connected");
85 shouldNotThrow('dc = pc.createDataChannel("label");');
86 shouldBe("dc.readyState", "'connecting'");
87 dc
.onopen
= dc_onopen
;
91 pc
= new webkitRTCPeerConnection(null, null);
92 shouldNotThrow('dc = pc.createDataChannel("label1");');
93 shouldBe("dc.reliable", "true");
94 shouldNotThrow('dc = pc.createDataChannel("label2", {});');
95 shouldBe("dc.reliable", "true");
96 shouldNotThrow('dc = pc.createDataChannel("label3", {ordered:true});');
97 shouldBe("dc.reliable", "true");
98 shouldNotThrow('dc = pc.createDataChannel("label3", {ordered:false});');
99 shouldBe("dc.reliable", "false");
100 shouldNotThrow('dc = pc.createDataChannel("label3", {maxRetransmits:0});');
101 shouldBe("dc.reliable", "false");
102 shouldNotThrow('dc = pc.createDataChannel("label3", {maxRetransmitTime:0});');
103 shouldBe("dc.reliable", "false");
105 pc
= new webkitRTCPeerConnection(null, null);
106 pc
.oniceconnectionstatechange
= pc_onicechange
;
107 pc
.ondatachannel
= pc_ondatachannel
;
109 window
.jsTestIsAsync
= true;
110 window
.successfullyParsed
= true;