Commit e8e1bf91 authored by Philipp Hancke's avatar Philipp Hancke Committed by Commit Bot

rtcpeerconnection: dont fire signalingstatechange from close()

RTCPeerConnection.close() shall not fire events. It doesn't already for
iceconnectionstate/connectionstate

BUG=699036

Change-Id: I771cdd81c3bbdb4312a623e96f8150be8471d906
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1959042
Commit-Queue: Harald Alvestrand <hta@chromium.org>
Reviewed-by: default avatarHarald Alvestrand <hta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727965}
parent 1ab64d80
...@@ -3101,6 +3101,9 @@ void RTCPeerConnection::ChangeSignalingState( ...@@ -3101,6 +3101,9 @@ void RTCPeerConnection::ChangeSignalingState(
if (signaling_state_ != if (signaling_state_ !=
webrtc::PeerConnectionInterface::SignalingState::kClosed) { webrtc::PeerConnectionInterface::SignalingState::kClosed) {
signaling_state_ = signaling_state; signaling_state_ = signaling_state;
if (closed_) {
return;
}
Event* event = Event::Create(event_type_names::kSignalingstatechange); Event* event = Event::Create(event_type_names::kSignalingstatechange);
if (dispatch_event_immediately) if (dispatch_event_immediately)
DispatchEvent(*event); DispatchEvent(*event);
......
<!doctype html>
<meta charset=utf-8>
<title>RTCPeerConnection.prototype.close</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
promise_test(async t => {
const pc = new RTCPeerConnection();
t.add_cleanup(() => pc.close());
pc.onsignalingstatechange = t.unreached_func();
pc.close();
assert_true(pc.signalingState === 'closed');
await new Promise(r => t.step_timeout(r, 100));
}, 'RTCPeerConnection.close() does not fire signalingstatechange event.');
</script>
Tests that RTCPeerConnection event callbacks are async so that for example close can be called safely. The order of the messages is very important.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS gotStream was called.
PASS gotStream done.
PASS onNegotiationNeeded was called.
PASS onNegotiationNeeded done.
PASS onStateChange was called.
PASS pc.signalingState is 'closed'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
description("Tests that RTCPeerConnection event callbacks are async so that for example close can be called safely. The order of the messages is very important.");
var stream = null;
var pc = null;
function error() {
testFailed('Stream generation failed.');
finishJSTest();
}
function getUserMedia(dictionary, callback) {
try {
navigator.webkitGetUserMedia(dictionary, callback, error);
} catch (e) {
testFailed('webkitGetUserMedia threw exception :' + e);
finishJSTest();
}
}
function onStateChange(event) {
testPassed('onStateChange was called.');
shouldBe("pc.signalingState", "'closed'");
finishJSTest();
}
function onNegotiationNeeded(event) {
testPassed('onNegotiationNeeded was called.');
pc.onsignalingstatechange = onStateChange;
pc.onnegotiationneeded = onNegotiationNeededAgain;
pc.close();
testPassed('onNegotiationNeeded done.')
}
function onNegotiationNeededAgain(event) {
testFailed('onNegotiationNeededAgain should never be called.');
}
function gotStream(s) {
testPassed('gotStream was called.');
stream = s;
pc = new RTCPeerConnection();
pc.onnegotiationneeded = onNegotiationNeeded;
pc.addStream(stream);
testPassed('gotStream done.');
}
getUserMedia({audio:true, video:true}, gotStream);
window.jsTestIsAsync = true;
window.successfullyParsed = true;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>RTCPeerConnection signalingState</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
async_test(function(test) {
var pc = new RTCPeerConnection();
assert_equals(pc.signalingState, 'stable');
pc.onsignalingstatechange = test.step_func(() => {
assert_equals(pc.signalingState, 'closed');
test.done();
});
pc.close();
}, 'Tests the RTCPeerConnection "stable" and "closed" signalingState strings.');
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment