Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8474)

Unified Diff: components/test_runner/mock_constraints.cc

Issue 1608073002: Revert of Remove MockConstraints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/test_runner/mock_constraints.h ('k') | components/test_runner/mock_web_user_media_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/test_runner/mock_constraints.cc
diff --git a/components/test_runner/mock_constraints.cc b/components/test_runner/mock_constraints.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e18e55ecdfc1b4fc3f68988167ad24c5b2e00af
--- /dev/null
+++ b/components/test_runner/mock_constraints.cc
@@ -0,0 +1,64 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/test_runner/mock_constraints.h"
+
+#include <stddef.h>
+
+#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+
+using blink::WebMediaConstraint;
+using blink::WebMediaConstraints;
+using blink::WebString;
+using blink::WebVector;
+
+namespace test_runner {
+
+namespace {
+
+bool IsSupported(const WebString& constraint) {
+ return constraint == "valid_and_supported_1" ||
+ constraint == "valid_and_supported_2";
+}
+
+bool IsValid(const WebString& constraint) {
+ return IsSupported(constraint) || constraint == "valid_but_unsupported_1" ||
+ constraint == "valid_but_unsupported_2";
+}
+
+} // namespace
+
+bool MockConstraints::VerifyConstraints(const WebMediaConstraints& constraints,
+ WebString* failed_constraint) {
+ WebVector<WebMediaConstraint> mandatory_constraints;
+ constraints.getMandatoryConstraints(mandatory_constraints);
+ if (mandatory_constraints.size()) {
+ for (size_t i = 0; i < mandatory_constraints.size(); ++i) {
+ const WebMediaConstraint& curr = mandatory_constraints[i];
+ if (!IsSupported(curr.m_name) || curr.m_value != "1") {
+ if (failed_constraint)
+ *failed_constraint = curr.m_name;
+ return false;
+ }
+ }
+ }
+
+ WebVector<WebMediaConstraint> optional_constraints;
+ constraints.getOptionalConstraints(optional_constraints);
+ if (optional_constraints.size()) {
+ for (size_t i = 0; i < optional_constraints.size(); ++i) {
+ const WebMediaConstraint& curr = optional_constraints[i];
+ if (!IsValid(curr.m_name) || curr.m_value != "0") {
+ if (failed_constraint)
+ *failed_constraint = curr.m_name;
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+} // namespace test_runner
« no previous file with comments | « components/test_runner/mock_constraints.h ('k') | components/test_runner/mock_web_user_media_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698