Backed out changeset 36a709ae32db (bug 917328) for failures in test_exceptions_from_jsimplemented.html on a CLOSED TREE

This commit is contained in:
Ed Morley 2013-10-09 16:46:03 +01:00
parent bdcfbec358
commit 07bd89fe32
3 changed files with 65 additions and 59 deletions

View File

@ -324,44 +324,75 @@ RTCPeerConnection.prototype = {
},
/**
* MediaConstraints look like this:
* Constraints look like this:
*
* {
* mandatory: {"OfferToReceiveAudio": true, "OfferToReceiveVideo": true },
* optional: [{"VoiceActivityDetection": true}, {"FooBar": 10}]
* }
*
* WebIDL normalizes the top structure for us, but the mandatory constraints
* member comes in as a raw object so we can detect unknown constraints.
* We compare its members against ones we support, and fail if not found.
* We check for basic structure of constraints and the validity of
* mandatory constraints against those we support (fail if we don't).
* Unknown optional constraints may be of any type.
*/
_mustValidateConstraints: function(constraints, errorMsg) {
function isObject(obj) {
return obj && (typeof obj === "object");
}
function isArraylike(obj) {
return isObject(obj) && ("length" in obj);
}
const SUPPORTED_CONSTRAINTS = {
OfferToReceiveAudio:1,
OfferToReceiveVideo:1,
MozDontOfferDataChannel:1
};
const OTHER_KNOWN_CONSTRAINTS = {
VoiceActivityDetection:1,
IceTransports:1,
RequestIdentity:1
};
// Parse-aid: Testing for pilot error of missing outer block avoids
// otherwise silent no-op since both mandatory and optional are optional
if (!isObject(constraints) || Array.isArray(constraints)) {
throw new this._win.DOMError("", errorMsg);
}
if (constraints.mandatory) {
let supported;
try {
// Passing the raw constraints.mandatory here validates its structure
supported = this._observer.getSupportedConstraints(constraints.mandatory);
} catch (e) {
throw new this._win.DOMError("", errorMsg + " - " + e.message);
// Testing for pilot error of using [] on mandatory here throws nicer msg
// (arrays would throw in loop below regardless but with more cryptic msg)
if (!isObject(constraints.mandatory) || Array.isArray(constraints.mandatory)) {
throw new this._win.DOMError("",
errorMsg + " - malformed mandatory constraints");
}
for (let constraint of Object.keys(constraints.mandatory)) {
if (!(constraint in supported)) {
throw new this._win.DOMError("",
errorMsg + " - unsupported mandatory constraint: " + constraint);
for (let constraint in constraints.mandatory) {
if (!(constraint in SUPPORTED_CONSTRAINTS) &&
constraints.mandatory.hasOwnProperty(constraint)) {
throw new this._win.DOMError("", errorMsg + " - " +
((constraint in OTHER_KNOWN_CONSTRAINTS)? "unsupported" : "unknown") +
" mandatory constraint: " + constraint);
}
}
}
if (constraints.optional) {
if (!isArraylike(constraints.optional)) {
throw new this._win.DOMError("",
errorMsg + " - malformed optional constraint array");
}
let len = constraints.optional.length;
for (let i = 0; i < len; i++) {
for (let i = 0; i < len; i += 1) {
if (!isObject(constraints.optional[i])) {
throw new this._win.DOMError("", errorMsg +
" - malformed optional constraint: " + constraints.optional[i]);
}
let constraints_per_entry = 0;
for (let constraint in Object.keys(constraints.optional[i])) {
if (constraints_per_entry) {
throw new this._win.DOMError("", errorMsg +
" - optional constraint must be single key/value pair");
for (let constraint in constraints.optional[i]) {
if (constraints.optional[i].hasOwnProperty(constraint)) {
if (constraints_per_entry) {
throw new this._win.DOMError("", errorMsg +
" - optional constraint must be single key/value pair");
}
constraints_per_entry += 1;
}
constraints_per_entry += 1;
}
}
}
@ -1075,14 +1106,6 @@ PeerConnectionObserver.prototype = {
notifyClosedConnection: function() {
this.dispatchEvent(new this._dompc._win.Event("closedconnection"));
},
getSupportedConstraints: function(dict) {
// TODO: Once Bug 917328 makes this a webidl object, we just return our arg
// return dict;
return { "OfferToReceiveAudio":true,
"OfferToReceiveVideo":true,
"MozDontOfferDataChannel":true };
}
};

View File

@ -27,9 +27,15 @@
try { pconnect.createOffer(step1, failed, 1); } catch (e) { exception = e; }
ok(exception, "createOffer(step1, failed, 1) throws");
exception = null;
try { pconnect.createOffer(step1, failed, []); } catch (e) { exception = e; }
ok(exception, "createOffer(step1, failed, []) throws");
exception = null;
try { pconnects.createOffer(step1, failed, {}); } catch (e) { exception = e; }
ok(!exception, "createOffer(step1, failed, {}) succeeds");
exception = null;
try { pconnect.createOffer(step1, failed, { mandatory: [] }); } catch (e) { exception = e; }
ok(exception, "createOffer(step1, failed, { mandatory: [] }) throws");
exception = null;
try {
pconnect.createOffer(step1, failed, { mandatory: { FooBar: true } });
} catch (e) {
@ -38,6 +44,9 @@
}
ok(exception, "createOffer(step1, failed, { mandatory: { FooBar: true } }) throws");
exception = null;
try { pconnect.createOffer(step1, failed, { optional: {} }); } catch (e) { exception = e; }
ok(exception, "createOffer(step1, failed, { optional: {} }) throws");
exception = null;
try { pconnects.createOffer(step1, failed, { optional: [] }); } catch (e) { exception = e; }
ok(!exception, "createOffer(step1, failed, { optional: [] }) succeeds");
exception = null;

View File

@ -51,32 +51,6 @@ dictionary RTCDataChannelInit {
unsigned short stream; // now id
};
// Misnomer dictionaries housing PeerConnection-specific constraints.
//
// Important! Do not ever add members that might need tracing (e.g. object)
// to MediaConstraintSet or any dictionary marked XxxInternal here
dictionary MediaConstraintSet {
boolean OfferToReceiveAudio;
boolean OfferToReceiveVideo;
boolean MozDontOfferDataChannel;
};
// MediaConstraint = single-property-subset of MediaConstraintSet
// Implemented as full set. Test Object.keys(pair).length == 1
// typedef MediaConstraintSet MediaConstraint; // TODO: Bug 913053
dictionary MediaConstraints {
object mandatory; // so we can see unknown + unsupported constraints
sequence<MediaConstraintSet> _optional; // a.k.a. MediaConstraint
};
dictionary MediaConstraintsInternal {
MediaConstraintSet mandatory; // holds only supported constraints
sequence<MediaConstraintSet> _optional; // a.k.a. MediaConstraint
};
interface RTCDataChannel;
[Pref="media.peerconnection.enabled",
@ -87,10 +61,10 @@ interface RTCDataChannel;
interface mozRTCPeerConnection : EventTarget {
void createOffer (RTCSessionDescriptionCallback successCallback,
RTCPeerConnectionErrorCallback? failureCallback, // for apprtc
optional MediaConstraints constraints);
optional object? constraints);
void createAnswer (RTCSessionDescriptionCallback successCallback,
RTCPeerConnectionErrorCallback? failureCallback, // for apprtc
optional MediaConstraints constraints);
optional object? constraints);
void setLocalDescription (mozRTCSessionDescription description,
optional VoidFunction successCallback,
optional RTCPeerConnectionErrorCallback failureCallback);
@ -101,7 +75,7 @@ interface mozRTCPeerConnection : EventTarget {
readonly attribute mozRTCSessionDescription? remoteDescription;
readonly attribute RTCSignalingState signalingState;
void updateIce (optional RTCConfiguration configuration,
optional MediaConstraints constraints);
optional object? constraints);
void addIceCandidate (mozRTCIceCandidate candidate,
optional VoidFunction successCallback,
optional RTCPeerConnectionErrorCallback failureCallback);
@ -110,7 +84,7 @@ interface mozRTCPeerConnection : EventTarget {
sequence<MediaStream> getLocalStreams ();
sequence<MediaStream> getRemoteStreams ();
MediaStream? getStreamById (DOMString streamId);
void addStream (MediaStream stream, optional MediaConstraints constraints);
void addStream (MediaStream stream, optional object? constraints);
void removeStream (MediaStream stream);
void close ();
attribute EventHandler onnegotiationneeded;