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.
4
5#include "base/values.h"
6#include "testing/gtest/include/gtest/gtest.h"
7#include "tools/json_schema_compiler/test/functions_on_types.h"
8
9using namespace test::api::functions_on_types;
10
11TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetParamsCreate) {
12  {
13    scoped_ptr<base::ListValue> params_value(new base::ListValue());
14    scoped_ptr<StorageArea::Get::Params> params(
15        StorageArea::Get::Params::Create(*params_value));
16    ASSERT_TRUE(params);
17    EXPECT_FALSE(params->keys);
18  }
19  {
20    scoped_ptr<base::ListValue> params_value(new base::ListValue());
21    params_value->Append(new base::FundamentalValue(9));
22    scoped_ptr<StorageArea::Get::Params> params(
23        StorageArea::Get::Params::Create(*params_value));
24    EXPECT_FALSE(params);
25  }
26  {
27    scoped_ptr<base::ListValue> params_value(new base::ListValue());
28    params_value->Append(new base::StringValue("test"));
29    scoped_ptr<StorageArea::Get::Params> params(
30        StorageArea::Get::Params::Create(*params_value));
31    ASSERT_TRUE(params);
32    ASSERT_TRUE(params->keys);
33    EXPECT_EQ("test", *params->keys->as_string);
34  }
35  {
36    scoped_ptr<base::DictionaryValue> keys_object_value(
37        new base::DictionaryValue());
38    keys_object_value->SetInteger("integer", 5);
39    keys_object_value->SetString("string", "string");
40    scoped_ptr<base::ListValue> params_value(new base::ListValue());
41    params_value->Append(keys_object_value->DeepCopy());
42    scoped_ptr<StorageArea::Get::Params> params(
43        StorageArea::Get::Params::Create(*params_value));
44    ASSERT_TRUE(params);
45    ASSERT_TRUE(params->keys);
46    EXPECT_TRUE(keys_object_value->Equals(
47        &params->keys->as_object->additional_properties));
48  }
49}
50
51TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetResultCreate) {
52  StorageArea::Get::Results::Items items;
53  items.additional_properties.SetDouble("asdf", 0.1);
54  items.additional_properties.SetString("sdfg", "zxcv");
55  scoped_ptr<base::ListValue> results =
56      StorageArea::Get::Results::Create(items);
57  base::DictionaryValue* item_result = NULL;
58  ASSERT_TRUE(results->GetDictionary(0, &item_result));
59  EXPECT_TRUE(item_result->Equals(&items.additional_properties));
60}
61
62TEST(JsonSchemaCompilerFunctionsOnTypesTest, ChromeSettingGetParamsCreate) {
63  scoped_ptr<base::DictionaryValue> details_value(new base::DictionaryValue());
64  details_value->SetBoolean("incognito", true);
65  scoped_ptr<base::ListValue> params_value(new base::ListValue());
66  params_value->Append(details_value.release());
67  scoped_ptr<ChromeSetting::Get::Params> params(
68      ChromeSetting::Get::Params::Create(*params_value));
69  EXPECT_TRUE(params.get());
70  EXPECT_TRUE(*params->details.incognito);
71}
72