Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: components/policy/core/browser/android/policy_converter_unittest.cc

Issue 2476493003: Remove FundamentalValue
Patch Set: Fix Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "components/policy/core/browser/android/policy_converter.h" 12 #include "components/policy/core/browser/android/policy_converter.h"
13 #include "components/policy/core/common/schema.h" 13 #include "components/policy/core/common/schema.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using base::DictionaryValue; 16 using base::DictionaryValue;
17 using base::FundamentalValue; 17 using base::Value;
18 using base::ListValue; 18 using base::ListValue;
19 using base::StringValue; 19 using base::StringValue;
20 using base::Value; 20 using base::Value;
21 using base::android::JavaRef; 21 using base::android::JavaRef;
22 using base::android::ScopedJavaLocalRef; 22 using base::android::ScopedJavaLocalRef;
23 23
24 namespace policy { 24 namespace policy {
25 namespace android { 25 namespace android {
26 26
27 class PolicyConverterTest : public testing::Test { 27 class PolicyConverterTest : public testing::Test {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 Schema null_schema = schema_.GetKnownProperty("null"); 100 Schema null_schema = schema_.GetKnownProperty("null");
101 ASSERT_TRUE(null_schema.valid()); 101 ASSERT_TRUE(null_schema.valid());
102 102
103 EXPECT_EQ("null", Convert(new StringValue("foo"), null_schema)); 103 EXPECT_EQ("null", Convert(new StringValue("foo"), null_schema));
104 } 104 }
105 105
106 TEST_F(PolicyConverterTest, ConvertToBoolValue) { 106 TEST_F(PolicyConverterTest, ConvertToBoolValue) {
107 Schema bool_schema = schema_.GetKnownProperty("bool"); 107 Schema bool_schema = schema_.GetKnownProperty("bool");
108 ASSERT_TRUE(bool_schema.valid()); 108 ASSERT_TRUE(bool_schema.valid());
109 109
110 EXPECT_EQ("true", Convert(new FundamentalValue(true), bool_schema)); 110 EXPECT_EQ("true", Convert(new Value(true), bool_schema));
111 EXPECT_EQ("false", Convert(new FundamentalValue(false), bool_schema)); 111 EXPECT_EQ("false", Convert(new Value(false), bool_schema));
112 EXPECT_EQ("true", Convert(new StringValue("true"), bool_schema)); 112 EXPECT_EQ("true", Convert(new StringValue("true"), bool_schema));
113 EXPECT_EQ("false", Convert(new StringValue("false"), bool_schema)); 113 EXPECT_EQ("false", Convert(new StringValue("false"), bool_schema));
114 EXPECT_EQ("\"narf\"", Convert(new StringValue("narf"), bool_schema)); 114 EXPECT_EQ("\"narf\"", Convert(new StringValue("narf"), bool_schema));
115 EXPECT_EQ("false", Convert(new FundamentalValue(0), bool_schema)); 115 EXPECT_EQ("false", Convert(new Value(0), bool_schema));
116 EXPECT_EQ("true", Convert(new FundamentalValue(1), bool_schema)); 116 EXPECT_EQ("true", Convert(new Value(1), bool_schema));
117 EXPECT_EQ("true", Convert(new FundamentalValue(42), bool_schema)); 117 EXPECT_EQ("true", Convert(new Value(42), bool_schema));
118 EXPECT_EQ("true", Convert(new FundamentalValue(-1), bool_schema)); 118 EXPECT_EQ("true", Convert(new Value(-1), bool_schema));
119 EXPECT_EQ("\"1\"", Convert(new StringValue("1"), bool_schema)); 119 EXPECT_EQ("\"1\"", Convert(new StringValue("1"), bool_schema));
120 EXPECT_EQ("{}", Convert(new DictionaryValue(), bool_schema)); 120 EXPECT_EQ("{}", Convert(new DictionaryValue(), bool_schema));
121 } 121 }
122 122
123 TEST_F(PolicyConverterTest, ConvertToIntValue) { 123 TEST_F(PolicyConverterTest, ConvertToIntValue) {
124 Schema int_schema = schema_.GetKnownProperty("int"); 124 Schema int_schema = schema_.GetKnownProperty("int");
125 ASSERT_TRUE(int_schema.valid()); 125 ASSERT_TRUE(int_schema.valid());
126 126
127 EXPECT_EQ("23", Convert(new FundamentalValue(23), int_schema)); 127 EXPECT_EQ("23", Convert(new Value(23), int_schema));
128 EXPECT_EQ("42", Convert(new StringValue("42"), int_schema)); 128 EXPECT_EQ("42", Convert(new StringValue("42"), int_schema));
129 EXPECT_EQ("-1", Convert(new StringValue("-1"), int_schema)); 129 EXPECT_EQ("-1", Convert(new StringValue("-1"), int_schema));
130 EXPECT_EQ("\"poit\"", Convert(new StringValue("poit"), int_schema)); 130 EXPECT_EQ("\"poit\"", Convert(new StringValue("poit"), int_schema));
131 EXPECT_EQ("false", Convert(new FundamentalValue(false), int_schema)); 131 EXPECT_EQ("false", Convert(new Value(false), int_schema));
132 } 132 }
133 133
134 TEST_F(PolicyConverterTest, ConvertToDoubleValue) { 134 TEST_F(PolicyConverterTest, ConvertToDoubleValue) {
135 Schema double_schema = schema_.GetKnownProperty("double"); 135 Schema double_schema = schema_.GetKnownProperty("double");
136 ASSERT_TRUE(double_schema.valid()); 136 ASSERT_TRUE(double_schema.valid());
137 137
138 EXPECT_EQ("3", Convert(new FundamentalValue(3), double_schema)); 138 EXPECT_EQ("3", Convert(new Value(3), double_schema));
139 EXPECT_EQ("3.14", Convert(new FundamentalValue(3.14), double_schema)); 139 EXPECT_EQ("3.14", Convert(new Value(3.14), double_schema));
140 EXPECT_EQ("2.71", Convert(new StringValue("2.71"), double_schema)); 140 EXPECT_EQ("2.71", Convert(new StringValue("2.71"), double_schema));
141 EXPECT_EQ("\"zort\"", Convert(new StringValue("zort"), double_schema)); 141 EXPECT_EQ("\"zort\"", Convert(new StringValue("zort"), double_schema));
142 EXPECT_EQ("true", Convert(new FundamentalValue(true), double_schema)); 142 EXPECT_EQ("true", Convert(new Value(true), double_schema));
143 } 143 }
144 144
145 TEST_F(PolicyConverterTest, ConvertToStringValue) { 145 TEST_F(PolicyConverterTest, ConvertToStringValue) {
146 Schema string_schema = schema_.GetKnownProperty("string"); 146 Schema string_schema = schema_.GetKnownProperty("string");
147 ASSERT_TRUE(string_schema.valid()); 147 ASSERT_TRUE(string_schema.valid());
148 148
149 EXPECT_EQ("\"troz\"", Convert(new StringValue("troz"), string_schema)); 149 EXPECT_EQ("\"troz\"", Convert(new StringValue("troz"), string_schema));
150 EXPECT_EQ("4711", Convert(new FundamentalValue(4711), string_schema)); 150 EXPECT_EQ("4711", Convert(new Value(4711), string_schema));
151 } 151 }
152 152
153 TEST_F(PolicyConverterTest, ConvertToListValue) { 153 TEST_F(PolicyConverterTest, ConvertToListValue) {
154 Schema list_schema = schema_.GetKnownProperty("list"); 154 Schema list_schema = schema_.GetKnownProperty("list");
155 ASSERT_TRUE(list_schema.valid()); 155 ASSERT_TRUE(list_schema.valid());
156 156
157 ListValue* list = new ListValue; 157 ListValue* list = new ListValue;
158 list->AppendString("foo"); 158 list->AppendString("foo");
159 list->AppendString("bar"); 159 list->AppendString("bar");
160 EXPECT_EQ("[\"foo\",\"bar\"]", Convert(list, list_schema)); 160 EXPECT_EQ("[\"foo\",\"bar\"]", Convert(list, list_schema));
161 EXPECT_EQ("[\"baz\",\"blurp\"]", 161 EXPECT_EQ("[\"baz\",\"blurp\"]",
162 Convert(new StringValue("[\"baz\", \"blurp\"]"), list_schema)); 162 Convert(new StringValue("[\"baz\", \"blurp\"]"), list_schema));
163 EXPECT_EQ("\"hurz\"", Convert(new StringValue("hurz"), list_schema)); 163 EXPECT_EQ("\"hurz\"", Convert(new StringValue("hurz"), list_schema));
164 EXPECT_EQ("19", Convert(new FundamentalValue(19), list_schema)); 164 EXPECT_EQ("19", Convert(new Value(19), list_schema));
165 } 165 }
166 166
167 TEST_F(PolicyConverterTest, ConvertFromJavaListToListValue) { 167 TEST_F(PolicyConverterTest, ConvertFromJavaListToListValue) {
168 JNIEnv* env = base::android::AttachCurrentThread(); 168 JNIEnv* env = base::android::AttachCurrentThread();
169 EXPECT_EQ("[\"foo\",\"bar\",\"baz\"]", 169 EXPECT_EQ("[\"foo\",\"bar\",\"baz\"]",
170 ConvertJavaStringArrayToListValue( 170 ConvertJavaStringArrayToListValue(
171 env, MakeJavaStringArray(env, {"foo", "bar", "baz"}))); 171 env, MakeJavaStringArray(env, {"foo", "bar", "baz"})));
172 EXPECT_EQ("[]", ConvertJavaStringArrayToListValue( 172 EXPECT_EQ("[]", ConvertJavaStringArrayToListValue(
173 env, MakeJavaStringArray(env, {}))); 173 env, MakeJavaStringArray(env, {})));
174 } 174 }
175 175
176 TEST_F(PolicyConverterTest, ConvertToDictionaryValue) { 176 TEST_F(PolicyConverterTest, ConvertToDictionaryValue) {
177 Schema dict_schema = schema_.GetKnownProperty("dict"); 177 Schema dict_schema = schema_.GetKnownProperty("dict");
178 ASSERT_TRUE(dict_schema.valid()); 178 ASSERT_TRUE(dict_schema.valid());
179 179
180 DictionaryValue* dict = new DictionaryValue; 180 DictionaryValue* dict = new DictionaryValue;
181 dict->SetInteger("thx", 1138); 181 dict->SetInteger("thx", 1138);
182 EXPECT_EQ("{\"thx\":1138}", Convert(dict, dict_schema)); 182 EXPECT_EQ("{\"thx\":1138}", Convert(dict, dict_schema));
183 EXPECT_EQ("{\"moose\":true}", 183 EXPECT_EQ("{\"moose\":true}",
184 Convert(new StringValue("{\"moose\": true}"), dict_schema)); 184 Convert(new StringValue("{\"moose\": true}"), dict_schema));
185 EXPECT_EQ("\"fnord\"", Convert(new StringValue("fnord"), dict_schema)); 185 EXPECT_EQ("\"fnord\"", Convert(new StringValue("fnord"), dict_schema));
186 EXPECT_EQ("1729", Convert(new FundamentalValue(1729), dict_schema)); 186 EXPECT_EQ("1729", Convert(new Value(1729), dict_schema));
187 } 187 }
188 188
189 } // namespace android 189 } // namespace android
190 } // namespace policy 190 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698