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

Side by Side Diff: chrome/browser/policy/policy_schema_unittest.cc

Issue 15133005: Added a PolicySchema class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/policy_schema.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace policy {
10
11 namespace {
12
13 #define SCHEMA_VERSION "\"$schema\":\"http://json-schema.org/draft-03/schema#\""
14 #define OBJECT_TYPE "\"type\":\"object\""
15
16 bool ParseFails(const std::string& content) {
17 std::string error;
18 scoped_ptr<PolicySchema> schema = PolicySchema::Parse(content, &error);
19 EXPECT_TRUE(schema || !error.empty());
20 return !schema;
21 }
22
23 } // namespace
24
25 TEST(PolicySchemaTest, MinimalSchema) {
26 EXPECT_FALSE(ParseFails(
27 "{"
28 SCHEMA_VERSION ","
29 OBJECT_TYPE
30 "}"));
31 }
32
33 TEST(PolicySchemaTest, InvalidSchemas) {
34 EXPECT_TRUE(ParseFails(""));
35 EXPECT_TRUE(ParseFails("omg"));
36 EXPECT_TRUE(ParseFails("\"omg\""));
37 EXPECT_TRUE(ParseFails("123"));
38 EXPECT_TRUE(ParseFails("[]"));
39 EXPECT_TRUE(ParseFails("null"));
40 EXPECT_TRUE(ParseFails("{}"));
Mattias Nissler (ping if slow) 2013/05/15 10:04:12 Many of these seem redundant, given that you rely
Joao da Silva 2013/05/19 13:17:08 It's true that the JSONSchemaValidator tests cover
41 EXPECT_TRUE(ParseFails("{" SCHEMA_VERSION "}"));
42 EXPECT_TRUE(ParseFails("{" OBJECT_TYPE "}"));
43
44 EXPECT_TRUE(ParseFails(
45 "{"
46 SCHEMA_VERSION ","
47 OBJECT_TYPE ","
48 "\"additionalProperties\": { \"type\":\"object\" }"
49 "}"));
50
51 EXPECT_TRUE(ParseFails(
52 "{"
53 SCHEMA_VERSION ","
54 OBJECT_TYPE ","
55 "\"patternProperties\": { \"a+b*\": { \"type\": \"object\" } }"
56 "}"));
57
58 EXPECT_TRUE(ParseFails(
59 "{"
60 SCHEMA_VERSION ","
61 OBJECT_TYPE ","
62 "\"properties\": { \"Policy\": { \"type\": \"bogus\" } }"
63 "}"));
64
65 EXPECT_TRUE(ParseFails(
66 "{"
67 SCHEMA_VERSION ","
68 OBJECT_TYPE ","
69 "\"properties\": { \"Policy\": { \"type\": [\"string\", \"number\"] } }"
70 "}"));
71
72 EXPECT_TRUE(ParseFails(
73 "{"
74 SCHEMA_VERSION ","
75 OBJECT_TYPE ","
76 "\"properties\": { \"Policy\": { \"type\": \"any\" } }"
77 "}"));
78 }
79
80 TEST(PolicySchemaTest, TypeMap) {
81 std::string error;
82 scoped_ptr<PolicySchema> schema = PolicySchema::Parse(
83 "{"
84 SCHEMA_VERSION ","
85 OBJECT_TYPE ","
86 "\"properties\": {"
87 " \"Array\": { \"type\": \"array\" },"
88 " \"Boolean\": { \"type\": \"boolean\" },"
89 " \"Integer\": { \"type\": \"integer\" },"
90 " \"Null\": { \"type\": \"null\" },"
91 " \"Number\": { \"type\": \"number\" },"
92 " \"Object\": { \"type\": \"object\" },"
93 " \"String\": { \"type\": \"string\" }"
94 "}"
95 "}", &error);
96 ASSERT_TRUE(schema);
97
98 PolicySchema::TypeMap map;
99 map["Array"] = base::Value::TYPE_LIST;
100 map["Boolean"] = base::Value::TYPE_BOOLEAN;
101 map["Integer"] = base::Value::TYPE_INTEGER;
102 map["Null"] = base::Value::TYPE_NULL;
103 map["Number"] = base::Value::TYPE_DOUBLE;
104 map["Object"] = base::Value::TYPE_DICTIONARY;
105 map["String"] = base::Value::TYPE_STRING;
106
107 EXPECT_EQ(map, schema->type_map());
108 }
109
110 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698