Home | History | Annotate | Download | only in test_runner
      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/mock_constraints.h"
      6 
      7 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
      8 #include "third_party/WebKit/public/platform/WebString.h"
      9 
     10 using blink::WebMediaConstraint;
     11 using blink::WebMediaConstraints;
     12 using blink::WebString;
     13 using blink::WebVector;
     14 
     15 namespace content {
     16 
     17 namespace {
     18 
     19 bool IsSupported(const WebString& constraint) {
     20   return constraint == "valid_and_supported_1" ||
     21          constraint == "valid_and_supported_2";
     22 }
     23 
     24 bool IsValid(const WebString& constraint) {
     25   return IsSupported(constraint) || constraint == "valid_but_unsupported_1" ||
     26          constraint == "valid_but_unsupported_2";
     27 }
     28 
     29 }  // namespace
     30 
     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;
     42       }
     43     }
     44   }
     45 
     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;
     55       }
     56     }
     57   }
     58 
     59   return true;
     60 }
     61 
     62 }  // namespace content
     63