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

Unified Diff: chrome/test/automation/value_conversion_util.h

Issue 7522024: Refactor chromedriver's script execution to reduce amount of custom Value parsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 5 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
Index: chrome/test/automation/value_conversion_util.h
diff --git a/chrome/test/automation/value_conversion_util.h b/chrome/test/automation/value_conversion_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..952c4b134460f61b737dcfa307e359284460463c
--- /dev/null
+++ b/chrome/test/automation/value_conversion_util.h
@@ -0,0 +1,104 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_TEST_AUTOMATION_VALUE_CONVERSION_UTIL_H_
+#define CHROME_TEST_AUTOMATION_VALUE_CONVERSION_UTIL_H_
+#pragma once
+
+#include <string>
+
+#include "base/values.h"
+#include "chrome/test/automation/value_conversion_traits.h"
+
+// Creates a value from the given parameter. Will not return NULL.
+template <typename T>
+base::Value* CreateValueFrom(const T& t) {
+ return ValueConversionTraits<T>::CreateValueFrom(t);
+}
+
+// Sets |t| from the given value. Returns true on success. |t| will not be
+// modified unless successful.
+template <typename T>
+bool SetFromValue(const base::Value* value, T* t) {
+ return ValueConversionTraits<T>::SetFromValue(value, t);
+}
+
+// Creates a list value containing the converted value from the the given
+// parameter.
+template <typename T>
+base::ListValue* CreateListValueFrom(const T& t) {
+ base::ListValue* list = new base::ListValue();
+ list->Append(CreateValueFrom(t));
+ return list;
+}
+
+// Same as above, but with more arguments.
+template <typename T1, typename T2>
+base::ListValue* CreateListValueFrom(const T1& t1, const T2& t2) {
+ base::ListValue* list = new base::ListValue();
+ list->Append(CreateValueFrom(t1));
+ list->Append(CreateValueFrom(t2));
+ return list;
+}
+
+// Same as above, but with more arguments.
+template <typename T1, typename T2, typename T3>
+base::ListValue* CreateListValueFrom(const T1& t1, const T2& t2, const T3& t3) {
+ base::ListValue* list = new base::ListValue();
+ list->Append(CreateValueFrom(t1));
+ list->Append(CreateValueFrom(t2));
+ list->Append(CreateValueFrom(t3));
+ return list;
+}
+
+// Sets |t| from the first element in the given list. Returns true on success.
+// |t| will not be modified unless successful.
+template <typename T>
+bool SetFromListValue(const base::ListValue* list, T* t) {
+ if (list->GetSize() != 1)
+ return false;
+
+ if (!ValueConversionTraits<T>::CanConvert(*list->begin()))
+ return false;
+
+ CHECK(SetFromValue(*list->begin(), t));
+ return true;
+}
+
+// Same as above, but with more arguments.
+template <typename T1, typename T2>
+bool SetFromListValue(const base::ListValue* list, T1* t1, T2* t2) {
+ if (list->GetSize() != 2)
+ return false;
+
+ if (!ValueConversionTraits<T1>::CanConvert(*list->begin()))
+ return false;
+ if (!ValueConversionTraits<T2>::CanConvert(*(list->begin() + 1)))
+ return false;
+
+ CHECK(SetFromValue(*list->begin(), t1));
+ CHECK(SetFromValue(*(list->begin() + 1), t2));
+ return true;
+}
+
+// Same as above, but with more arguments.
+template <typename T1, typename T2, typename T3>
+bool SetFromListValue(const base::ListValue* list, T1* t1, T2* t2, T3* t3) {
+ if (list->GetSize() != 3)
+ return false;
+
+ if (!ValueConversionTraits<T1>::CanConvert(*list->begin()))
+ return false;
+ if (!ValueConversionTraits<T2>::CanConvert(*(list->begin() + 1)))
+ return false;
+ if (!ValueConversionTraits<T3>::CanConvert(*(list->begin() + 2)))
+ return false;
+
+ CHECK(SetFromValue(*list->begin(), t1));
+ CHECK(SetFromValue(*(list->begin() + 1), t2));
+ CHECK(SetFromValue(*(list->begin() + 2), t3));
+ return true;
+}
+
+#endif // CHROME_TEST_AUTOMATION_VALUE_CONVERSION_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698