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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/automation/value_conversion_traits.cc ('k') | chrome/test/webdriver/automation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #ifndef CHROME_TEST_AUTOMATION_VALUE_CONVERSION_UTIL_H_
6 #define CHROME_TEST_AUTOMATION_VALUE_CONVERSION_UTIL_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/values.h"
12 #include "chrome/test/automation/value_conversion_traits.h"
13
14 // Creates a value from the given parameter. Will not return NULL.
15 template <typename T>
16 base::Value* CreateValueFrom(const T& t) {
17 return ValueConversionTraits<T>::CreateValueFrom(t);
18 }
19
20 // Sets |t| from the given value. Returns true on success. |t| will not be
21 // modified unless successful.
22 template <typename T>
23 bool SetFromValue(const base::Value* value, T* t) {
24 return ValueConversionTraits<T>::SetFromValue(value, t);
25 }
26
27 // Creates a list value containing the converted value from the the given
28 // parameter.
29 template <typename T>
30 base::ListValue* CreateListValueFrom(const T& t) {
31 base::ListValue* list = new base::ListValue();
32 list->Append(CreateValueFrom(t));
33 return list;
34 }
35
36 // Same as above, but with more arguments.
37 template <typename T1, typename T2>
38 base::ListValue* CreateListValueFrom(const T1& t1, const T2& t2) {
39 base::ListValue* list = new base::ListValue();
40 list->Append(CreateValueFrom(t1));
41 list->Append(CreateValueFrom(t2));
42 return list;
43 }
44
45 // Same as above, but with more arguments.
46 template <typename T1, typename T2, typename T3>
47 base::ListValue* CreateListValueFrom(const T1& t1, const T2& t2, const T3& t3) {
48 base::ListValue* list = new base::ListValue();
49 list->Append(CreateValueFrom(t1));
50 list->Append(CreateValueFrom(t2));
51 list->Append(CreateValueFrom(t3));
52 return list;
53 }
54
55 // Sets |t| from the first element in the given list. Returns true on success.
56 // |t| will not be modified unless successful.
57 template <typename T>
58 bool SetFromListValue(const base::ListValue* list, T* t) {
59 if (list->GetSize() != 1)
60 return false;
61
62 if (!ValueConversionTraits<T>::CanConvert(*list->begin()))
63 return false;
64
65 CHECK(SetFromValue(*list->begin(), t));
66 return true;
67 }
68
69 // Same as above, but with more arguments.
70 template <typename T1, typename T2>
71 bool SetFromListValue(const base::ListValue* list, T1* t1, T2* t2) {
72 if (list->GetSize() != 2)
73 return false;
74
75 if (!ValueConversionTraits<T1>::CanConvert(*list->begin()))
76 return false;
77 if (!ValueConversionTraits<T2>::CanConvert(*(list->begin() + 1)))
78 return false;
79
80 CHECK(SetFromValue(*list->begin(), t1));
81 CHECK(SetFromValue(*(list->begin() + 1), t2));
82 return true;
83 }
84
85 // Same as above, but with more arguments.
86 template <typename T1, typename T2, typename T3>
87 bool SetFromListValue(const base::ListValue* list, T1* t1, T2* t2, T3* t3) {
88 if (list->GetSize() != 3)
89 return false;
90
91 if (!ValueConversionTraits<T1>::CanConvert(*list->begin()))
92 return false;
93 if (!ValueConversionTraits<T2>::CanConvert(*(list->begin() + 1)))
94 return false;
95 if (!ValueConversionTraits<T3>::CanConvert(*(list->begin() + 2)))
96 return false;
97
98 CHECK(SetFromValue(*list->begin(), t1));
99 CHECK(SetFromValue(*(list->begin() + 1), t2));
100 CHECK(SetFromValue(*(list->begin() + 2), t3));
101 return true;
102 }
103
104 #endif // CHROME_TEST_AUTOMATION_VALUE_CONVERSION_UTIL_H_
OLDNEW
« no previous file with comments | « chrome/test/automation/value_conversion_traits.cc ('k') | chrome/test/webdriver/automation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698