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

Side by Side Diff: chrome/test/automation/javascript_message_utils.h

Issue 9590002: JSONWriter cleanup: integrate pretty print into write options. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflict 7. Created 8 years, 9 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
OLDNEW
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>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 }; 71 };
72 72
73 namespace javascript_utils { 73 namespace javascript_utils {
74 74
75 // Converts |arg| to a JSON string. 75 // Converts |arg| to a JSON string.
76 template <typename T> 76 template <typename T>
77 std::string JSONStringify(const T& arg) { 77 std::string JSONStringify(const T& arg) {
78 std::string javascript; 78 std::string javascript;
79 scoped_ptr<Value> value(ValueConversionTraits<T>::CreateValueFrom(arg)); 79 scoped_ptr<Value> value(ValueConversionTraits<T>::CreateValueFrom(arg));
80 base::JSONWriter::Write(value.get(), false, &javascript); 80 base::JSONWriter::Write(value.get(), &javascript);
81 return javascript; 81 return javascript;
82 } 82 }
83 83
84 // Converts |arg| to a JSON string and returns a string formatted as 84 // Converts |arg| to a JSON string and returns a string formatted as
85 // |format| specifies. |format| should only expect string arguments. 85 // |format| specifies. |format| should only expect string arguments.
86 template <typename T> 86 template <typename T>
87 std::string JavaScriptPrintf(const std::string& format, const T& arg) { 87 std::string JavaScriptPrintf(const std::string& format, const T& arg) {
88 return base::StringPrintf(format.c_str(), JSONStringify(arg).c_str()); 88 return base::StringPrintf(format.c_str(), JSONStringify(arg).c_str());
89 } 89 }
90 90
(...skipping 12 matching lines...) Expand all
103 const T2& arg2, const T3& arg3) { 103 const T2& arg2, const T3& arg3) {
104 return base::StringPrintf(format.c_str(), 104 return base::StringPrintf(format.c_str(),
105 JSONStringify(arg1).c_str(), 105 JSONStringify(arg1).c_str(),
106 JSONStringify(arg2).c_str(), 106 JSONStringify(arg2).c_str(),
107 JSONStringify(arg3).c_str()); 107 JSONStringify(arg3).c_str());
108 } 108 }
109 109
110 } // namespace javascript_utils 110 } // namespace javascript_utils
111 111
112 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ 112 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_
OLDNEW
« no previous file with comments | « chrome/test/automation/automation_json_requests.cc ('k') | chrome/test/webdriver/commands/response.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698