Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tests for RTCDataChannel id attribute. #5742

Merged
merged 3 commits into from May 9, 2017

Conversation

taylor-b
Copy link
Contributor

@taylor-b taylor-b commented Apr 30, 2017

When no ID argument is provided, and the DTLS role hasn't been
determined, the id attribute should return null.

After the DTLS role is determined by an answer being applied with
"a=setup:active" (or "passive"), the null IDs should be replaced with
either odd or even IDs, depending on the negotiated role.


This change is Reviewable

When no ID argument is provided, and the DTLS role hasn't been
determined, the id attribute should return `null`.

After the DTLS role is determined by an answer being applied with
"a=setup:active" (or "passive"), the null IDs should be replaced with
either odd or even IDs, depending on the negotiated role.
@wpt-pr-bot
Copy link
Collaborator

@taylor-b
Copy link
Contributor Author

This is the thing @foolip requested on w3c/webrtc-pc#1137, with an additional test for the odd/even ID selection after setRemoteDescription.

@agouaillard
Copy link
Contributor

agouaillard commented Apr 30, 2017

Read the thread, looked at the code. LGTM. As soon as @foolip approve, (and travis is happy) I will merge.

@w3c-bots
Copy link

w3c-bots commented Apr 30, 2017

View the complete job log.

Lint

Passed

@w3c-bots
Copy link

w3c-bots commented Apr 30, 2017

View the complete job log.

Firefox (nightly channel)

Testing web-platform-tests at revision 5805688
Using browser at version BuildID 20170507100239; SourceStamp 37a5b7f6f101df2eb292b1b6baaf1540c9920e20
Starting 10 test iterations
All results were stable

All results

2 tests ran
/webrtc/RTCDataChannel-id.html
Subtest Results Messages
OK
DTLS client uses odd data channel IDs FAIL assert_not_equals: got disallowed value 65535
DTLS server uses even data channel IDs FAIL assert_equals: id expected 0 but got 1
/webrtc/RTCPeerConnection-createDataChannel.html
Subtest Results Messages
OK
createDataChannel required arguments PASS
createDataChannel with closed connection PASS
createDataChannel defaults FAIL RTCDataChannel is not defined
createDataChannel with label "foo" PASS
createDataChannel with label null PASS
createDataChannel with label undefined PASS
createDataChannel with label lone surrogate PASS
createDataChannel with ordered false PASS
createDataChannel with ordered null/undefined PASS
createDataChannel with maxPacketLifeTime 0 FAIL assert_equals: expected (number) 0 but got (undefined) undefined
createDataChannel with maxRetransmits 0 FAIL assert_equals: expected (number) 0 but got (undefined) undefined
createDataChannel with both maxPacketLifeTime and maxRetransmits FAIL assert_throws: function "() => pc.createDataChannel('', {\n maxPacketLifeTime: 0,\n maxRetransmits: 0\n })" threw object "InvalidParameterError: Both maxPacketLifeTime and maxRetransmits cannot be provided" that is not a DOMException SyntaxError: property "code" is equal to 0, expected 12
createDataChannel with protocol "foo" PASS
createDataChannel with protocol null PASS
createDataChannel with protocol undefined PASS
createDataChannel with protocol lone surrogate PASS
createDataChannel with negotiated true FAIL assert_equals: expected (boolean) true but got (undefined) undefined
createDataChannel with id -1 FAIL assert_throws: function "() => pc.createDataChannel('', { id: id })" did not throw
createDataChannel with id 0 PASS
createDataChannel with id 1 PASS
createDataChannel with id 65534 PASS
createDataChannel with id 65535 FAIL assert_throws: function "() => pc.createDataChannel('', { id: id })" did not throw
createDataChannel with id 65536 FAIL assert_throws: function "() => pc.createDataChannel('', { id: id })" did not throw
createDataChannel with priority "high" FAIL assert_equals: expected (string) "high" but got (undefined) undefined

@w3c-bots
Copy link

w3c-bots commented Apr 30, 2017

View the complete job log.

Chrome (unstable channel)

Testing web-platform-tests at revision 5805688
Using browser at version 60.0.3088.3 dev
Starting 10 test iterations
All results were stable

All results

2 tests ran
/webrtc/RTCDataChannel-id.html
Subtest Results Messages
OK
DTLS client uses odd data channel IDs PASS
DTLS server uses even data channel IDs PASS
/webrtc/RTCPeerConnection-createDataChannel.html
Subtest Results Messages
OK
createDataChannel required arguments PASS
createDataChannel with closed connection PASS
createDataChannel defaults FAIL assert_equals: maxPacketLifeTime expected (object) null but got (undefined) undefined
createDataChannel with label "foo" PASS
createDataChannel with label null PASS
createDataChannel with label undefined PASS
createDataChannel with label lone surrogate PASS
createDataChannel with ordered false PASS
createDataChannel with ordered null/undefined PASS
createDataChannel with maxPacketLifeTime 0 FAIL assert_equals: expected (number) 0 but got (undefined) undefined
createDataChannel with maxRetransmits 0 PASS
createDataChannel with both maxPacketLifeTime and maxRetransmits FAIL assert_throws: function "() => pc.createDataChannel('', {\n maxPacketLifeTime: 0,\n maxRetransmits: 0\n })" did not throw
createDataChannel with protocol "foo" PASS
createDataChannel with protocol null PASS
createDataChannel with protocol undefined PASS
createDataChannel with protocol lone surrogate PASS
createDataChannel with negotiated true PASS
createDataChannel with id -1 PASS
createDataChannel with id 0 PASS
createDataChannel with id 1 PASS
createDataChannel with id 65534 FAIL Failed to execute 'createDataChannel' on 'RTCPeerConnection': RTCDataChannel is not supported
createDataChannel with id 65535 FAIL assert_throws: function "() => pc.createDataChannel('', { id: id })" threw object "NotSupportedError: Failed to execute 'createDataChannel' on 'RTCPeerConnection': RTCDataChannel is not supported" ("NotSupportedError") expected object "TypeError" ("TypeError")
createDataChannel with id 65536 PASS
createDataChannel with priority "high" FAIL assert_equals: expected (string) "high" but got (undefined) undefined

@taylor-b
Copy link
Contributor Author

taylor-b commented Apr 30, 2017

The new tests are failing on Firefox because it looks like Firefox only assigns the ID after the DTLS (and SCTP?) handshake completes. But the spec currently says it should be assigned by setting an answer. This was discussed briefly in a virtual interim, and changed in this PR: w3c/webrtc-pc#1038

But there wasn't a lot of discussion. @jesup, @jan-ivar, any opinions? Should the spec be more loose about when the ID is assigned?

@agouaillard
Copy link
Contributor

agouaillard commented May 1, 2017 via email

const answer = new RTCSessionDescription({
type: "answer",
sdp: pc.localDescription.sdp.replace("actpass", "active")
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agouaillard By that standard we shouldn't use the legacy RTCSessionDescription constructor ;)

// and should use even data channel IDs, according to rtcweb-data-channel.
assert_equals(channel.id, 0, 'id');
const another_channel = pc.createDataChannel('another');
assert_equals(another_channel.id, 2, 'id');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the spec says the next channel must be '2', just that it must be even.

.then(function() {
// Since the remote description had a "passive" DTLS role, we're the client
// and should use even data channel IDs, according to rtcweb-data-channel.
assert_equals(channel.id, 0, 'id');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the spec says this must be 0, just that it must be even

.then(function() {
// Since the remote description had an "active" DTLS role, we're the server
// and should use odd data channel IDs, according to rtcweb-data-channel.
assert_equals(channel.id, 1, 'id');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the spec says this must be 1, just that it must be odd:
"If the side is the DTLS client, it MUST choose an even
Stream Identifier, if the side is the DTLS server, it MUST choose an
odd one. "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Now only testing that the IDs are odd, and distinct from each other.

// and should use odd data channel IDs, according to rtcweb-data-channel.
assert_equals(channel.id, 1, 'id');
const another_channel = pc.createDataChannel('another');
assert_equals(another_channel.id, 3, 'id');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the spec says this must be 3, just that it must be odd

@jesup
Copy link
Contributor

jesup commented May 1, 2017

The interim discussion was on "what do we return before the id is established", and agreed null made more sense than the current impl's 65535.

Assigning the ID when setting the answer would require we inform the DataChannel code of the DTLS roles that will be negotiated, assuming one is guaranteed to know that at Answer time. Right now as stated we (firefox) assign them on DTLS negotiation, which gates us being able to actually send the Open packets on a specific id.

@w3c-bots
Copy link

w3c-bots commented May 1, 2017

These tests are now available on w3c-test.org

@taylor-b
Copy link
Contributor Author

taylor-b commented May 1, 2017

@jesup

Assigning the ID when setting the answer would require we inform the DataChannel code of the DTLS roles that will be negotiated, assuming one is guaranteed to know that at Answer time.

Since the answer contains the answerer's selected role, this should be guaranteed. Would it be feasible to change Firefox's behavior? Or should the spec's requirements be made more loose (for example, "the ID will be assigned at some point before readyState changes to "open"")?

assert_equals(channel.priority, 'low', 'priority');
}, 'createDataChannel defaults');

async_test(test => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this test into RTCDataChannel-id.html or similar? This file is for the createDataChannel method without further poking at the returned RTCDataChannel.

.then(function() {
// Turn our own offer SDP into valid answer SDP by setting the DTLS role to
// "active".
const answer = new RTCSessionDescription({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setRemoteDescription takes a RTCSessionDescriptionInit dictionary, so just passing the object (dictionary) directly should work?

assert_not_equals(channel.id, another_channel.id);
test.done();
})
.catch(test.step_func(function(e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test would probably be slightly smaller using promise_test, which would avoid the need for this.

const pc = new RTCPeerConnection;
const channel = pc.createDataChannel('');
pc.createOffer()
.then(function(offer) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be offer => pc.setLocalDescription(offer)

@taylor-b
Copy link
Contributor Author

taylor-b commented May 7, 2017

@foolip Addressed your comments; take another look.

@foolip foolip merged commit ce56f0e into web-platform-tests:master May 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants