Skip to content

Commit

Permalink
[Payment Request] Avoid use of base::string16 in Payment Request
Browse files Browse the repository at this point in the history
In order to be consistent with the mojo implementation of the payment
request, this CL changes types of strings in multiple places from
base::string16 to std::string.
https://cs.chromium.org/chromium/src/out/Debug/gen/third_party/WebKit/public/platform/modules/payments/payment_request.mojom.h

Bug: 602666
Change-Id: I1612cae8e50a5067eab863838e6db32e55c12e86
Reviewed-on: https://chromium-review.googlesource.com/644127
Commit-Queue: mahmadi (Moe) <mahmadi@chromium.org>
Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#498593}
  • Loading branch information
Mohamad Ahmadi authored and Commit Bot committed Aug 30, 2017
1 parent 1a8df4c commit dad9a7e
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 167 deletions.
4 changes: 1 addition & 3 deletions components/payments/core/payment_currency_amount.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "components/payments/core/payment_currency_amount.h"

#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"

namespace payments {
Expand All @@ -25,8 +24,7 @@ static const char kPaymentCurrencyAmountValue[] = "value";
PaymentCurrencyAmount::PaymentCurrencyAmount()
// By default, the currency is defined by [ISO4217]. For example, USD for
// US Dollars.
: currency_system(
base::ASCIIToUTF16(kPaymentCurrencyAmountCurrencySystemISO4217)) {}
: currency_system(kPaymentCurrencyAmountCurrencySystemISO4217) {}

PaymentCurrencyAmount::~PaymentCurrencyAmount() = default;

Expand Down
9 changes: 4 additions & 5 deletions components/payments/core/payment_currency_amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#define COMPONENTS_PAYMENTS_CORE_PAYMENT_CURRENCY_AMOUNT_H_

#include <memory>

#include "base/strings/string16.h"
#include <string>

// C++ bindings for the PaymentRequest API PaymentCurrencyAmount. Conforms to
// the following spec:
Expand Down Expand Up @@ -39,14 +38,14 @@ class PaymentCurrencyAmount {
// A currency identifier. The most common identifiers are three-letter
// alphabetic codes as defined by ISO 4217 (for example, "USD" for US Dollars)
// however any string is considered valid.
base::string16 currency;
std::string currency;

// A string containing the decimal monetary value.
base::string16 value;
std::string value;

// A URL that indicates the currency system that the currency identifier
// belongs to.
base::string16 currency_system;
std::string currency_system;
};

} // namespace payments
Expand Down
26 changes: 12 additions & 14 deletions components/payments/core/payment_currency_amount_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "components/payments/core/payment_currency_amount.h"

#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -14,8 +13,8 @@ namespace payments {
// dictionary.
TEST(PaymentRequestTest, PaymentCurrencyAmountFromDictionaryValueSuccess) {
PaymentCurrencyAmount expected;
expected.currency = base::ASCIIToUTF16("AUD");
expected.value = base::ASCIIToUTF16("-438.23");
expected.currency = "AUD";
expected.value = "-438.23";

base::DictionaryValue amount_dict;
amount_dict.SetString("currency", "AUD");
Expand All @@ -26,7 +25,7 @@ TEST(PaymentRequestTest, PaymentCurrencyAmountFromDictionaryValueSuccess) {

EXPECT_EQ(expected, actual);

expected.currency_system = base::ASCIIToUTF16("urn:iso:std:iso:123456789");
expected.currency_system = "urn:iso:std:iso:123456789";
amount_dict.SetString("currencySystem", "urn:iso:std:iso:123456789");
EXPECT_TRUE(actual.FromDictionaryValue(amount_dict));
EXPECT_EQ(expected, actual);
Expand Down Expand Up @@ -57,18 +56,18 @@ TEST(PaymentRequestTest, PaymentCurrencyAmountEquality) {
PaymentCurrencyAmount currency_amount2;
EXPECT_EQ(currency_amount1, currency_amount2);

currency_amount1.currency = base::ASCIIToUTF16("HKD");
currency_amount1.currency = "HKD";
EXPECT_NE(currency_amount1, currency_amount2);
currency_amount2.currency = base::ASCIIToUTF16("USD");
currency_amount2.currency = "USD";
EXPECT_NE(currency_amount1, currency_amount2);
currency_amount2.currency = base::ASCIIToUTF16("HKD");
currency_amount2.currency = "HKD";
EXPECT_EQ(currency_amount1, currency_amount2);

currency_amount1.value = base::ASCIIToUTF16("49.89");
currency_amount1.value = "49.89";
EXPECT_NE(currency_amount1, currency_amount2);
currency_amount2.value = base::ASCIIToUTF16("49.99");
currency_amount2.value = "49.99";
EXPECT_NE(currency_amount1, currency_amount2);
currency_amount2.value = base::ASCIIToUTF16("49.89");
currency_amount2.value = "49.89";
EXPECT_EQ(currency_amount1, currency_amount2);
}

Expand Down Expand Up @@ -96,10 +95,9 @@ TEST(PaymentRequestTest, PopulatedCurrencyAmountDictionary) {
expected_value.SetString("currencySystem", "urn:iso:std:iso:123456789");

PaymentCurrencyAmount payment_currency_amount;
payment_currency_amount.currency = base::ASCIIToUTF16("AUD");
payment_currency_amount.value = base::ASCIIToUTF16("-438.23");
payment_currency_amount.currency_system =
base::ASCIIToUTF16("urn:iso:std:iso:123456789");
payment_currency_amount.currency = "AUD";
payment_currency_amount.value = "-438.23";
payment_currency_amount.currency_system = "urn:iso:std:iso:123456789";

EXPECT_TRUE(
expected_value.Equals(payment_currency_amount.ToDictionaryValue().get()));
Expand Down
3 changes: 1 addition & 2 deletions components/payments/core/payment_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <string>
#include <vector>

#include "base/strings/string16.h"
#include "components/payments/core/payment_details_modifier.h"
#include "components/payments/core/payment_item.h"
#include "components/payments/core/payment_shipping_option.h"
Expand Down Expand Up @@ -60,7 +59,7 @@ class PaymentDetails {

// If non-empty, this is the error message the user agent should display to
// the user when the payment request is updated using updateWith.
base::string16 error;
std::string error;
};

} // namespace payments
Expand Down
4 changes: 2 additions & 2 deletions components/payments/core/payment_details_modifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#define COMPONENTS_PAYMENTS_CORE_PAYMENT_DETAILS_MODIFIER_H_

#include <memory>
#include <string>
#include <vector>

#include "base/strings/string16.h"
#include "components/payments/core/payment_item.h"

// C++ bindings for the PaymentRequest API PaymentDetailsModifier. Conforms to
Expand Down Expand Up @@ -39,7 +39,7 @@ class PaymentDetailsModifier {
// A sequence of payment method identifiers. The remaining fields in the
// PaymentDetailsModifier apply only if the user selects a payment method
// included in this sequence.
std::vector<base::string16> supported_methods;
std::vector<std::string> supported_methods;

// This value overrides the total field in the PaymentDetails dictionary for
// the payment method identifiers in the supportedMethods field.
Expand Down
30 changes: 14 additions & 16 deletions components/payments/core/payment_details_modifier_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ TEST(PaymentRequestTest, PopulatedDetailsModifierDictionary) {
expected_value.SetDictionary("total", std::move(item_dict));

PaymentDetailsModifier payment_detials_modififer;
payment_detials_modififer.supported_methods.push_back(
base::ASCIIToUTF16("visa"));
payment_detials_modififer.supported_methods.push_back(
base::ASCIIToUTF16("amex"));
payment_detials_modififer.total.label = base::ASCIIToUTF16("Gratuity");
payment_detials_modififer.total.amount.currency = base::ASCIIToUTF16("USD");
payment_detials_modififer.total.amount.value = base::ASCIIToUTF16("139.99");
payment_detials_modififer.supported_methods.push_back("visa");
payment_detials_modififer.supported_methods.push_back("amex");
payment_detials_modififer.total.label = "Gratuity";
payment_detials_modififer.total.amount.currency = "USD";
payment_detials_modififer.total.amount.value = "139.99";

EXPECT_TRUE(expected_value.Equals(
payment_detials_modififer.ToDictionaryValue().get()));
Expand All @@ -80,27 +78,27 @@ TEST(PaymentRequestTest, PaymentDetailsModifierEquality) {
PaymentDetailsModifier details_modifier2;
EXPECT_EQ(details_modifier1, details_modifier2);

std::vector<base::string16> supported_methods1;
supported_methods1.push_back(base::ASCIIToUTF16("China UnionPay"));
supported_methods1.push_back(base::ASCIIToUTF16("BobPay"));
std::vector<std::string> supported_methods1;
supported_methods1.push_back("China UnionPay");
supported_methods1.push_back("BobPay");
details_modifier1.supported_methods = supported_methods1;
EXPECT_NE(details_modifier1, details_modifier2);
std::vector<base::string16> supported_methods2;
supported_methods2.push_back(base::ASCIIToUTF16("BobPay"));
std::vector<std::string> supported_methods2;
supported_methods2.push_back("BobPay");
details_modifier2.supported_methods = supported_methods2;
EXPECT_NE(details_modifier1, details_modifier2);
details_modifier2.supported_methods = supported_methods1;
EXPECT_EQ(details_modifier1, details_modifier2);

details_modifier1.total.label = base::ASCIIToUTF16("Total");
details_modifier1.total.label = "Total";
EXPECT_NE(details_modifier1, details_modifier2);
details_modifier2.total.label = base::ASCIIToUTF16("Gratuity");
details_modifier2.total.label = "Gratuity";
EXPECT_NE(details_modifier1, details_modifier2);
details_modifier2.total.label = base::ASCIIToUTF16("Total");
details_modifier2.total.label = "Total";
EXPECT_EQ(details_modifier1, details_modifier2);

PaymentItem payment_item;
payment_item.label = base::ASCIIToUTF16("Tax");
payment_item.label = "Tax";
std::vector<PaymentItem> display_items1;
display_items1.push_back(payment_item);
details_modifier1.additional_display_items = display_items1;
Expand Down
44 changes: 19 additions & 25 deletions components/payments/core/payment_details_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <memory>

#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand All @@ -15,7 +14,7 @@ namespace payments {
// Tests the success case when populating a PaymentDetails from a dictionary.
TEST(PaymentRequestTest, PaymentDetailsFromDictionaryValueSuccess) {
PaymentDetails expected;
expected.error = base::ASCIIToUTF16("Error in details");
expected.error = "Error in details";

base::DictionaryValue details_dict;
details_dict.SetString("error", "Error in details");
Expand All @@ -24,9 +23,9 @@ TEST(PaymentRequestTest, PaymentDetailsFromDictionaryValueSuccess) {
actual.FromDictionaryValue(details_dict, /*requires_total=*/false));
EXPECT_EQ(expected, actual);

expected.total.label = base::ASCIIToUTF16("TOTAL");
expected.total.amount.currency = base::ASCIIToUTF16("GBP");
expected.total.amount.value = base::ASCIIToUTF16("6.66");
expected.total.label = "TOTAL";
expected.total.amount.currency = "GBP";
expected.total.amount.value = "6.66";

std::unique_ptr<base::DictionaryValue> total_dict(new base::DictionaryValue);
total_dict->SetString("label", "TOTAL");
Expand All @@ -48,10 +47,10 @@ TEST(PaymentRequestTest, PaymentDetailsFromDictionaryValueSuccess) {
// Tests the failure case when populating a PaymentDetails from a dictionary.
TEST(PaymentRequestTest, PaymentDetailsFromDictionaryValueFailure) {
PaymentDetails expected;
expected.total.label = base::ASCIIToUTF16("TOTAL");
expected.total.amount.currency = base::ASCIIToUTF16("GBP");
expected.total.amount.value = base::ASCIIToUTF16("6.66");
expected.error = base::ASCIIToUTF16("Error in details");
expected.total.label = "TOTAL";
expected.total.amount.currency = "GBP";
expected.total.amount.value = "6.66";
expected.error = "Error in details";

base::DictionaryValue details_dict;
details_dict.SetString("error", "Error in details");
Expand All @@ -77,22 +76,22 @@ TEST(PaymentRequestTest, PaymentDetailsEquality) {
details2.id = details1.id;
EXPECT_EQ(details1, details2);

details1.total.label = base::ASCIIToUTF16("Total");
details1.total.label = "Total";
EXPECT_NE(details1, details2);
details2.total.label = base::ASCIIToUTF16("Shipping");
details2.total.label = "Shipping";
EXPECT_NE(details1, details2);
details2.total.label = base::ASCIIToUTF16("Total");
details2.total.label = "Total";
EXPECT_EQ(details1, details2);

details1.error = base::ASCIIToUTF16("Foo");
details1.error = "Foo";
EXPECT_NE(details1, details2);
details2.error = base::ASCIIToUTF16("Bar");
details2.error = "Bar";
EXPECT_NE(details1, details2);
details2.error = base::ASCIIToUTF16("Foo");
details2.error = "Foo";
EXPECT_EQ(details1, details2);

PaymentItem payment_item;
payment_item.label = base::ASCIIToUTF16("Tax");
payment_item.label = "Tax";
std::vector<PaymentItem> display_items1;
display_items1.push_back(payment_item);
details1.display_items = display_items1;
Expand All @@ -106,7 +105,7 @@ TEST(PaymentRequestTest, PaymentDetailsEquality) {
EXPECT_EQ(details1, details2);

PaymentShippingOption shipping_option;
shipping_option.label = base::ASCIIToUTF16("Overnight");
shipping_option.label = "Overnight";
std::vector<PaymentShippingOption> shipping_options1;
shipping_options1.push_back(shipping_option);
details1.shipping_options = shipping_options1;
Expand All @@ -120,15 +119,10 @@ TEST(PaymentRequestTest, PaymentDetailsEquality) {
EXPECT_EQ(details1, details2);

PaymentDetailsModifier details_modifier;
details_modifier.total.label = base::ASCIIToUTF16("Total");
std::vector<PaymentDetailsModifier> details_modifiers1;
details_modifiers1.push_back(details_modifier);
details1.modifiers = details_modifiers1;
details_modifier.total.label = "Total";
details1.modifiers.push_back(details_modifier);
EXPECT_NE(details1, details2);
std::vector<PaymentDetailsModifier> details_modifiers2;
details2.modifiers = details_modifiers2;
EXPECT_NE(details1, details2);
details2.modifiers = details_modifiers1;
details2.modifiers.push_back(details_modifier);
EXPECT_EQ(details1, details2);
}

Expand Down
4 changes: 2 additions & 2 deletions components/payments/core/payment_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define COMPONENTS_PAYMENTS_CORE_PAYMENT_ITEM_H_

#include <memory>
#include <string>

#include "base/strings/string16.h"
#include "components/payments/core/payment_currency_amount.h"

// C++ bindings for the PaymentRequest API PaymentItem. Conforms to the
Expand Down Expand Up @@ -39,7 +39,7 @@ class PaymentItem {
std::unique_ptr<base::DictionaryValue> ToDictionaryValue() const;

// A human-readable description of the item.
base::string16 label;
std::string label;

// The monetary amount for the item.
PaymentCurrencyAmount amount;
Expand Down
24 changes: 12 additions & 12 deletions components/payments/core/payment_item_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace payments {
// Tests the success case when populating a PaymentItem from a dictionary.
TEST(PaymentRequestTest, PaymentItemFromDictionaryValueSuccess) {
PaymentItem expected;
expected.label = base::ASCIIToUTF16("Payment Total");
expected.amount.currency = base::ASCIIToUTF16("NZD");
expected.amount.value = base::ASCIIToUTF16("2,242,093.00");
expected.label = "Payment Total";
expected.amount.currency = "NZD";
expected.amount.value = "2,242,093.00";

base::DictionaryValue item_dict;
item_dict.SetString("label", "Payment Total");
Expand Down Expand Up @@ -59,18 +59,18 @@ TEST(PaymentRequestTest, PaymentItemEquality) {
PaymentItem item2;
EXPECT_EQ(item1, item2);

item1.label = base::ASCIIToUTF16("Subtotal");
item1.label = "Subtotal";
EXPECT_NE(item1, item2);
item2.label = base::ASCIIToUTF16("Total");
item2.label = "Total";
EXPECT_NE(item1, item2);
item2.label = base::ASCIIToUTF16("Subtotal");
item2.label = "Subtotal";
EXPECT_EQ(item1, item2);

item1.amount.value = base::ASCIIToUTF16("104.34");
item1.amount.value = "104.34";
EXPECT_NE(item1, item2);
item2.amount.value = base::ASCIIToUTF16("104");
item2.amount.value = "104";
EXPECT_NE(item1, item2);
item2.amount.value = base::ASCIIToUTF16("104.34");
item2.amount.value = "104.34";
EXPECT_EQ(item1, item2);

item1.pending = true;
Expand Down Expand Up @@ -110,9 +110,9 @@ TEST(PaymentRequestTest, PopulatedPaymentItemDictionary) {
expected_value.SetBoolean("pending", true);

PaymentItem payment_item;
payment_item.label = base::ASCIIToUTF16("Payment Total");
payment_item.amount.currency = base::ASCIIToUTF16("NZD");
payment_item.amount.value = base::ASCIIToUTF16("2,242,093.00");
payment_item.label = "Payment Total";
payment_item.amount.currency = "NZD";
payment_item.amount.value = "2,242,093.00";
payment_item.pending = true;

EXPECT_TRUE(expected_value.Equals(payment_item.ToDictionaryValue().get()));
Expand Down
4 changes: 2 additions & 2 deletions components/payments/core/payment_shipping_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class PaymentShippingOption {

// An identifier used to reference this PaymentShippingOption. It is unique
// for a given PaymentRequest.
base::string16 id;
std::string id;

// A human-readable description of the item. The user agent should use this
// string to display the shipping option to the user.
base::string16 label;
std::string label;

// A PaymentCurrencyAmount containing the monetary amount for the option.
PaymentCurrencyAmount amount;
Expand Down
Loading

0 comments on commit dad9a7e

Please sign in to comment.