-
Notifications
You must be signed in to change notification settings - Fork 54
/
RTCPeerConnection-setRemoteDescription-replaceTrack.https.html
145 lines (136 loc) · 5.25 KB
/
RTCPeerConnection-setRemoteDescription-replaceTrack.https.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!doctype html>
<meta charset=utf-8>
<title>RTCPeerConnection.prototype.setRemoteDescription - replaceTrack</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';
// The following helper functions are called from RTCPeerConnection-helper.js:
// getUserMediaTracksAndStreams
async_test(t => {
const caller = new RTCPeerConnection();
t.add_cleanup(() => caller.close());
return getUserMediaTracksAndStreams(2)
.then(t.step_func(([tracks, streams]) => {
const sender = caller.addTrack(tracks[0], streams[0]);
return sender.replaceTrack(tracks[1])
.then(t.step_func(() => {
assert_equals(sender.track, tracks[1]);
t.done();
}));
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'replaceTrack() sets the track attribute to a new track.');
async_test(t => {
const caller = new RTCPeerConnection();
t.add_cleanup(() => caller.close());
return getUserMediaTracksAndStreams(1)
.then(t.step_func(([tracks, streams]) => {
const sender = caller.addTrack(tracks[0], streams[0]);
return sender.replaceTrack(null)
.then(t.step_func(() => {
assert_equals(sender.track, null);
t.done();
}));
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'replaceTrack() sets the track attribute to null.');
async_test(t => {
const caller = new RTCPeerConnection();
t.add_cleanup(() => caller.close());
return getUserMediaTracksAndStreams(2)
.then(t.step_func(([tracks, streams]) => {
const sender = caller.addTrack(tracks[0], streams[0]);
assert_equals(sender.track, tracks[0]);
sender.replaceTrack(tracks[1]);
// replaceTrack() is asynchronous, there should be no synchronously
// observable effects.
assert_equals(sender.track, tracks[0]);
t.done();
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'replaceTrack() does not set the track synchronously.');
async_test(t => {
const expectedException = 'InvalidStateError';
const caller = new RTCPeerConnection();
t.add_cleanup(() => caller.close());
return getUserMediaTracksAndStreams(2)
.then(t.step_func(([tracks, streams]) => {
const sender = caller.addTrack(tracks[0], streams[0]);
caller.close();
return sender.replaceTrack(tracks[1])
.then(t.step_func(() => {
assert_unreached('Expected replaceTrack() to be rejected with ' +
expectedException + ' but the promise was resolved.');
}),
t.step_func(e => {
assert_equals(e.name, expectedException);
t.done();
}));
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'replaceTrack() rejects when the peer connection is closed.');
async_test(t => {
const expectedException = 'InvalidModificationError';
const caller = new RTCPeerConnection();
t.add_cleanup(() => caller.close());
return getUserMediaTracksAndStreams(2)
.then(t.step_func(([tracks, streams]) => {
const sender = caller.addTrack(tracks[0], streams[0]);
caller.removeTrack(sender);
// replaceTrack() should fail because the sender should be inactive after
// removeTrack().
return sender.replaceTrack(tracks[1])
.then(t.step_func(() => {
assert_unreached('Expected replaceTrack() to be rejected with ' +
expectedException + ' but the promise was resolved.');
}),
t.step_func(e => {
assert_equals(e.name, expectedException);
t.done();
}));
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'replaceTrack() rejects when invoked after removeTrack().');
async_test(t => {
const expectedException = 'InvalidModificationError';
const caller = new RTCPeerConnection();
t.add_cleanup(() => caller.close());
return getUserMediaTracksAndStreams(2)
.then(t.step_func(([tracks, streams]) => {
const sender = caller.addTrack(tracks[0], streams[0]);
let p = sender.replaceTrack(tracks[1])
caller.removeTrack(sender);
// replaceTrack() should fail because it executes steps in parallel and
// queues a task to execute after removeTrack() has occurred. The sender
// should be inactive. If this can be racy, update or remove the test.
// https://github.com/w3c/webrtc-pc/issues/1728
return p.then(t.step_func(() => {
assert_unreached('Expected replaceTrack() to be rejected with ' +
expectedException + ' but the promise was resolved.');
}),
t.step_func(e => {
assert_equals(e.name, expectedException);
t.done();
}));
}))
.catch(t.step_func(reason => {
assert_unreached(reason);
}));
}, 'replaceTrack() rejects after a subsequent removeTrack().');
// TODO(hbos): Verify that replaceTrack() changes what media is received on
// the remote end of two connected peer connections. For video tracks, this
// requires Chromium's video tag to update on receiving frames when running
// content_shell. https://crbug.com/793808
</script>