Revert 224458 "Enabling MediaStreamInfoBarTest.DenyingCameraDoes..."
[chromium-blink-merge.git] / tools / json_schema_compiler / test / crossref_unittest.cc
blobd2747fdca4ca56f465f4febc27e43408ae854d3e
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<DictionaryValue> CreateTestTypeDictionary() {
15 DictionaryValue* value(new DictionaryValue());
16 value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(1.1));
17 value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(4));
18 value->SetWithoutPathExpansion("string", Value::CreateStringValue("bling"));
19 value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(true));
20 return scoped_ptr<DictionaryValue>(value);
23 } // namespace
25 TEST(JsonSchemaCompilerCrossrefTest, CrossrefTypePopulate) {
26 scoped_ptr<CrossrefType> crossref_type(new CrossrefType());
27 scoped_ptr<DictionaryValue> value(new DictionaryValue());
28 value->Set("testType", CreateTestTypeDictionary().release());
29 EXPECT_TRUE(CrossrefType::Populate(*value, crossref_type.get()));
30 EXPECT_TRUE(crossref_type->test_type.get());
31 EXPECT_TRUE(CreateTestTypeDictionary()->Equals(
32 crossref_type->test_type->ToValue().get()));
33 EXPECT_TRUE(value->Equals(crossref_type->ToValue().get()));
36 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamCreate) {
37 scoped_ptr<ListValue> params_value(new ListValue());
38 params_value->Append(CreateTestTypeDictionary().release());
39 scoped_ptr<TestTypeOptionalParam::Params> params(
40 TestTypeOptionalParam::Params::Create(*params_value));
41 EXPECT_TRUE(params.get());
42 EXPECT_TRUE(params->test_type.get());
43 EXPECT_TRUE(
44 CreateTestTypeDictionary()->Equals(params->test_type->ToValue().get()));
47 TEST(JsonSchemaCompilerCrossrefTest, TestTypeOptionalParamFail) {
48 scoped_ptr<ListValue> params_value(new ListValue());
49 scoped_ptr<DictionaryValue> test_type_value = CreateTestTypeDictionary();
50 test_type_value->RemoveWithoutPathExpansion("number", NULL);
51 params_value->Append(test_type_value.release());
52 scoped_ptr<TestTypeOptionalParam::Params> params(
53 TestTypeOptionalParam::Params::Create(*params_value));
54 EXPECT_FALSE(params.get());
57 TEST(JsonSchemaCompilerCrossrefTest, GetTestType) {
58 scoped_ptr<DictionaryValue> value = CreateTestTypeDictionary();
59 scoped_ptr<test::api::simple_api::TestType> test_type(
60 new test::api::simple_api::TestType());
61 EXPECT_TRUE(
62 test::api::simple_api::TestType::Populate(*value, test_type.get()));
64 scoped_ptr<ListValue> results = GetTestType::Results::Create(*test_type);
65 DictionaryValue* result_dict = NULL;
66 results->GetDictionary(0, &result_dict);
67 EXPECT_TRUE(value->Equals(result_dict));
70 TEST(JsonSchemaCompilerCrossrefTest, TestTypeInObjectParamsCreate) {
72 scoped_ptr<ListValue> params_value(new ListValue());
73 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue());
74 param_object_value->Set("testType", CreateTestTypeDictionary().release());
75 param_object_value->Set("boolean", Value::CreateBooleanValue(true));
76 params_value->Append(param_object_value.release());
77 scoped_ptr<TestTypeInObject::Params> params(
78 TestTypeInObject::Params::Create(*params_value));
79 EXPECT_TRUE(params.get());
80 EXPECT_TRUE(params->param_object.test_type.get());
81 EXPECT_TRUE(params->param_object.boolean);
82 EXPECT_TRUE(CreateTestTypeDictionary()->Equals(
83 params->param_object.test_type->ToValue().get()));
86 scoped_ptr<ListValue> params_value(new ListValue());
87 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue());
88 param_object_value->Set("boolean", Value::CreateBooleanValue(true));
89 params_value->Append(param_object_value.release());
90 scoped_ptr<TestTypeInObject::Params> params(
91 TestTypeInObject::Params::Create(*params_value));
92 EXPECT_TRUE(params.get());
93 EXPECT_FALSE(params->param_object.test_type.get());
94 EXPECT_TRUE(params->param_object.boolean);
97 scoped_ptr<ListValue> params_value(new ListValue());
98 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue());
99 param_object_value->Set("testType", Value::CreateStringValue("invalid"));
100 param_object_value->Set("boolean", Value::CreateBooleanValue(true));
101 params_value->Append(param_object_value.release());
102 scoped_ptr<TestTypeInObject::Params> params(
103 TestTypeInObject::Params::Create(*params_value));
104 EXPECT_FALSE(params.get());
107 scoped_ptr<ListValue> params_value(new ListValue());
108 scoped_ptr<DictionaryValue> param_object_value(new DictionaryValue());
109 param_object_value->Set("testType", CreateTestTypeDictionary().release());
110 params_value->Append(param_object_value.release());
111 scoped_ptr<TestTypeInObject::Params> params(
112 TestTypeInObject::Params::Create(*params_value));
113 EXPECT_FALSE(params.get());