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

Unified Diff: chrome/test/automation/javascript_message_utils.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: rebase Created 9 years, 4 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 | « chrome/chrome_tests.gypi ('k') | chrome/test/automation/value_conversion_traits.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/automation/javascript_message_utils.h
diff --git a/chrome/test/automation/javascript_message_utils.h b/chrome/test/automation/javascript_message_utils.h
index 64c93d7c5f408a2921bedfd8967a0e5b87353557..e4b61f4d9961f222f192336398e99dd2dc185cf8 100644
--- a/chrome/test/automation/javascript_message_utils.h
+++ b/chrome/test/automation/javascript_message_utils.h
@@ -14,48 +14,12 @@
#include "base/stringprintf.h"
#include "base/values.h"
#include "chrome/test/automation/dom_element_proxy.h"
-
-// ValueConversionTraits contains functions for creating a value from a
-// type, and setting a type from a value. This is general-purpose and can
-// be moved to a common location if needed.
-template <class T>
-struct ValueConversionTraits {
-};
-
-template <>
-struct ValueConversionTraits<int> {
- static Value* CreateValue(int t) {
- return Value::CreateIntegerValue(t);
- }
- static bool SetFromValue(Value* value, int* t) {
- return value->GetAsInteger(t);
- }
-};
-
-template <>
-struct ValueConversionTraits<bool> {
- static Value* CreateValue(bool t) {
- return Value::CreateBooleanValue(t);
- }
- static bool SetFromValue(Value* value, bool* t) {
- return value->GetAsBoolean(t);
- }
-};
-
-template <>
-struct ValueConversionTraits<std::string> {
- static Value* CreateValue(const std::string& t) {
- return Value::CreateStringValue(t);
- }
- static bool SetFromValue(Value* value, std::string* t) {
- return value->GetAsString(t);
- }
-};
+#include "chrome/test/automation/value_conversion_traits.h"
template <>
struct ValueConversionTraits<DOMElementProxy::By> {
typedef DOMElementProxy::By type;
- static Value* CreateValue(const type& t) {
+ static Value* CreateValueFrom(const type& t) {
DictionaryValue* value = new DictionaryValue();
std::string by_type;
switch (t.type()) {
@@ -80,20 +44,24 @@ struct ValueConversionTraits<DOMElementProxy::By> {
template <typename T>
struct ValueConversionTraits<std::vector<T> > {
- static Value* CreateValue(const std::vector<T>& t) {
+ static Value* CreateValueFrom(const std::vector<T>& t) {
ListValue* value = new ListValue();
for (size_t i = 0; i < t.size(); i++) {
- value->Append(ValueConversionTraits<T>::CreateValue(t[i]));
+ value->Append(ValueConversionTraits<T>::CreateValueFrom(t[i]));
}
return value;
}
- static bool SetFromValue(Value* value, std::vector<T>* t) {
+ static bool SetFromValue(const Value* value, std::vector<T>* t) {
if (!value->IsType(Value::TYPE_LIST))
return false;
- ListValue* list_value = static_cast<ListValue*>(value);
+ const ListValue* list_value = static_cast<const ListValue*>(value);
ListValue::const_iterator iter;
for (iter = list_value->begin(); iter != list_value->end(); ++iter) {
+ if (!ValueConversionTraits<T>::CanConvert(*iter))
+ return false;
+ }
+ for (iter = list_value->begin(); iter != list_value->end(); ++iter) {
T inner_value;
ValueConversionTraits<T>::SetFromValue(*iter, &inner_value);
t->push_back(inner_value);
@@ -108,7 +76,7 @@ namespace javascript_utils {
template <typename T>
std::string JSONStringify(const T& arg) {
std::string javascript;
- scoped_ptr<Value> value(ValueConversionTraits<T>::CreateValue(arg));
+ scoped_ptr<Value> value(ValueConversionTraits<T>::CreateValueFrom(arg));
base::JSONWriter::Write(value.get(), false, &javascript);
return javascript;
}
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/automation/value_conversion_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698