[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / content / shell / renderer / test_runner / MockConstraints.cpp
blob7e018721020d88303fd8e3c65cd17c6075879af2
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;
12 namespace content {
14 namespace {
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") {
36 if (failedConstraint)
37 *failedConstraint = curr.m_name;
38 return false;
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;
56 return true;
59 } // namespace content