Roll src/third_party/WebKit f007c95:0171005 (svn 185074:185088)
[chromium-blink-merge.git] / tools / json_schema_compiler / test / objects_unittest.cc
blob6dc2c4548d2e8c70f96ef0e618d117b8eb903b6f
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/objects.h"
7 #include "base/json/json_writer.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using namespace test::api::objects;
12 TEST(JsonSchemaCompilerObjectsTest, ObjectParamParamsCreate) {
14 scoped_ptr<base::ListValue> strings(new base::ListValue());
15 strings->Append(new base::StringValue("one"));
16 strings->Append(new base::StringValue("two"));
17 scoped_ptr<base::DictionaryValue> info_value(new base::DictionaryValue());
18 info_value->Set("strings", strings.release());
19 info_value->Set("integer", new base::FundamentalValue(5));
20 info_value->Set("boolean", new base::FundamentalValue(true));
22 scoped_ptr<base::ListValue> params_value(new base::ListValue());
23 params_value->Append(info_value.release());
24 scoped_ptr<ObjectParam::Params> params(
25 ObjectParam::Params::Create(*params_value));
26 EXPECT_TRUE(params.get());
27 EXPECT_EQ((size_t) 2, params->info.strings.size());
28 EXPECT_EQ("one", params->info.strings[0]);
29 EXPECT_EQ("two", params->info.strings[1]);
30 EXPECT_EQ(5, params->info.integer);
31 EXPECT_TRUE(params->info.boolean);
34 scoped_ptr<base::ListValue> strings(new base::ListValue());
35 strings->Append(new base::StringValue("one"));
36 strings->Append(new base::StringValue("two"));
37 scoped_ptr<base::DictionaryValue> info_value(new base::DictionaryValue());
38 info_value->Set("strings", strings.release());
39 info_value->Set("integer", new base::FundamentalValue(5));
41 scoped_ptr<base::ListValue> params_value(new base::ListValue());
42 params_value->Append(info_value.release());
43 scoped_ptr<ObjectParam::Params> params(
44 ObjectParam::Params::Create(*params_value));
45 EXPECT_FALSE(params.get());
49 TEST(JsonSchemaCompilerObjectsTest, ReturnsObjectResultCreate) {
50 ReturnsObject::Results::Info info;
51 info.state = ReturnsObject::Results::Info::STATE_FOO;
52 scoped_ptr<base::ListValue> results = ReturnsObject::Results::Create(info);
54 base::DictionaryValue expected;
55 expected.SetString("state", "foo");
56 base::DictionaryValue* result = NULL;
57 ASSERT_TRUE(results->GetDictionary(0, &result));
58 ASSERT_TRUE(result->Equals(&expected));
61 TEST(JsonSchemaCompilerObjectsTest, OnObjectFiredCreate) {
62 OnObjectFired::SomeObject object;
63 object.state = OnObjectFired::SomeObject::STATE_BAR;
64 scoped_ptr<base::ListValue> results(OnObjectFired::Create(object));
66 base::DictionaryValue expected;
67 expected.SetString("state", "bar");
68 base::DictionaryValue* result = NULL;
69 ASSERT_TRUE(results->GetDictionary(0, &result));
70 ASSERT_TRUE(result->Equals(&expected));