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

Unified Diff: third_party/WebKit/Source/platform/inspector_protocol/ParserTest.cpp

Issue 1738073002: DevTools: introduce protocol::Value, baseline for hierarchical data in remote debugging protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
Index: third_party/WebKit/Source/platform/inspector_protocol/ParserTest.cpp
diff --git a/third_party/WebKit/Source/platform/JSONParserTest.cpp b/third_party/WebKit/Source/platform/inspector_protocol/ParserTest.cpp
similarity index 83%
copy from third_party/WebKit/Source/platform/JSONParserTest.cpp
copy to third_party/WebKit/Source/platform/inspector_protocol/ParserTest.cpp
index 8e5a80c7c460c766c72e309c0c2bc2026d818a98..415b36ce683003d25448c7107797c1132bdef9c8 100644
--- a/third_party/WebKit/Source/platform/JSONParserTest.cpp
+++ b/third_party/WebKit/Source/platform/inspector_protocol/ParserTest.cpp
@@ -2,26 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "platform/JSONParser.h"
+#include "platform/inspector_protocol/Parser.h"
-#include "platform/JSONValues.h"
+#include "platform/inspector_protocol/Values.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/text/StringBuilder.h"
namespace blink {
+namespace protocol {
-TEST(JSONParserTest, Reading)
+TEST(ParserTest, Reading)
{
- RefPtr<JSONValue> tmpValue;
- RefPtr<JSONValue> root;
- RefPtr<JSONValue> root2;
+ RefPtr<protocol::Value> tmpValue;
+ RefPtr<protocol::Value> root;
+ RefPtr<protocol::Value> root2;
String strVal;
int intVal = 0;
// some whitespace checking
root = parseJSON(" null ");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNull, root->type());
+ EXPECT_EQ(Value::TypeNull, root->type());
// Invalid JSON string
root = parseJSON("nu");
@@ -30,34 +31,34 @@ TEST(JSONParserTest, Reading)
// Simple bool
root = parseJSON("true ");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeBoolean, root->type());
+ EXPECT_EQ(Value::TypeBoolean, root->type());
// Embedded comment
root = parseJSON("40 /*/");
EXPECT_FALSE(root.get());
root = parseJSON("/* comment */null");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNull, root->type());
+ EXPECT_EQ(Value::TypeNull, root->type());
root = parseJSON("40 /* comment */");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
EXPECT_TRUE(root->asNumber(&intVal));
EXPECT_EQ(40, intVal);
root = parseJSON("/**/ 40 /* multi-line\n comment */ // more comment");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
EXPECT_TRUE(root->asNumber(&intVal));
EXPECT_EQ(40, intVal);
root = parseJSON("true // comment");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeBoolean, root->type());
+ EXPECT_EQ(Value::TypeBoolean, root->type());
root = parseJSON("/* comment */\"sample string\"");
ASSERT_TRUE(root.get());
EXPECT_TRUE(root->asString(&strVal));
EXPECT_EQ("sample string", strVal);
root = parseJSON("[1, /* comment, 2 ] */ \n 3]");
ASSERT_TRUE(root.get());
- RefPtr<JSONArray> list = JSONArray::cast(root);
+ RefPtr<protocol::ListValue> list = ListValue::cast(root);
ASSERT_TRUE(list);
EXPECT_EQ(2u, list->length());
tmpValue = list->get(0);
@@ -70,12 +71,12 @@ TEST(JSONParserTest, Reading)
EXPECT_EQ(3, intVal);
root = parseJSON("[1, /*a*/2, 3]");
ASSERT_TRUE(root.get());
- list = JSONArray::cast(root);
+ list = ListValue::cast(root);
ASSERT_TRUE(list);
EXPECT_EQ(3u, list->length());
root = parseJSON("/* comment **/42");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
EXPECT_TRUE(root->asNumber(&intVal));
EXPECT_EQ(42, intVal);
root = parseJSON(
@@ -83,14 +84,14 @@ TEST(JSONParserTest, Reading)
"// */ 43\n"
"44");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
EXPECT_TRUE(root->asNumber(&intVal));
EXPECT_EQ(44, intVal);
// Test number formats
root = parseJSON("43");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
EXPECT_TRUE(root->asNumber(&intVal));
EXPECT_EQ(43, intVal);
@@ -106,7 +107,7 @@ TEST(JSONParserTest, Reading)
// clause).
root = parseJSON("0");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
intVal = 1;
EXPECT_TRUE(root->asNumber(&intVal));
EXPECT_EQ(0, intVal);
@@ -116,13 +117,13 @@ TEST(JSONParserTest, Reading)
root = parseJSON("2147483648");
ASSERT_TRUE(root.get());
double doubleVal;
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
doubleVal = 0.0;
EXPECT_TRUE(root->asNumber(&doubleVal));
EXPECT_DOUBLE_EQ(2147483648.0, doubleVal);
root = parseJSON("-2147483649");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
doubleVal = 0.0;
EXPECT_TRUE(root->asNumber(&doubleVal));
EXPECT_DOUBLE_EQ(-2147483649.0, doubleVal);
@@ -130,42 +131,42 @@ TEST(JSONParserTest, Reading)
// Parse a double
root = parseJSON("43.1");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
doubleVal = 0.0;
EXPECT_TRUE(root->asNumber(&doubleVal));
EXPECT_DOUBLE_EQ(43.1, doubleVal);
root = parseJSON("4.3e-1");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
doubleVal = 0.0;
EXPECT_TRUE(root->asNumber(&doubleVal));
EXPECT_DOUBLE_EQ(.43, doubleVal);
root = parseJSON("2.1e0");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
doubleVal = 0.0;
EXPECT_TRUE(root->asNumber(&doubleVal));
EXPECT_DOUBLE_EQ(2.1, doubleVal);
root = parseJSON("2.1e+0001");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
doubleVal = 0.0;
EXPECT_TRUE(root->asNumber(&doubleVal));
EXPECT_DOUBLE_EQ(21.0, doubleVal);
root = parseJSON("0.01");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
doubleVal = 0.0;
EXPECT_TRUE(root->asNumber(&doubleVal));
EXPECT_DOUBLE_EQ(0.01, doubleVal);
root = parseJSON("1.00");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeNumber, root->type());
+ EXPECT_EQ(Value::TypeNumber, root->type());
doubleVal = 0.0;
EXPECT_TRUE(root->asNumber(&doubleVal));
EXPECT_DOUBLE_EQ(1.0, doubleVal);
@@ -209,28 +210,28 @@ TEST(JSONParserTest, Reading)
// Test string parser
root = parseJSON("\"hello world\"");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeString, root->type());
+ EXPECT_EQ(Value::TypeString, root->type());
EXPECT_TRUE(root->asString(&strVal));
EXPECT_EQ("hello world", strVal);
// Empty string
root = parseJSON("\"\"");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeString, root->type());
+ EXPECT_EQ(Value::TypeString, root->type());
EXPECT_TRUE(root->asString(&strVal));
EXPECT_EQ("", strVal);
// Test basic string escapes
root = parseJSON("\" \\\"\\\\\\/\\b\\f\\n\\r\\t\\v\"");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeString, root->type());
+ EXPECT_EQ(Value::TypeString, root->type());
EXPECT_TRUE(root->asString(&strVal));
EXPECT_EQ(" \"\\/\b\f\n\r\t\v", strVal);
// Test hex and unicode escapes including the null character.
root = parseJSON("\"\\x41\\x00\\u1234\"");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeString, root->type());
+ EXPECT_EQ(Value::TypeString, root->type());
EXPECT_TRUE(root->asString(&strVal));
UChar tmp1[] = {0x41, 0, 0x1234};
EXPECT_EQ(String(tmp1, WTF_ARRAY_LENGTH(tmp1)), strVal);
@@ -252,24 +253,24 @@ TEST(JSONParserTest, Reading)
// Basic array
root = parseJSON("[true, false, null]");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeArray, root->type());
- list = JSONArray::cast(root);
+ EXPECT_EQ(Value::TypeArray, root->type());
+ list = ListValue::cast(root);
ASSERT_TRUE(list);
EXPECT_EQ(3U, list->length());
// Empty array
root = parseJSON("[]");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeArray, root->type());
- list = JSONArray::cast(root);
+ EXPECT_EQ(Value::TypeArray, root->type());
+ list = ListValue::cast(root);
ASSERT_TRUE(list);
EXPECT_EQ(0U, list->length());
// Nested arrays
root = parseJSON("[[true], [], [false, [], [null]], null]");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeArray, root->type());
- list = JSONArray::cast(root);
+ EXPECT_EQ(Value::TypeArray, root->type());
+ list = ListValue::cast(root);
ASSERT_TRUE(list);
EXPECT_EQ(4U, list->length());
@@ -291,13 +292,13 @@ TEST(JSONParserTest, Reading)
root = parseJSON("[true]");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeArray, root->type());
- list = JSONArray::cast(root);
+ EXPECT_EQ(Value::TypeArray, root->type());
+ list = ListValue::cast(root);
ASSERT_TRUE(list);
EXPECT_EQ(1U, list->length());
tmpValue = list->get(0);
ASSERT_TRUE(tmpValue.get());
- EXPECT_EQ(JSONValue::TypeBoolean, tmpValue->type());
+ EXPECT_EQ(Value::TypeBoolean, tmpValue->type());
bool boolValue = false;
EXPECT_TRUE(tmpValue->asBoolean(&boolValue));
EXPECT_TRUE(boolValue);
@@ -315,19 +316,19 @@ TEST(JSONParserTest, Reading)
// Test objects
root = parseJSON("{}");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeObject, root->type());
+ EXPECT_EQ(Value::TypeObject, root->type());
root = parseJSON("{\"number\":9.87654321, \"null\":null , \"\\x53\" : \"str\" }");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeObject, root->type());
- RefPtr<JSONObject> objectVal = JSONObject::cast(root);
+ EXPECT_EQ(Value::TypeObject, root->type());
+ RefPtr<protocol::DictionaryValue> objectVal = DictionaryValue::cast(root);
ASSERT_TRUE(objectVal);
doubleVal = 0.0;
EXPECT_TRUE(objectVal->getNumber("number", &doubleVal));
EXPECT_DOUBLE_EQ(9.87654321, doubleVal);
- RefPtr<JSONValue> nullVal = objectVal->get("null");
+ RefPtr<protocol::Value> nullVal = objectVal->get("null");
ASSERT_TRUE(nullVal.get());
- EXPECT_EQ(JSONValue::TypeNull, nullVal->type());
+ EXPECT_EQ(Value::TypeNull, nullVal->type());
EXPECT_TRUE(objectVal->getString("S", &strVal));
EXPECT_EQ("str", strVal);
@@ -353,12 +354,12 @@ TEST(JSONParserTest, Reading)
// Test nesting
root = parseJSON("{\"inner\":{\"array\":[true]},\"false\":false,\"d\":{}}");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeObject, root->type());
- objectVal = JSONObject::cast(root);
+ EXPECT_EQ(Value::TypeObject, root->type());
+ objectVal = DictionaryValue::cast(root);
ASSERT_TRUE(objectVal);
- RefPtr<JSONObject> innerObject = objectVal->getObject("inner");
+ RefPtr<protocol::DictionaryValue> innerObject = objectVal->getObject("inner");
ASSERT_TRUE(innerObject.get());
- RefPtr<JSONArray> innerArray = innerObject->getArray("array");
+ RefPtr<protocol::ListValue> innerArray = innerObject->getArray("array");
ASSERT_TRUE(innerArray.get());
EXPECT_EQ(1U, innerArray->length());
boolValue = true;
@@ -370,8 +371,8 @@ TEST(JSONParserTest, Reading)
// Test keys with periods
root = parseJSON("{\"a.b\":3,\"c\":2,\"d.e.f\":{\"g.h.i.j\":1}}");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeObject, root->type());
- objectVal = JSONObject::cast(root);
+ EXPECT_EQ(Value::TypeObject, root->type());
+ objectVal = DictionaryValue::cast(root);
ASSERT_TRUE(objectVal);
int integerValue = 0;
EXPECT_TRUE(objectVal->getNumber("a.b", &integerValue));
@@ -386,8 +387,8 @@ TEST(JSONParserTest, Reading)
root = parseJSON("{\"a\":{\"b\":2},\"a.b\":1}");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeObject, root->type());
- objectVal = JSONObject::cast(root);
+ EXPECT_EQ(Value::TypeObject, root->type());
+ objectVal = DictionaryValue::cast(root);
ASSERT_TRUE(objectVal);
innerObject = objectVal->getObject("a");
ASSERT_TRUE(innerObject.get());
@@ -445,23 +446,23 @@ TEST(JSONParserTest, Reading)
notEvil.append("[]]");
root = parseJSON(notEvil.toString());
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeArray, root->type());
- list = JSONArray::cast(root);
+ EXPECT_EQ(Value::TypeArray, root->type());
+ list = ListValue::cast(root);
ASSERT_TRUE(list);
EXPECT_EQ(5001U, list->length());
// Test utf8 encoded input
root = parseJSON("\"\\xe7\\xbd\\x91\\xe9\\xa1\\xb5\"");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeString, root->type());
+ EXPECT_EQ(Value::TypeString, root->type());
EXPECT_TRUE(root->asString(&strVal));
UChar tmp4[] = {0x7f51, 0x9875};
EXPECT_EQ(String(tmp4, WTF_ARRAY_LENGTH(tmp4)), strVal);
root = parseJSON("{\"path\": \"/tmp/\\xc3\\xa0\\xc3\\xa8\\xc3\\xb2.png\"}");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeObject, root->type());
- objectVal = JSONObject::cast(root);
+ EXPECT_EQ(Value::TypeObject, root->type());
+ objectVal = DictionaryValue::cast(root);
ASSERT_TRUE(objectVal);
EXPECT_TRUE(objectVal->getString("path", &strVal));
UChar tmp5[] = {0x2f, 0x74, 0x6d, 0x70, 0x2f, 0xe0, 0xe8, 0xf2, 0x2e, 0x70, 0x6e, 0x67};
@@ -478,14 +479,14 @@ TEST(JSONParserTest, Reading)
// Test utf16 encoded strings.
root = parseJSON("\"\\u20ac3,14\"");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeString, root->type());
+ EXPECT_EQ(Value::TypeString, root->type());
EXPECT_TRUE(root->asString(&strVal));
UChar tmp2[] = {0x20ac, 0x33, 0x2c, 0x31, 0x34};
EXPECT_EQ(String(tmp2, WTF_ARRAY_LENGTH(tmp2)), strVal);
root = parseJSON("\"\\ud83d\\udca9\\ud83d\\udc6c\"");
ASSERT_TRUE(root.get());
- EXPECT_EQ(JSONValue::TypeString, root->type());
+ EXPECT_EQ(Value::TypeString, root->type());
EXPECT_TRUE(root->asString(&strVal));
UChar tmp3[] = {0xd83d, 0xdca9, 0xd83d, 0xdc6c};
EXPECT_EQ(String(tmp3, WTF_ARRAY_LENGTH(tmp3)), strVal);
@@ -508,7 +509,7 @@ TEST(JSONParserTest, Reading)
// Test literal root objects.
root = parseJSON("null");
- EXPECT_EQ(JSONValue::TypeNull, root->type());
+ EXPECT_EQ(Value::TypeNull, root->type());
root = parseJSON("true");
ASSERT_TRUE(root.get());
@@ -526,7 +527,7 @@ TEST(JSONParserTest, Reading)
EXPECT_EQ("root", strVal);
}
-TEST(JSONParserTest, InvalidSanity)
+TEST(ParserTest, InvalidSanity)
{
const char* const invalidJson[] = {
"/* test *",
@@ -543,9 +544,10 @@ TEST(JSONParserTest, InvalidSanity)
};
for (size_t i = 0; i < WTF_ARRAY_LENGTH(invalidJson); ++i) {
- RefPtr<JSONValue> result = parseJSON(invalidJson[i]);
+ RefPtr<protocol::Value> result = parseJSON(invalidJson[i]);
EXPECT_FALSE(result.get());
}
}
+} // namespace protocol
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698