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

Unified Diff: chrome/test/webdriver/webdriver_util.cc

Issue 8341044: Enhance and refactor ChromeDriver's capability handling. Log warning for (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 2 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/test/webdriver/webdriver_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/webdriver/webdriver_util.cc
diff --git a/chrome/test/webdriver/webdriver_util.cc b/chrome/test/webdriver/webdriver_util.cc
index 45e080f378877a307f30559fc5ff90e609ecd48e..5440d5ac0fa5862ef4c3befc468f8d779a61d65f 100644
--- a/chrome/test/webdriver/webdriver_util.cc
+++ b/chrome/test/webdriver/webdriver_util.cc
@@ -7,9 +7,13 @@
#include "base/basictypes.h"
#include "base/format_macros.h"
#include "base/json/json_writer.h"
+#include "base/memory/scoped_ptr.h"
#include "base/rand_util.h"
#include "base/stringprintf.h"
-#include "base/values.h"
+
+using base::DictionaryValue;
+using base::ListValue;
+using base::Value;
namespace webdriver {
@@ -27,6 +31,91 @@ std::string JsonStringify(const Value* value) {
return json;
}
+namespace {
+
+// Truncates the given string to 40 characters, adding an ellipsis if
+// truncation was necessary.
+void TruncateString(std::string* data) {
+ if (data->length() > 40) {
+ data->resize(40);
+ data->replace(37, 3, "...");
+ }
+}
+
+// Truncates all strings contained in the given value.
+void TruncateContainedStrings(Value* value) {
+ ListValue* list;
+ if (value->IsType(Value::TYPE_DICTIONARY)) {
+ DictionaryValue* dict = static_cast<DictionaryValue*>(value);
+ DictionaryValue::key_iterator key = dict->begin_keys();
+ for (; key != dict->end_keys(); ++key) {
+ Value* child;
+ if (!dict->GetWithoutPathExpansion(*key, &child))
+ continue;
+ std::string data;
+ if (child->GetAsString(&data)) {
+ TruncateString(&data);
+ dict->SetWithoutPathExpansion(*key, Value::CreateStringValue(data));
+ } else {
+ TruncateContainedStrings(child);
+ }
+ }
+ } else if (value->GetAsList(&list)) {
+ for (size_t i = 0; i < list->GetSize(); ++i) {
+ Value* child;
+ if (!list->Get(i, &child))
+ continue;
+ std::string data;
+ if (child->GetAsString(&data)) {
+ TruncateString(&data);
+ list->Set(i, Value::CreateStringValue(data));
+ } else {
+ TruncateContainedStrings(child);
+ }
+ }
+ }
+}
+
+} // namespace
+
+std::string JsonStringifyForDisplay(const Value* value) {
+ scoped_ptr<Value> copy;
+ if (value->IsType(Value::TYPE_STRING)) {
+ std::string data;
+ value->GetAsString(&data);
+ TruncateString(&data);
+ copy.reset(Value::CreateStringValue(data));
+ } else {
+ copy.reset(value->DeepCopy());
+ TruncateContainedStrings(copy.get());
+ }
+ std::string json;
+ base::JSONWriter::Write(copy.get(), true /* pretty_print */, &json);
+ return json;
+}
+
+const char* GetJsonTypeName(Value::Type type) {
+ switch (type) {
+ case Value::TYPE_NULL:
+ return "null";
+ case Value::TYPE_BOOLEAN:
+ return "boolean";
+ case Value::TYPE_INTEGER:
+ return "integer";
+ case Value::TYPE_DOUBLE:
+ return "double";
+ case Value::TYPE_STRING:
+ return "string";
+ case Value::TYPE_BINARY:
+ return "binary";
+ case Value::TYPE_DICTIONARY:
+ return "dictionary";
+ case Value::TYPE_LIST:
+ return "list";
+ }
+ return "unknown";
+}
+
ValueParser::ValueParser() { }
ValueParser::~ValueParser() { }
@@ -34,11 +123,11 @@ ValueParser::~ValueParser() { }
} // namespace webdriver
bool ValueConversionTraits<webdriver::SkipParsing>::SetFromValue(
- const base::Value* value, const webdriver::SkipParsing* t) {
+ const Value* value, const webdriver::SkipParsing* t) {
return true;
}
bool ValueConversionTraits<webdriver::SkipParsing>::CanConvert(
- const base::Value* value) {
+ const Value* value) {
return true;
}
« no previous file with comments | « chrome/test/webdriver/webdriver_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698