1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/renderer/test_runner/MockConstraints.h"
7 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
8 #include "third_party/WebKit/public/platform/WebString.h"
10 using namespace blink
;
16 bool isSupported(const WebString
& constraint
)
18 return constraint
== "valid_and_supported_1" || constraint
== "valid_and_supported_2";
21 bool isValid(const WebString
& constraint
)
23 return isSupported(constraint
) || constraint
== "valid_but_unsupported_1" || constraint
== "valid_but_unsupported_2";
28 bool MockConstraints::verifyConstraints(const WebMediaConstraints
& constraints
, WebString
* failedConstraint
)
30 WebVector
<WebMediaConstraint
> mandatoryConstraints
;
31 constraints
.getMandatoryConstraints(mandatoryConstraints
);
32 if (mandatoryConstraints
.size()) {
33 for (size_t i
= 0; i
< mandatoryConstraints
.size(); ++i
) {
34 const WebMediaConstraint
& curr
= mandatoryConstraints
[i
];
35 if (!isSupported(curr
.m_name
) || curr
.m_value
!= "1") {
37 *failedConstraint
= curr
.m_name
;
43 WebVector
<WebMediaConstraint
> optionalConstraints
;
44 constraints
.getOptionalConstraints(optionalConstraints
);
45 if (optionalConstraints
.size()) {
46 for (size_t i
= 0; i
< optionalConstraints
.size(); ++i
) {
47 const WebMediaConstraint
& curr
= optionalConstraints
[i
];
48 if (!isValid(curr
.m_name
) || curr
.m_value
!= "0") {
50 *failedConstraint
= curr
.m_name
;
59 } // namespace content