Bug 1610422 part 1. Pull in missing upstream changes for RTCPeerConnection-ondatachannel.html. r=jgraham

It looks like most of the changes from
https://github.com/web-platform-tests/wpt/pull/16038 we have already, except
some whitespace bits.

Differential Revision: https://phabricator.services.mozilla.com/D60469

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2020-01-21 11:16:41 +00:00
Родитель 12ffabd93a
Коммит 5f84a2e9df
1 изменённых файлов: 70 добавлений и 0 удалений

Просмотреть файл

@ -6,12 +6,15 @@
<script src="RTCPeerConnection-helper.js"></script>
<script>
'use strict';
// Test is based on the following revision:
// https://rawgit.com/w3c/webrtc-pc/1cc5bfc3ff18741033d804c4a71f7891242fb5b3/webrtc.html
// The following helper functions are called from RTCPeerConnection-helper.js:
// exchangeIceCandidates
// doSignalingHandshake
// createDataChannelPair
/*
6.2. RTCDataChannel
When an underlying data transport is to be announced (the other peer created a channel with
@ -20,11 +23,13 @@
2. Let channel be a newly created RTCDataChannel object.
7. Set channel's [[ReadyState]] to open (but do not fire the open event, yet).
8. Fire a datachannel event named datachannel with channel at the RTCPeerConnection object.
6.3. RTCDataChannelEvent
Firing a datachannel event named e with an RTCDataChannel channel means that an event with the
name e, which does not bubble (except where otherwise stated) and is not cancelable (except
where otherwise stated), and which uses the RTCDataChannelEvent interface with the channel
attribute set to channel, MUST be created and dispatched at the given target.
interface RTCDataChannelEvent : Event {
readonly attribute RTCDataChannel channel;
};
@ -35,29 +40,40 @@ promise_test(async (t) => {
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
let eventCount = 0;
pc2.ondatachannel = t.step_func((event) => {
eventCount++;
assert_equals(eventCount, 1,
'Expect data channel event to fire exactly once');
assert_true(event instanceof RTCDataChannelEvent,
'Expect event to be instance of RTCDataChannelEvent');
assert_equals(event.bubbles, false);
assert_equals(event.cancelable, false);
const dc = event.channel;
assert_true(dc instanceof RTCDataChannel,
'Expect channel to be instance of RTCDataChannel');
// The channel should be in the 'open' state already.
// See: https://github.com/w3c/webrtc-pc/pull/1851
assert_equals(dc.readyState, 'open',
'Expect channel ready state to be open');
resolver.resolve();
});
pc1.createDataChannel('fire-me!');
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
await resolver;
}, 'Data channel event should fire when new data channel is announced to the remote peer');
/*
Since the channel should be in the 'open' state when dispatching via the 'datachannel' event,
we should be able to send data in the event handler.
@ -68,21 +84,28 @@ promise_test(async (t) => {
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
const message = 'meow meow!';
pc2.ondatachannel = t.step_func((event) => {
const dc2 = event.channel;
dc2.send(message);
});
const dc1 = pc1.createDataChannel('fire-me!');
dc1.onmessage = t.step_func((event) => {
assert_equals(event.data, message,
'Received data should be equal to sent data');
resolver.resolve();
});
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
await resolver;
}, 'Should be able to send data in a datachannel event handler');
/*
6.2. RTCDataChannel
When an underlying data transport is to be announced (the other peer created a channel with
@ -97,21 +120,28 @@ promise_test(async (t) => {
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
pc2.ondatachannel = t.step_func((event) => {
const dc = event.channel;
dc.onopen = t.step_func(() => {
assert_unreached('Open event should not fire');
});
// This should prevent triggering the 'open' event
dc.close();
// Wait a bit to ensure the 'open' event does NOT fire
t.step_timeout(() => resolver.resolve(), 500);
});
pc1.createDataChannel('fire-me!');
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
await resolver;
}, 'Open event should not be raised when closing the channel in the datachannel event');
// Added this test as a result of the discussion in
// https://github.com/w3c/webrtc-pc/pull/1851#discussion_r185976747
promise_test(async (t) => {
@ -120,11 +150,13 @@ promise_test(async (t) => {
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
pc2.ondatachannel = t.step_func((event) => {
const dc = event.channel;
dc.onopen = t.step_func((event) => {
resolver.resolve();
});
// This should NOT prevent triggering the 'open' event since it enqueues at least two tasks
t.step_timeout(() => {
t.step_timeout(() => {
@ -132,12 +164,17 @@ promise_test(async (t) => {
}, 1);
}, 1);
});
pc1.createDataChannel('fire-me!');
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
await resolver;
}, 'Open event should be raised when closing the channel in the datachannel event after ' +
'enqueuing a task');
/*
Combination of the two tests above (send and close).
*/
@ -147,29 +184,38 @@ promise_test(async (t) => {
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
const message = 'meow meow!';
pc2.ondatachannel = t.step_func((event) => {
const dc2 = event.channel;
dc2.onopen = t.step_func(() => {
assert_unreached('Open event should not fire');
});
// This should send but still prevent triggering the 'open' event
dc2.send(message);
dc2.close();
});
const dc1 = pc1.createDataChannel('fire-me!');
dc1.onmessage = t.step_func((event) => {
assert_equals(event.data, message,
'Received data should be equal to sent data');
resolver.resolve();
});
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
await resolver;
}, 'Open event should not be raised when sending and immediately closing the channel in the ' +
'datachannel event');
/*
6.2. RTCDataChannel
interface RTCDataChannel : EventTarget {
readonly attribute USVString label;
readonly attribute boolean ordered;
@ -182,6 +228,7 @@ promise_test(async (t) => {
readonly attribute RTCDataChannelState readyState;
...
};
When an underlying data transport is to be announced (the other peer created a channel with
negotiated unset or set to false), the user agent of the peer that did not initiate the
creation process MUST queue a task to run the following steps:
@ -197,20 +244,24 @@ promise_test(async (t) => {
value in configuration, [...]
7. Set channel's [[ReadyState]] slot to connecting.
8. Fire a datachannel event named datachannel with channel at the RTCPeerConnection object.
Note: More exhaustive tests are defined in RTCDataChannel-dcep
*/
promise_test(async (t) => {
const resolver = new Resolver();
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
const dc1 = pc1.createDataChannel('test', {
ordered: false,
maxRetransmits: 1,
protocol: 'custom',
priority: 'high'
});
assert_equals(dc1.label, 'test');
assert_equals(dc1.ordered, false);
assert_equals(dc1.maxPacketLifeTime, null);
@ -218,10 +269,12 @@ promise_test(async (t) => {
assert_equals(dc1.protocol, 'custom');
assert_equals(dc1.negotiated, false);
assert_equals(dc1.priority, 'high');
pc2.ondatachannel = t.step_func((event) => {
const dc2 = event.channel;
assert_true(dc2 instanceof RTCDataChannel,
'Expect channel to be instance of RTCDataChannel');
assert_equals(dc2.label, 'test');
assert_equals(dc2.ordered, false);
assert_equals(dc2.maxPacketLifeTime, null);
@ -230,20 +283,26 @@ promise_test(async (t) => {
assert_equals(dc2.negotiated, false);
assert_equals(dc2.id, dc1.id);
assert_equals(dc2.priority, 'high');
resolver.resolve();
});
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
await resolver;
}, 'In-band negotiated channel created on remote peer should match the same configuration as local ' +
'peer');
promise_test(async (t) => {
const resolver = new Resolver();
const pc1 = new RTCPeerConnection();
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
const dc1 = pc1.createDataChannel('');
assert_equals(dc1.label, '');
assert_equals(dc1.ordered, true);
assert_equals(dc1.maxPacketLifeTime, null);
@ -251,10 +310,12 @@ promise_test(async (t) => {
assert_equals(dc1.protocol, '');
assert_equals(dc1.negotiated, false);
assert_equals(dc1.priority, 'low');
pc2.ondatachannel = t.step_func((event) => {
const dc2 = event.channel;
assert_true(dc2 instanceof RTCDataChannel,
'Expect channel to be instance of RTCDataChannel');
assert_equals(dc2.label, '');
assert_equals(dc2.ordered, true);
assert_equals(dc2.maxPacketLifeTime, null);
@ -263,13 +324,17 @@ promise_test(async (t) => {
assert_equals(dc2.negotiated, false);
assert_equals(dc2.id, dc1.id);
assert_equals(dc2.priority, 'low');
resolver.resolve();
});
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
await resolver;
}, 'In-band negotiated channel created on remote peer should match the same (default) ' +
'configuration as local peer');
/*
6.2. RTCDataChannel
Dictionary RTCDataChannelInit Members
@ -286,24 +351,29 @@ promise_test(async (t) => {
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc1.close());
t.add_cleanup(() => pc2.close());
pc2.ondatachannel = t.unreached_func('datachannel event should not be fired');
pc1.createDataChannel('test', {
negotiated: true,
id: 42
});
exchangeIceCandidates(pc1, pc2);
await doSignalingHandshake(pc1, pc2);
// Wait a bit to ensure the 'datachannel' event does NOT fire
t.step_timeout(() => resolver.resolve(), 500);
await resolver;
}, 'Negotiated channel should not fire datachannel event on remote peer');
/*
Non-testable
6.2. RTCDataChannel
When an underlying data transport is to be announced
1. If the associated RTCPeerConnection object's [[isClosed]] slot
is true, abort these steps.
The above step is not testable because to reach it we would have to
close the peer connection just between receiving the in-band negotiated data
channel via DCEP and firing the datachannel event.