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 /* |
| 6 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions are |
| 10 * met: |
| 11 * |
| 12 * * Redistributions of source code must retain the above copyright |
| 13 * notice, this list of conditions and the following disclaimer. |
| 14 * * Redistributions in binary form must reproduce the above |
| 15 * copyright notice, this list of conditions and the following disclaimer |
| 16 * in the documentation and/or other materials provided with the |
| 17 * distribution. |
| 18 * * Neither the name of Google Inc. nor the names of its |
| 19 * contributors may be used to endorse or promote products derived from |
| 20 * this software without specific prior written permission. |
| 21 * |
| 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 */ |
| 34 |
| 35 #include "content/test/layout_tests/runner/MockConstraints.h" |
| 36 |
| 37 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 38 #include "third_party/WebKit/public/platform/WebString.h" |
| 39 |
| 40 using namespace blink; |
| 41 |
| 42 namespace WebTestRunner { |
| 43 |
| 44 namespace { |
| 45 |
| 46 bool isSupported(const WebString& constraint) |
| 47 { |
| 48 return constraint == "valid_and_supported_1" || constraint == "valid_and_sup
ported_2"; |
| 49 } |
| 50 |
| 51 bool isValid(const WebString& constraint) |
| 52 { |
| 53 return isSupported(constraint) || constraint == "valid_but_unsupported_1" ||
constraint == "valid_but_unsupported_2"; |
| 54 } |
| 55 |
| 56 } |
| 57 |
| 58 bool MockConstraints::verifyConstraints(const WebMediaConstraints& constraints,
WebString* failedConstraint) |
| 59 { |
| 60 WebVector<WebMediaConstraint> mandatoryConstraints; |
| 61 constraints.getMandatoryConstraints(mandatoryConstraints); |
| 62 if (mandatoryConstraints.size()) { |
| 63 for (size_t i = 0; i < mandatoryConstraints.size(); ++i) { |
| 64 const WebMediaConstraint& curr = mandatoryConstraints[i]; |
| 65 if (!isSupported(curr.m_name) || curr.m_value != "1") { |
| 66 if (failedConstraint) |
| 67 *failedConstraint = curr.m_name; |
| 68 return false; |
| 69 } |
| 70 } |
| 71 } |
| 72 |
| 73 WebVector<WebMediaConstraint> optionalConstraints; |
| 74 constraints.getOptionalConstraints(optionalConstraints); |
| 75 if (optionalConstraints.size()) { |
| 76 for (size_t i = 0; i < optionalConstraints.size(); ++i) { |
| 77 const WebMediaConstraint& curr = optionalConstraints[i]; |
| 78 if (!isValid(curr.m_name) || curr.m_value != "0") { |
| 79 if (failedConstraint) |
| 80 *failedConstraint = curr.m_name; |
| 81 return false; |
| 82 } |
| 83 } |
| 84 } |
| 85 |
| 86 return true; |
| 87 } |
| 88 |
| 89 } |
OLD | NEW |