| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "components/test_runner/mock_constraints.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | |
| 10 #include "third_party/WebKit/public/platform/WebString.h" | |
| 11 | |
| 12 using blink::WebMediaConstraint; | |
| 13 using blink::WebMediaConstraints; | |
| 14 using blink::WebString; | |
| 15 using blink::WebVector; | |
| 16 | |
| 17 namespace test_runner { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 bool IsSupported(const WebString& constraint) { | |
| 22 return constraint == "valid_and_supported_1" || | |
| 23 constraint == "valid_and_supported_2"; | |
| 24 } | |
| 25 | |
| 26 bool IsValid(const WebString& constraint) { | |
| 27 return IsSupported(constraint) || constraint == "valid_but_unsupported_1" || | |
| 28 constraint == "valid_but_unsupported_2"; | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 bool MockConstraints::VerifyConstraints(const WebMediaConstraints& constraints, | |
| 34 WebString* failed_constraint) { | |
| 35 WebVector<WebMediaConstraint> mandatory_constraints; | |
| 36 constraints.getMandatoryConstraints(mandatory_constraints); | |
| 37 if (mandatory_constraints.size()) { | |
| 38 for (size_t i = 0; i < mandatory_constraints.size(); ++i) { | |
| 39 const WebMediaConstraint& curr = mandatory_constraints[i]; | |
| 40 if (!IsSupported(curr.m_name) || curr.m_value != "1") { | |
| 41 if (failed_constraint) | |
| 42 *failed_constraint = curr.m_name; | |
| 43 return false; | |
| 44 } | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 WebVector<WebMediaConstraint> optional_constraints; | |
| 49 constraints.getOptionalConstraints(optional_constraints); | |
| 50 if (optional_constraints.size()) { | |
| 51 for (size_t i = 0; i < optional_constraints.size(); ++i) { | |
| 52 const WebMediaConstraint& curr = optional_constraints[i]; | |
| 53 if (!IsValid(curr.m_name) || curr.m_value != "0") { | |
| 54 if (failed_constraint) | |
| 55 *failed_constraint = curr.m_name; | |
| 56 return false; | |
| 57 } | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 return true; | |
| 62 } | |
| 63 | |
| 64 } // namespace test_runner | |
| OLD | NEW |