Don't preload rarely seen large images
[chromium-blink-merge.git] / components / test_runner / mock_constraints.cc
blob90586196ac1e78ae57f48da92e7e32f918aa15e1
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 "components/test_runner/mock_constraints.h"
7 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
8 #include "third_party/WebKit/public/platform/WebString.h"
10 using blink::WebMediaConstraint;
11 using blink::WebMediaConstraints;
12 using blink::WebString;
13 using blink::WebVector;
15 namespace test_runner {
17 namespace {
19 bool IsSupported(const WebString& constraint) {
20 return constraint == "valid_and_supported_1" ||
21 constraint == "valid_and_supported_2";
24 bool IsValid(const WebString& constraint) {
25 return IsSupported(constraint) || constraint == "valid_but_unsupported_1" ||
26 constraint == "valid_but_unsupported_2";
29 } // namespace
31 bool MockConstraints::VerifyConstraints(const WebMediaConstraints& constraints,
32 WebString* failed_constraint) {
33 WebVector<WebMediaConstraint> mandatory_constraints;
34 constraints.getMandatoryConstraints(mandatory_constraints);
35 if (mandatory_constraints.size()) {
36 for (size_t i = 0; i < mandatory_constraints.size(); ++i) {
37 const WebMediaConstraint& curr = mandatory_constraints[i];
38 if (!IsSupported(curr.m_name) || curr.m_value != "1") {
39 if (failed_constraint)
40 *failed_constraint = curr.m_name;
41 return false;
46 WebVector<WebMediaConstraint> optional_constraints;
47 constraints.getOptionalConstraints(optional_constraints);
48 if (optional_constraints.size()) {
49 for (size_t i = 0; i < optional_constraints.size(); ++i) {
50 const WebMediaConstraint& curr = optional_constraints[i];
51 if (!IsValid(curr.m_name) || curr.m_value != "0") {
52 if (failed_constraint)
53 *failed_constraint = curr.m_name;
54 return false;
59 return true;
62 } // namespace test_runner