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<ListValue> params_value(new 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<ListValue> params_value(new ListValue()); 21 params_value->Append(Value::CreateIntegerValue(9)); 22 scoped_ptr<StorageArea::Get::Params> params( 23 StorageArea::Get::Params::Create(*params_value)); 24 EXPECT_FALSE(params); 25 } 26 { 27 scoped_ptr<ListValue> params_value(new ListValue()); 28 params_value->Append(Value::CreateStringValue("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<DictionaryValue> keys_object_value(new DictionaryValue()); 37 keys_object_value->SetInteger("integer", 5); 38 keys_object_value->SetString("string", "string"); 39 scoped_ptr<ListValue> params_value(new ListValue()); 40 params_value->Append(keys_object_value->DeepCopy()); 41 scoped_ptr<StorageArea::Get::Params> params( 42 StorageArea::Get::Params::Create(*params_value)); 43 ASSERT_TRUE(params); 44 ASSERT_TRUE(params->keys); 45 EXPECT_TRUE(keys_object_value->Equals( 46 ¶ms->keys->as_object->additional_properties)); 47 } 48} 49 50TEST(JsonSchemaCompilerFunctionsOnTypesTest, StorageAreaGetResultCreate) { 51 StorageArea::Get::Results::Items items; 52 items.additional_properties.SetDouble("asdf", 0.1); 53 items.additional_properties.SetString("sdfg", "zxcv"); 54 scoped_ptr<ListValue> results = StorageArea::Get::Results::Create(items); 55 DictionaryValue* item_result = NULL; 56 ASSERT_TRUE(results->GetDictionary(0, &item_result)); 57 EXPECT_TRUE(item_result->Equals(&items.additional_properties)); 58} 59 60TEST(JsonSchemaCompilerFunctionsOnTypesTest, ChromeSettingGetParamsCreate) { 61 scoped_ptr<DictionaryValue> details_value(new DictionaryValue()); 62 details_value->SetBoolean("incognito", true); 63 scoped_ptr<ListValue> params_value(new ListValue()); 64 params_value->Append(details_value.release()); 65 scoped_ptr<ChromeSetting::Get::Params> params( 66 ChromeSetting::Get::Params::Create(*params_value)); 67 EXPECT_TRUE(params.get()); 68 EXPECT_TRUE(*params->details.incognito); 69} 70