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

Side by Side Diff: chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_api_chromeos_unittest.cc

Issue 2799093006: Remove base::BinaryValue (Closed)
Patch Set: Rebase Created 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ api.h" 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_ api.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 *user_public_key = "user public key"; 91 *user_public_key = "user public key";
92 *user_private_key = "user private key"; 92 *user_private_key = "user private key";
93 } 93 }
94 94
95 private: 95 private:
96 ~TestableGetPermitAccessFunction() override {} 96 ~TestableGetPermitAccessFunction() override {}
97 97
98 DISALLOW_COPY_AND_ASSIGN(TestableGetPermitAccessFunction); 98 DISALLOW_COPY_AND_ASSIGN(TestableGetPermitAccessFunction);
99 }; 99 };
100 100
101 // Converts a string to a base::BinaryValue value whose buffer contains the 101 // Converts a string to a base::Value value whose buffer contains the
102 // string data without the trailing '\0'. 102 // string data without the trailing '\0'.
103 std::unique_ptr<base::BinaryValue> StringToBinaryValue( 103 std::unique_ptr<base::Value> StringToBinaryValue(const std::string& value) {
104 const std::string& value) { 104 return base::Value::CreateWithCopiedBuffer(value.data(), value.length());
105 return base::BinaryValue::CreateWithCopiedBuffer(value.data(),
106 value.length());
107 } 105 }
108 106
109 // Copies |private_key_source| and |public_key_source| to |private_key_target| 107 // Copies |private_key_source| and |public_key_source| to |private_key_target|
110 // and |public_key_target|. It is used as a callback for 108 // and |public_key_target|. It is used as a callback for
111 // |EasyUnlockClient::GenerateEcP256KeyPair| to save the values returned by the 109 // |EasyUnlockClient::GenerateEcP256KeyPair| to save the values returned by the
112 // method. 110 // method.
113 void CopyKeyPair(std::string* private_key_target, 111 void CopyKeyPair(std::string* private_key_target,
114 std::string* public_key_target, 112 std::string* public_key_target,
115 const std::string& private_key_source, 113 const std::string& private_key_source,
116 const std::string& public_key_source) { 114 const std::string& public_key_source) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 if (!result_list) { 155 if (!result_list) {
158 LOG(ERROR) << "Function has no result list."; 156 LOG(ERROR) << "Function has no result list.";
159 return ""; 157 return "";
160 } 158 }
161 159
162 if (result_list->GetSize() != 1u) { 160 if (result_list->GetSize() != 1u) {
163 LOG(ERROR) << "Invalid number of results."; 161 LOG(ERROR) << "Invalid number of results.";
164 return ""; 162 return "";
165 } 163 }
166 164
167 const base::BinaryValue* result_binary_value; 165 const base::Value* result_binary_value;
168 if (!result_list->GetBinary(0, &result_binary_value) || 166 if (!result_list->GetBinary(0, &result_binary_value) ||
169 !result_binary_value) { 167 !result_binary_value) {
170 LOG(ERROR) << "Result not a binary value."; 168 LOG(ERROR) << "Result not a binary value.";
171 return ""; 169 return "";
172 } 170 }
173 171
174 return std::string(result_binary_value->GetBuffer(), 172 return std::string(result_binary_value->GetBuffer(),
175 result_binary_value->GetSize()); 173 result_binary_value->GetSize());
176 } 174 }
177 175
178 chromeos::EasyUnlockClient* client_; 176 chromeos::EasyUnlockClient* client_;
179 }; 177 };
180 178
181 TEST_F(EasyUnlockPrivateApiTest, GenerateEcP256KeyPair) { 179 TEST_F(EasyUnlockPrivateApiTest, GenerateEcP256KeyPair) {
182 scoped_refptr<EasyUnlockPrivateGenerateEcP256KeyPairFunction> function( 180 scoped_refptr<EasyUnlockPrivateGenerateEcP256KeyPairFunction> function(
183 new EasyUnlockPrivateGenerateEcP256KeyPairFunction()); 181 new EasyUnlockPrivateGenerateEcP256KeyPairFunction());
184 function->set_has_callback(true); 182 function->set_has_callback(true);
185 183
186 ASSERT_TRUE(extension_function_test_utils::RunFunction( 184 ASSERT_TRUE(extension_function_test_utils::RunFunction(
187 function.get(), 185 function.get(),
188 "[]", 186 "[]",
189 browser(), 187 browser(),
190 extension_function_test_utils::NONE)); 188 extension_function_test_utils::NONE));
191 189
192 const base::ListValue* result_list = function->GetResultList(); 190 const base::ListValue* result_list = function->GetResultList();
193 ASSERT_TRUE(result_list); 191 ASSERT_TRUE(result_list);
194 ASSERT_EQ(2u, result_list->GetSize()); 192 ASSERT_EQ(2u, result_list->GetSize());
195 193
196 const base::BinaryValue* public_key; 194 const base::Value* public_key;
197 ASSERT_TRUE(result_list->GetBinary(0, &public_key)); 195 ASSERT_TRUE(result_list->GetBinary(0, &public_key));
198 ASSERT_TRUE(public_key); 196 ASSERT_TRUE(public_key);
199 197
200 const base::BinaryValue* private_key; 198 const base::Value* private_key;
201 ASSERT_TRUE(result_list->GetBinary(1, &private_key)); 199 ASSERT_TRUE(result_list->GetBinary(1, &private_key));
202 ASSERT_TRUE(private_key); 200 ASSERT_TRUE(private_key);
203 201
204 EXPECT_TRUE(chromeos::FakeEasyUnlockClient::IsEcP256KeyPair( 202 EXPECT_TRUE(chromeos::FakeEasyUnlockClient::IsEcP256KeyPair(
205 std::string(private_key->GetBuffer(), private_key->GetSize()), 203 std::string(private_key->GetBuffer(), private_key->GetSize()),
206 std::string(public_key->GetBuffer(), public_key->GetSize()))); 204 std::string(public_key->GetBuffer(), public_key->GetSize())));
207 } 205 }
208 206
209 TEST_F(EasyUnlockPrivateApiTest, PerformECDHKeyAgreement) { 207 TEST_F(EasyUnlockPrivateApiTest, PerformECDHKeyAgreement) {
210 scoped_refptr<EasyUnlockPrivatePerformECDHKeyAgreementFunction> function( 208 scoped_refptr<EasyUnlockPrivatePerformECDHKeyAgreementFunction> function(
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 651
654 scoped_refptr<TestableGetPermitAccessFunction> function( 652 scoped_refptr<TestableGetPermitAccessFunction> function(
655 new TestableGetPermitAccessFunction()); 653 new TestableGetPermitAccessFunction());
656 std::unique_ptr<base::Value> value( 654 std::unique_ptr<base::Value> value(
657 extensions::api_test_utils::RunFunctionAndReturnSingleResult( 655 extensions::api_test_utils::RunFunctionAndReturnSingleResult(
658 function.get(), "[]", profile())); 656 function.get(), "[]", profile()));
659 EXPECT_FALSE(value); 657 EXPECT_FALSE(value);
660 } 658 }
661 659
662 } // namespace 660 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698