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

Unified Diff: components/payments/content/payment_request_spec_unittest.cc

Issue 2872033007: [Payments] Do not show error on initial load of address screen (Closed)
Patch Set: deps check Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/payments/content/payment_request_spec.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/payments/content/payment_request_spec_unittest.cc
diff --git a/components/payments/content/payment_request_spec_unittest.cc b/components/payments/content/payment_request_spec_unittest.cc
index 7414a613f25206b7cea3212e89b9705353aabdb0..28d2774b40efa251a76407a648e8acde40e3ef3c 100644
--- a/components/payments/content/payment_request_spec_unittest.cc
+++ b/components/payments/content/payment_request_spec_unittest.cc
@@ -7,8 +7,11 @@
#include <utility>
#include "base/memory/weak_ptr.h"
+#include "base/strings/utf_string_conversions.h"
#include "components/payments/mojom/payment_request.mojom.h"
+#include "components/strings/grit/components_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/l10n/l10n_util.h"
namespace payments {
@@ -281,22 +284,61 @@ TEST_F(PaymentRequestSpecTest, ShippingOptionsSelection) {
RecreateSpecWithOptionsAndDetails(std::move(options), std::move(details));
EXPECT_EQ("option:2", spec()->selected_shipping_option()->id);
+ EXPECT_TRUE(spec()->selected_shipping_option_error().empty());
+ // Call updateWith with option:1 now selected.
std::vector<mojom::PaymentShippingOptionPtr> new_shipping_options;
mojom::PaymentShippingOptionPtr new_option =
mojom::PaymentShippingOption::New();
new_option->id = "option:1";
- new_option->selected = false;
- shipping_options.push_back(std::move(new_option));
+ new_option->selected = true;
+ new_shipping_options.push_back(std::move(new_option));
mojom::PaymentShippingOptionPtr new_option2 =
mojom::PaymentShippingOption::New();
new_option2->id = "option:2";
- new_option2->selected = true;
+ new_option2->selected = false;
new_shipping_options.push_back(std::move(new_option2));
mojom::PaymentDetailsPtr new_details = mojom::PaymentDetails::New();
new_details->shipping_options = std::move(new_shipping_options);
spec()->UpdateWith(std::move(new_details));
+
+ EXPECT_EQ("option:1", spec()->selected_shipping_option()->id);
+ EXPECT_TRUE(spec()->selected_shipping_option_error().empty());
+}
+
+// Test that the last shipping option is selected, even in the case of
+// updateWith.
+TEST_F(PaymentRequestSpecTest, ShippingOptionsSelection_NoOptionsAtAll) {
+ // No options are provided at first.
+ mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
+ options->request_shipping = true;
+ RecreateSpecWithOptionsAndDetails(std::move(options),
+ mojom::PaymentDetails::New());
+
+ // No option selected, but no error either (the flow just started and no
+ // address has been selected yet).
+ EXPECT_EQ(nullptr, spec()->selected_shipping_option());
+ EXPECT_TRUE(spec()->selected_shipping_option_error().empty());
+
+ // Call updateWith with still no options.
+ spec()->UpdateWith(mojom::PaymentDetails::New());
+
+ // Now it's more serious. No option selected, but there is a generic error.
+ EXPECT_EQ(nullptr, spec()->selected_shipping_option());
+ EXPECT_EQ(
+ l10n_util::GetStringUTF16(IDS_PAYMENTS_UNSUPPORTED_SHIPPING_ADDRESS),
+ spec()->selected_shipping_option_error());
+
+ // Call updateWith with still no options, but a customized error string.
+ mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New();
+ details->error = "No can do shipping.";
+ spec()->UpdateWith(std::move(details));
+
+ // No option selected, but there is an error provided by the mercahnt.
+ EXPECT_EQ(nullptr, spec()->selected_shipping_option());
+ EXPECT_EQ(base::ASCIIToUTF16("No can do shipping."),
+ spec()->selected_shipping_option_error());
}
} // namespace payments
« no previous file with comments | « components/payments/content/payment_request_spec.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698