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

Side by Side Diff: components/json_schema/json_schema_validator_unittest.cc

Issue 94043003: Ignore unknown attributes when parsing JSON schemas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added flag Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "base/values.h" 5 #include "base/values.h"
6 #include "components/json_schema/json_schema_validator.h" 6 #include "components/json_schema/json_schema_validator.h"
7 #include "components/json_schema/json_schema_validator_unittest_base.h" 7 #include "components/json_schema/json_schema_validator_unittest_base.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase { 10 class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 << test_source; 47 << test_source;
48 } 48 }
49 }; 49 };
50 50
51 TEST_F(JSONSchemaValidatorCPPTest, Test) { 51 TEST_F(JSONSchemaValidatorCPPTest, Test) {
52 RunTests(); 52 RunTests();
53 } 53 }
54 54
55 TEST(JSONSchemaValidator, IsValidSchema) { 55 TEST(JSONSchemaValidator, IsValidSchema) {
56 std::string error; 56 std::string error;
57 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("", &error)); 57 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("", false, &error));
58 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\0", &error)); 58 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\0", false, &error));
59 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("string", &error)); 59 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("string", false, &error));
60 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\"string\"", &error)); 60 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\"string\"", false, &error));
61 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("[]", &error)); 61 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("[]", false, &error));
62 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("{}", &error)); 62 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("{}", false, &error));
63 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( 63 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
64 "{ \"type\": 123 }", &error)); 64 "{ \"type\": 123 }", false, &error));
65 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( 65 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
66 "{ \"type\": \"invalid\" }", &error)); 66 "{ \"type\": \"invalid\" }", false, &error));
67 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( 67 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
68 "{" 68 "{"
69 " \"type\": \"object\"," 69 " \"type\": \"object\","
70 " \"properties\": []" // Invalid properties type. 70 " \"properties\": []" // Invalid properties type.
71 "}", &error)); 71 "}", false, &error));
72 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( 72 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
73 "{" 73 "{"
74 " \"type\": \"string\"," 74 " \"type\": \"string\","
75 " \"maxLength\": -1" // Must be >= 0. 75 " \"maxLength\": -1" // Must be >= 0.
76 "}", &error)); 76 "}", false, &error));
77 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( 77 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
78 "{" 78 "{"
79 " \"type\": \"string\"," 79 " \"type\": \"string\","
80 " \"enum\": [ {} ]" // "enum" dict values must contain "name". 80 " \"enum\": [ {} ]" // "enum" dict values must contain "name".
81 "}", &error)); 81 "}", false, &error));
82 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( 82 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
83 "{" 83 "{"
84 " \"type\": \"string\"," 84 " \"type\": \"string\","
85 " \"enum\": [ { \"name\": {} } ]" // "enum" name must be a simple value. 85 " \"enum\": [ { \"name\": {} } ]" // "enum" name must be a simple value.
86 "}", 86 "}", false, &error));
87 &error));
88 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( 87 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
89 "{" 88 "{"
90 " \"type\": \"array\"," 89 " \"type\": \"array\","
91 " \"items\": [ 123 ]," // "items" must contain a schema or schemas. 90 " \"items\": [ 123 ]," // "items" must contain a schema or schemas.
92 "}", &error)); 91 "}", false, &error));
93 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( 92 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
94 "{ \"type\": \"object\" }", &error)) << error; 93 "{ \"type\": \"object\" }", false, &error)) << error;
95 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( 94 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
96 "{ \"type\": [\"object\", \"array\"] }", &error)) << error; 95 "{ \"type\": [\"object\", \"array\"] }", false, &error)) << error;
97 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( 96 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
98 "{" 97 "{"
99 " \"type\": [\"object\", \"array\"]," 98 " \"type\": [\"object\", \"array\"],"
100 " \"properties\": {" 99 " \"properties\": {"
101 " \"string-property\": {" 100 " \"string-property\": {"
102 " \"type\": \"string\"," 101 " \"type\": \"string\","
103 " \"minLength\": 1," 102 " \"minLength\": 1,"
104 " \"maxLength\": 100," 103 " \"maxLength\": 100,"
105 " \"title\": \"The String Policy\"," 104 " \"title\": \"The String Policy\","
106 " \"description\": \"This policy controls the String widget.\"" 105 " \"description\": \"This policy controls the String widget.\""
(...skipping 17 matching lines...) Expand all
124 " \"type\": \"array\"," 123 " \"type\": \"array\","
125 " \"items\": [" 124 " \"items\": ["
126 " { \"type\": \"string\" }," 125 " { \"type\": \"string\" },"
127 " { \"type\": \"integer\" }" 126 " { \"type\": \"integer\" }"
128 " ]" 127 " ]"
129 " }" 128 " }"
130 " }," 129 " },"
131 " \"additionalProperties\": {" 130 " \"additionalProperties\": {"
132 " \"type\": \"any\"" 131 " \"type\": \"any\""
133 " }" 132 " }"
134 "}", &error)) << error; 133 "}", false, &error)) << error;
134 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
135 "{"
136 " \"type\": \"object\","
137 " \"unknown attribute\": \"that should just be ignored\""
138 "}", true, &error)) << error;
139 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
140 "{"
141 " \"type\": \"object\","
142 " \"unknown attribute\": \"that will cause a failure\""
143 "}", false, &error)) << error;
135 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698