| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 5 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
| 6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string_util.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/test/automation/dom_element_proxy.h" | 16 #include "chrome/test/automation/dom_element_proxy.h" |
| 17 | 17 |
| 18 // ValueConversionTraits contains functions for creating a value from a | 18 // ValueConversionTraits contains functions for creating a value from a |
| 19 // type, and setting a type from a value. This is general-purpose and can | 19 // type, and setting a type from a value. This is general-purpose and can |
| 20 // be moved to a common location if needed. | 20 // be moved to a common location if needed. |
| 21 template <class T> | 21 template <class T> |
| 22 struct ValueConversionTraits { | 22 struct ValueConversionTraits { |
| 23 }; | 23 }; |
| 24 | 24 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 std::string javascript; | 110 std::string javascript; |
| 111 scoped_ptr<Value> value(ValueConversionTraits<T>::CreateValue(arg)); | 111 scoped_ptr<Value> value(ValueConversionTraits<T>::CreateValue(arg)); |
| 112 base::JSONWriter::Write(value.get(), false, &javascript); | 112 base::JSONWriter::Write(value.get(), false, &javascript); |
| 113 return javascript; | 113 return javascript; |
| 114 } | 114 } |
| 115 | 115 |
| 116 // Converts |arg| to a JSON string and returns a string formatted as | 116 // Converts |arg| to a JSON string and returns a string formatted as |
| 117 // |format| specifies. |format| should only expect string arguments. | 117 // |format| specifies. |format| should only expect string arguments. |
| 118 template <typename T> | 118 template <typename T> |
| 119 std::string JavaScriptPrintf(const std::string& format, const T& arg) { | 119 std::string JavaScriptPrintf(const std::string& format, const T& arg) { |
| 120 return StringPrintf(format.c_str(), JSONStringify(arg).c_str()); | 120 return base::StringPrintf(format.c_str(), JSONStringify(arg).c_str()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Similar to above, but with an additional argument. | 123 // Similar to above, but with an additional argument. |
| 124 template <typename T1, typename T2> | 124 template <typename T1, typename T2> |
| 125 std::string JavaScriptPrintf(const std::string& format, const T1& arg1, | 125 std::string JavaScriptPrintf(const std::string& format, const T1& arg1, |
| 126 const T2& arg2) { | 126 const T2& arg2) { |
| 127 return StringPrintf(format.c_str(), | 127 return base::StringPrintf(format.c_str(), |
| 128 JSONStringify(arg1).c_str(), | 128 JSONStringify(arg1).c_str(), |
| 129 JSONStringify(arg2).c_str()); | 129 JSONStringify(arg2).c_str()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Similar to above, but with an additional argument. | 132 // Similar to above, but with an additional argument. |
| 133 template <typename T1, typename T2, typename T3> | 133 template <typename T1, typename T2, typename T3> |
| 134 std::string JavaScriptPrintf(const std::string& format, const T1& arg1, | 134 std::string JavaScriptPrintf(const std::string& format, const T1& arg1, |
| 135 const T2& arg2, const T3& arg3) { | 135 const T2& arg2, const T3& arg3) { |
| 136 return StringPrintf(format.c_str(), | 136 return base::StringPrintf(format.c_str(), |
| 137 JSONStringify(arg1).c_str(), | 137 JSONStringify(arg1).c_str(), |
| 138 JSONStringify(arg2).c_str(), | 138 JSONStringify(arg2).c_str(), |
| 139 JSONStringify(arg3).c_str()); | 139 JSONStringify(arg3).c_str()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace javascript_utils | 142 } // namespace javascript_utils |
| 143 | 143 |
| 144 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 144 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
| OLD | NEW |