blob: 94e10dede58bea9acdb87be2d0f1c52fa346c476 [file] [log] [blame]
Philipp Hanckeb7014f72017-02-27 13:24:201<!doctype html>
Soares Chenfda87822017-06-05 14:00:302<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.setRemoteDescription</title>
4<script src="/resources/testharness.js"></script>
5<script src="/resources/testharnessreport.js"></script>
6<script src="RTCPeerConnection-helper.js"></script>
7<script>
Soares Chen0f176432017-05-04 04:40:478 'use strict';
9
Soares Chenfda87822017-06-05 14:00:3010 // Test is based on the following editor draft:
Soares Chena01b1e52017-07-07 09:52:0311 // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
Soares Chenfda87822017-06-05 14:00:3012
Rick Waldron1c5c05d2017-06-07 17:54:4213 // The following helper functions are called from RTCPeerConnection-helper.js:
14 // generateOffer()
15 // generateAnswer()
16 // assert_session_desc_not_equals()
17 // assert_session_desc_equals()
18 // test_state_change_event()
Rick Waldron1c5c05d2017-06-07 17:54:4219
Soares Chenfda87822017-06-05 14:00:3020 /*
Soares Chena01b1e52017-07-07 09:52:0321 4.3.2. Interface Definition
22 [Constructor(optional RTCConfiguration configuration)]
23 interface RTCPeerConnection : EventTarget {
24 Promise<void> setRemoteDescription(
25 RTCSessionDescriptionInit description);
26
27 readonly attribute RTCSessionDescription? remoteDescription;
28 readonly attribute RTCSessionDescription? currentRemoteDescription;
29 readonly attribute RTCSessionDescription? pendingRemoteDescription;
30 ...
31 };
32
33 4.6.2. RTCSessionDescription Class
34 dictionary RTCSessionDescriptionInit {
35 required RTCSdpType type;
36 DOMString sdp = "";
37 };
38
39 4.6.1. RTCSdpType
40 enum RTCSdpType {
41 "offer",
42 "pranswer",
43 "answer",
44 "rollback"
45 };
Soares Chenfda87822017-06-05 14:00:3046 */
47
Soares Chena01b1e52017-07-07 09:52:0348 /*
Soares Chena01b1e52017-07-07 09:52:0349 4.6.1. enum RTCSdpType
Soares Chenfda87822017-06-05 14:00:3050 */
51 promise_test(t => {
52 const pc = new RTCPeerConnection();
53
54 // SDP is validated after WebIDL validation
55 return promise_rejects(t, new TypeError(),
56 pc.setRemoteDescription({
57 type: 'bogus',
58 sdp: 'bogus'
59 }));
60 }, 'setRemoteDescription with invalid type and invalid SDP should reject with TypeError')
61
62 promise_test(t => {
63 const pc = new RTCPeerConnection();
64
65 // SDP is validated after validating type
66 return promise_rejects(t, 'InvalidStateError',
67 pc.setRemoteDescription({
68 type: 'answer',
69 sdp: 'invalid'
70 }));
71 }, 'setRemoteDescription() with invalid SDP and stable state should reject with InvalidStateError')
72
Soares Chena01b1e52017-07-07 09:52:0373 /* Operations after returning to stable state */
Soares Chenfda87822017-06-05 14:00:3074
75 promise_test(t => {
76 const pc = new RTCPeerConnection();
77 const pc2 = new RTCPeerConnection();
78
79 test_state_change_event(t, pc,
80 ['have-remote-offer', 'stable', 'have-remote-offer']);
81
82 return generateOffer({ audio: true })
83 .then(offer1 =>
84 pc.setRemoteDescription(offer1)
85 .then(() => pc.createAnswer())
86 .then(answer => pc.setLocalDescription(answer))
87 .then(() => generateOffer({ data: true }))
88 .then(offer2 =>
89 pc.setRemoteDescription(offer2)
90 .then(() => {
91 assert_equals(pc.signalingState, 'have-remote-offer');
92 assert_session_desc_not_equals(offer1, offer2);
93 assert_session_desc_equals(pc.remoteDescription, offer2);
94 assert_session_desc_equals(pc.currentRemoteDescription, offer1);
95 assert_session_desc_equals(pc.pendingRemoteDescription, offer2);
96 })));
97 }, 'Calling setRemoteDescription() again after one round of remote-offer/local-answer should succeed');
98
99 promise_test(t => {
100 const pc = new RTCPeerConnection();
101
102 test_state_change_event(t, pc,
103 ['have-local-offer', 'stable', 'have-remote-offer']);
104
105 return pc.createOffer({ offerToReceiveAudio: true })
106 .then(offer =>
107 pc.setLocalDescription(offer)
108 .then(() => generateAnswer(offer)))
109 .then(answer =>
110 pc.setRemoteDescription(answer)
111 .then(() => generateOffer({ data: true }))
112 .then(offer =>
113 pc.setRemoteDescription(offer)
114 .then(() => {
115 assert_equals(pc.signalingState, 'have-remote-offer');
116 assert_session_desc_equals(pc.remoteDescription, offer);
117 assert_session_desc_equals(pc.currentRemoteDescription, answer);
118 assert_session_desc_equals(pc.pendingRemoteDescription, offer);
119 })));
120 }, 'Switching role from offerer to answerer after going back to stable state should succeed');
121
122 /*
Soares Chena01b1e52017-07-07 09:52:03123 TODO
124 4.3.2. setRemoteDescription
125 - If an a=identity attribute is present in the session description, the browser
126 validates the identity assertion.
127 */
Soares Chen0f176432017-05-04 04:40:47128
Philipp Hanckeb7014f72017-02-27 13:24:20129</script>