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

Side by Side Diff: components/payments/core/payment_method_data_unittest.cc

Issue 2797833002: [Payments] base::string16 -> std::string in PaymentMethodData (Closed)
Patch Set: addressed comments 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/payments/core/payment_method_data.h" 5 #include "components/payments/core/payment_method_data.h"
6 6
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 7 #include "base/values.h"
9 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
10 9
11 namespace payments { 10 namespace payments {
12 11
13 // Tests the success case when populating a PaymentMethodData from a dictionary. 12 // Tests the success case when populating a PaymentMethodData from a dictionary.
14 TEST(PaymentMethodData, FromDictionaryValueSuccess) { 13 TEST(PaymentMethodData, FromDictionaryValueSuccess) {
15 PaymentMethodData expected; 14 PaymentMethodData expected;
16 std::vector<base::string16> supported_methods; 15 std::vector<std::string> supported_methods;
17 supported_methods.push_back(base::ASCIIToUTF16("visa")); 16 supported_methods.push_back("visa");
18 supported_methods.push_back(base::ASCIIToUTF16("basic-card")); 17 supported_methods.push_back("basic-card");
19 expected.supported_methods = supported_methods; 18 expected.supported_methods = supported_methods;
20 expected.data = base::ASCIIToUTF16( 19 expected.data =
21 "{\"supportedNetworks\":[\"mastercard\"]," 20 "{\"supportedNetworks\":[\"mastercard\"],"
22 "\"supportedTypes\":[\"debit\",\"credit\"]}"); 21 "\"supportedTypes\":[\"debit\",\"credit\"]}";
23 std::vector<base::string16> supported_networks; 22 std::vector<std::string> supported_networks;
24 supported_networks.push_back(base::ASCIIToUTF16("mastercard")); 23 supported_networks.push_back("mastercard");
25 expected.supported_networks = supported_networks; 24 expected.supported_networks = supported_networks;
26 std::vector<base::string16> supported_types; 25 std::vector<std::string> supported_types;
27 supported_types.push_back(base::ASCIIToUTF16("debit")); 26 supported_types.push_back("debit");
28 supported_types.push_back(base::ASCIIToUTF16("credit")); 27 supported_types.push_back("credit");
29 expected.supported_types = supported_types; 28 expected.supported_types = supported_types;
30 29
31 base::DictionaryValue method_data_dict; 30 base::DictionaryValue method_data_dict;
32 std::unique_ptr<base::ListValue> supported_methods_list(new base::ListValue); 31 std::unique_ptr<base::ListValue> supported_methods_list(new base::ListValue);
33 supported_methods_list->AppendString("visa"); 32 supported_methods_list->AppendString("visa");
34 supported_methods_list->AppendString("basic-card"); 33 supported_methods_list->AppendString("basic-card");
35 method_data_dict.Set("supportedMethods", std::move(supported_methods_list)); 34 method_data_dict.Set("supportedMethods", std::move(supported_methods_list));
36 std::unique_ptr<base::DictionaryValue> data_dict(new base::DictionaryValue); 35 std::unique_ptr<base::DictionaryValue> data_dict(new base::DictionaryValue);
37 std::unique_ptr<base::ListValue> supported_networks_list(new base::ListValue); 36 std::unique_ptr<base::ListValue> supported_networks_list(new base::ListValue);
38 supported_networks_list->AppendString("mastercard"); 37 supported_networks_list->AppendString("mastercard");
(...skipping 24 matching lines...) Expand all
63 EXPECT_FALSE(actual.FromDictionaryValue(method_data_dict)); 62 EXPECT_FALSE(actual.FromDictionaryValue(method_data_dict));
64 } 63 }
65 64
66 // Tests that two method data objects are not equal if their property values 65 // Tests that two method data objects are not equal if their property values
67 // differ or one is missing a value present in the other, and equal otherwise. 66 // differ or one is missing a value present in the other, and equal otherwise.
68 TEST(PaymentMethodData, Equality) { 67 TEST(PaymentMethodData, Equality) {
69 PaymentMethodData method_data1; 68 PaymentMethodData method_data1;
70 PaymentMethodData method_data2; 69 PaymentMethodData method_data2;
71 EXPECT_EQ(method_data1, method_data2); 70 EXPECT_EQ(method_data1, method_data2);
72 71
73 std::vector<base::string16> supported_methods1; 72 std::vector<std::string> supported_methods1;
74 supported_methods1.push_back(base::ASCIIToUTF16("basic-card")); 73 supported_methods1.push_back("basic-card");
75 supported_methods1.push_back(base::ASCIIToUTF16("http://bobpay.com")); 74 supported_methods1.push_back("http://bobpay.com");
76 method_data1.supported_methods = supported_methods1; 75 method_data1.supported_methods = supported_methods1;
77 EXPECT_NE(method_data1, method_data2); 76 EXPECT_NE(method_data1, method_data2);
78 std::vector<base::string16> supported_methods2; 77 std::vector<std::string> supported_methods2;
79 supported_methods2.push_back(base::ASCIIToUTF16("http://bobpay.com")); 78 supported_methods2.push_back("http://bobpay.com");
80 method_data2.supported_methods = supported_methods2; 79 method_data2.supported_methods = supported_methods2;
81 EXPECT_NE(method_data1, method_data2); 80 EXPECT_NE(method_data1, method_data2);
82 method_data2.supported_methods = supported_methods1; 81 method_data2.supported_methods = supported_methods1;
83 EXPECT_EQ(method_data1, method_data2); 82 EXPECT_EQ(method_data1, method_data2);
84 83
85 method_data1.data = base::ASCIIToUTF16("{merchantId: '123456'}"); 84 method_data1.data = "{merchantId: '123456'}";
86 EXPECT_NE(method_data1, method_data2); 85 EXPECT_NE(method_data1, method_data2);
87 method_data2.data = base::ASCIIToUTF16("{merchantId: '9999-88'}"); 86 method_data2.data = "{merchantId: '9999-88'}";
88 EXPECT_NE(method_data1, method_data2); 87 EXPECT_NE(method_data1, method_data2);
89 method_data2.data = base::ASCIIToUTF16("{merchantId: '123456'}"); 88 method_data2.data = "{merchantId: '123456'}";
90 EXPECT_EQ(method_data1, method_data2); 89 EXPECT_EQ(method_data1, method_data2);
91 90
92 std::vector<base::string16> supported_networks1{base::ASCIIToUTF16("visa")}; 91 std::vector<std::string> supported_networks1{"visa"};
93 method_data1.supported_networks = supported_networks1; 92 method_data1.supported_networks = supported_networks1;
94 EXPECT_NE(method_data1, method_data2); 93 EXPECT_NE(method_data1, method_data2);
95 std::vector<base::string16> supported_networks2{base::ASCIIToUTF16("jcb")}; 94 std::vector<std::string> supported_networks2{"jcb"};
96 method_data2.supported_networks = supported_networks2; 95 method_data2.supported_networks = supported_networks2;
97 EXPECT_NE(method_data1, method_data2); 96 EXPECT_NE(method_data1, method_data2);
98 method_data2.supported_networks = supported_networks1; 97 method_data2.supported_networks = supported_networks1;
99 EXPECT_EQ(method_data1, method_data2); 98 EXPECT_EQ(method_data1, method_data2);
100 99
101 std::vector<base::string16> supported_types1{base::ASCIIToUTF16("credit")}; 100 std::vector<std::string> supported_types1{"credit"};
102 method_data1.supported_types = supported_types1; 101 method_data1.supported_types = supported_types1;
103 EXPECT_NE(method_data1, method_data2); 102 EXPECT_NE(method_data1, method_data2);
104 std::vector<base::string16> supported_types2{base::ASCIIToUTF16("debit")}; 103 std::vector<std::string> supported_types2{"debit"};
105 method_data2.supported_types = supported_types2; 104 method_data2.supported_types = supported_types2;
106 EXPECT_NE(method_data1, method_data2); 105 EXPECT_NE(method_data1, method_data2);
107 method_data2.supported_types = supported_types1; 106 method_data2.supported_types = supported_types1;
108 EXPECT_EQ(method_data1, method_data2); 107 EXPECT_EQ(method_data1, method_data2);
109 } 108 }
110 109
111 } // namespace payments 110 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/payment_method_data.cc ('k') | ios/chrome/browser/payments/payment_request.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698