Enforce minimum visibility only for normal and panel windows
[chromium-blink-merge.git] / tools / json_schema_compiler / test / crossref_unittest.cc
blobdf91b2d29a123e08d4782d75963e73626c445c7d
1 // Copyright (c) 2012 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.
5 #include "tools/json_schema_compiler/test/simple_api.h"
6 #include "tools/json_schema_compiler/test/crossref.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using namespace test::api::crossref;
12 namespace {
14 static scoped_ptr<base::DictionaryValue> CreateTestTypeDictionary() {
15 base::DictionaryValue* value(new base::DictionaryValue());
16 value->SetWithoutPathExpansion("number", base::Value::CreateDoubleValue(1.1));
17 value->SetWithoutPathExpansion("integer", base::Value::CreateIntegerValue(4));
18 value->SetWithoutPathExpansion("string",
19 base::Value::CreateStringValue("bling"));
20 value->SetWithoutPathExpansion("boolean",
21 base::Value::CreateBooleanValue(true));
22 return scoped_ptr<base::DictionaryValue>(value);
25 } // namespace
27 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulate) {
28 scoped_ptr<CrossrefType> crossref_type(new CrossrefType());
29 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
30 value->Set("testType", CreateTestTypeDictionary().release());
31 EXPECT_TRUE(CrossrefType::Populate(*value, crossref_type.get()));
32 EXPECT_TRUE(crossref_type->test_type.get());
33 EXPECT_TRUE(CreateTestTypeDictionary()->Equals(
34 crossref_type->test_type->ToValue().get()));
35 EXPECT_TRUE(value->Equals(crossref_type->ToValue().get()));
38 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) {
39 scoped_ptr<base::ListValue> params_value(new base::ListValue());
40 params_value->Append(CreateTestTypeDictionary().release());
41 scoped_ptr<TestTypeOptionalParam::Params> params(
42 TestTypeOptionalParam::Params::Create(*params_value));
43 EXPECT_TRUE(params.get());
44 EXPECT_TRUE(params->test_type.get());
45 EXPECT_TRUE(
46 CreateTestTypeDictionary()->Equals(params->test_type->ToValue().get()));
49 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) {
50 scoped_ptr<base::ListValue> params_value(new base::ListValue());
51 scoped_ptr<base::DictionaryValue> test_type_value =
52 CreateTestTypeDictionary();
53 test_type_value->RemoveWithoutPathExpansion("number", NULL);
54 params_value->Append(test_type_value.release());
55 scoped_ptr<TestTypeOptionalParam::Params> params(
56 TestTypeOptionalParam::Params::Create(*params_value));
57 EXPECT_FALSE(params.get());
60 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) {
61 scoped_ptr<base::DictionaryValue> value = CreateTestTypeDictionary();
62 scoped_ptr<test::api::simple_api::TestType> test_type(
63 new test::api::simple_api::TestType());
64 EXPECT_TRUE(
65 test::api::simple_api::TestType::Populate(*value, test_type.get()));
67 scoped_ptr<base::ListValue> results =
68 GetTestType::Results::Create(*test_type);
69 base::DictionaryValue* result_dict = NULL;
70 results->GetDictionary(0, &result_dict);
71 EXPECT_TRUE(value->Equals(result_dict));
74 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) {
76 scoped_ptr<base::ListValue> params_value(new base::ListValue());
77 scoped_ptr<base::DictionaryValue> param_object_value(
78 new base::DictionaryValue());
79 param_object_value->Set("testType", CreateTestTypeDictionary().release());
80 param_object_value->Set("boolean", base::Value::CreateBooleanValue(true));
81 params_value->Append(param_object_value.release());
82 scoped_ptr<TestTypeInObject::Params> params(
83 TestTypeInObject::Params::Create(*params_value));
84 EXPECT_TRUE(params.get());
85 EXPECT_TRUE(params->param_object.test_type.get());
86 EXPECT_TRUE(params->param_object.boolean);
87 EXPECT_TRUE(CreateTestTypeDictionary()->Equals(
88 params->param_object.test_type->ToValue().get()));
91 scoped_ptr<base::ListValue> params_value(new base::ListValue());
92 scoped_ptr<base::DictionaryValue> param_object_value(
93 new base::DictionaryValue());
94 param_object_value->Set("boolean", base::Value::CreateBooleanValue(true));
95 params_value->Append(param_object_value.release());
96 scoped_ptr<TestTypeInObject::Params> params(
97 TestTypeInObject::Params::Create(*params_value));
98 EXPECT_TRUE(params.get());
99 EXPECT_FALSE(params->param_object.test_type.get());
100 EXPECT_TRUE(params->param_object.boolean);
103 scoped_ptr<base::ListValue> params_value(new base::ListValue());
104 scoped_ptr<base::DictionaryValue> param_object_value(
105 new base::DictionaryValue());
106 param_object_value->Set("testType",
107 base::Value::CreateStringValue("invalid"));
108 param_object_value->Set("boolean", base::Value::CreateBooleanValue(true));
109 params_value->Append(param_object_value.release());
110 scoped_ptr<TestTypeInObject::Params> params(
111 TestTypeInObject::Params::Create(*params_value));
112 EXPECT_FALSE(params.get());
115 scoped_ptr<base::ListValue> params_value(new base::ListValue());
116 scoped_ptr<base::DictionaryValue> param_object_value(
117 new base::DictionaryValue());
118 param_object_value->Set("testType", CreateTestTypeDictionary().release());
119 params_value->Append(param_object_value.release());
120 scoped_ptr<TestTypeInObject::Params> params(
121 TestTypeInObject::Params::Create(*params_value));
122 EXPECT_FALSE(params.get());