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

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

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 months 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"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 std::string error; 47 std::string error;
48 schema_ = Schema::Parse(kSchemaTemplate, &error); 48 schema_ = Schema::Parse(kSchemaTemplate, &error);
49 ASSERT_TRUE(schema_.valid()) << error; 49 ASSERT_TRUE(schema_.valid()) << error;
50 } 50 }
51 51
52 protected: 52 protected:
53 // Converts the passed in value to the passed in schema, and serializes the 53 // Converts the passed in value to the passed in schema, and serializes the
54 // result to JSON, to make it easier to compare with EXPECT_EQ. 54 // result to JSON, to make it easier to compare with EXPECT_EQ.
55 std::string Convert(Value* value, const Schema& value_schema) { 55 std::string Convert(Value* value, const Schema& value_schema) {
56 scoped_ptr<Value> converted_value(PolicyConverter::ConvertValueToSchema( 56 std::unique_ptr<Value> converted_value(
57 scoped_ptr<Value>(value), value_schema)); 57 PolicyConverter::ConvertValueToSchema(std::unique_ptr<Value>(value),
58 value_schema));
58 59
59 std::string json_string; 60 std::string json_string;
60 EXPECT_TRUE( 61 EXPECT_TRUE(
61 base::JSONWriter::Write(*(converted_value.get()), &json_string)); 62 base::JSONWriter::Write(*(converted_value.get()), &json_string));
62 return json_string; 63 return json_string;
63 } 64 }
64 65
65 // Uses|PolicyConverter::ConvertJavaStringArrayToListValue| to convert the 66 // Uses|PolicyConverter::ConvertJavaStringArrayToListValue| to convert the
66 // passed in java array and serializes the result to JSON, to make it easier 67 // passed in java array and serializes the result to JSON, to make it easier
67 // to compare with EXPECT_EQ. 68 // to compare with EXPECT_EQ.
68 std::string ConvertJavaStringArrayToListValue( 69 std::string ConvertJavaStringArrayToListValue(
69 JNIEnv* env, 70 JNIEnv* env,
70 const JavaRef<jobjectArray>& java_array) { 71 const JavaRef<jobjectArray>& java_array) {
71 scoped_ptr<ListValue> list = 72 std::unique_ptr<ListValue> list =
72 PolicyConverter::ConvertJavaStringArrayToListValue(env, java_array); 73 PolicyConverter::ConvertJavaStringArrayToListValue(env, java_array);
73 74
74 std::string json_string; 75 std::string json_string;
75 EXPECT_TRUE(base::JSONWriter::Write(*list, &json_string)); 76 EXPECT_TRUE(base::JSONWriter::Write(*list, &json_string));
76 77
77 return json_string; 78 return json_string;
78 } 79 }
79 80
80 // Converts the passed in values to a java string array 81 // Converts the passed in values to a java string array
81 ScopedJavaLocalRef<jobjectArray> MakeJavaStringArray( 82 ScopedJavaLocalRef<jobjectArray> MakeJavaStringArray(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 dict->SetInteger("thx", 1138); 181 dict->SetInteger("thx", 1138);
181 EXPECT_EQ("{\"thx\":1138}", Convert(dict, dict_schema)); 182 EXPECT_EQ("{\"thx\":1138}", Convert(dict, dict_schema));
182 EXPECT_EQ("{\"moose\":true}", 183 EXPECT_EQ("{\"moose\":true}",
183 Convert(new StringValue("{\"moose\": true}"), dict_schema)); 184 Convert(new StringValue("{\"moose\": true}"), dict_schema));
184 EXPECT_EQ("\"fnord\"", Convert(new StringValue("fnord"), dict_schema)); 185 EXPECT_EQ("\"fnord\"", Convert(new StringValue("fnord"), dict_schema));
185 EXPECT_EQ("1729", Convert(new FundamentalValue(1729), dict_schema)); 186 EXPECT_EQ("1729", Convert(new FundamentalValue(1729), dict_schema));
186 } 187 }
187 188
188 } // namespace android 189 } // namespace android
189 } // namespace policy 190 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/browser/android/policy_converter.cc ('k') | components/policy/core/browser/browser_policy_connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698