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 "content/shell/renderer/test_runner/MockConstraints.h" |
| 6 |
| 7 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 8 #include "third_party/WebKit/public/platform/WebString.h" |
| 9 |
| 10 using namespace blink; |
| 11 |
| 12 namespace WebTestRunner { |
| 13 |
| 14 namespace { |
| 15 |
| 16 bool isSupported(const WebString& constraint) |
| 17 { |
| 18 return constraint == "valid_and_supported_1" || constraint == "valid_and_sup
ported_2"; |
| 19 } |
| 20 |
| 21 bool isValid(const WebString& constraint) |
| 22 { |
| 23 return isSupported(constraint) || constraint == "valid_but_unsupported_1" ||
constraint == "valid_but_unsupported_2"; |
| 24 } |
| 25 |
| 26 } |
| 27 |
| 28 bool MockConstraints::verifyConstraints(const WebMediaConstraints& constraints,
WebString* failedConstraint) |
| 29 { |
| 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") { |
| 36 if (failedConstraint) |
| 37 *failedConstraint = curr.m_name; |
| 38 return false; |
| 39 } |
| 40 } |
| 41 } |
| 42 |
| 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") { |
| 49 if (failedConstraint) |
| 50 *failedConstraint = curr.m_name; |
| 51 return false; |
| 52 } |
| 53 } |
| 54 } |
| 55 |
| 56 return true; |
| 57 } |
| 58 |
| 59 } |
OLD | NEW |