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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/payments/content/payment_request_spec.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/content/payment_request_spec.h" 5 #include "components/payments/content/payment_request_spec.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/utf_string_conversions.h"
10 #include "components/payments/mojom/payment_request.mojom.h" 11 #include "components/payments/mojom/payment_request.mojom.h"
12 #include "components/strings/grit/components_strings.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/l10n/l10n_util.h"
12 15
13 namespace payments { 16 namespace payments {
14 17
15 class PaymentRequestSpecTest : public testing::Test, 18 class PaymentRequestSpecTest : public testing::Test,
16 public PaymentRequestSpec::Observer { 19 public PaymentRequestSpec::Observer {
17 protected: 20 protected:
18 ~PaymentRequestSpecTest() override {} 21 ~PaymentRequestSpecTest() override {}
19 22
20 void OnSpecUpdated() override { on_spec_updated_called_ = true; } 23 void OnSpecUpdated() override { on_spec_updated_called_ = true; }
21 24
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 option2->selected = true; 277 option2->selected = true;
275 shipping_options.push_back(std::move(option2)); 278 shipping_options.push_back(std::move(option2));
276 mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New(); 279 mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New();
277 details->shipping_options = std::move(shipping_options); 280 details->shipping_options = std::move(shipping_options);
278 281
279 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New(); 282 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
280 options->request_shipping = true; 283 options->request_shipping = true;
281 RecreateSpecWithOptionsAndDetails(std::move(options), std::move(details)); 284 RecreateSpecWithOptionsAndDetails(std::move(options), std::move(details));
282 285
283 EXPECT_EQ("option:2", spec()->selected_shipping_option()->id); 286 EXPECT_EQ("option:2", spec()->selected_shipping_option()->id);
287 EXPECT_TRUE(spec()->selected_shipping_option_error().empty());
284 288
289 // Call updateWith with option:1 now selected.
285 std::vector<mojom::PaymentShippingOptionPtr> new_shipping_options; 290 std::vector<mojom::PaymentShippingOptionPtr> new_shipping_options;
286 mojom::PaymentShippingOptionPtr new_option = 291 mojom::PaymentShippingOptionPtr new_option =
287 mojom::PaymentShippingOption::New(); 292 mojom::PaymentShippingOption::New();
288 new_option->id = "option:1"; 293 new_option->id = "option:1";
289 new_option->selected = false; 294 new_option->selected = true;
290 shipping_options.push_back(std::move(new_option)); 295 new_shipping_options.push_back(std::move(new_option));
291 mojom::PaymentShippingOptionPtr new_option2 = 296 mojom::PaymentShippingOptionPtr new_option2 =
292 mojom::PaymentShippingOption::New(); 297 mojom::PaymentShippingOption::New();
293 new_option2->id = "option:2"; 298 new_option2->id = "option:2";
294 new_option2->selected = true; 299 new_option2->selected = false;
295 new_shipping_options.push_back(std::move(new_option2)); 300 new_shipping_options.push_back(std::move(new_option2));
296 mojom::PaymentDetailsPtr new_details = mojom::PaymentDetails::New(); 301 mojom::PaymentDetailsPtr new_details = mojom::PaymentDetails::New();
297 new_details->shipping_options = std::move(new_shipping_options); 302 new_details->shipping_options = std::move(new_shipping_options);
298 303
299 spec()->UpdateWith(std::move(new_details)); 304 spec()->UpdateWith(std::move(new_details));
305
306 EXPECT_EQ("option:1", spec()->selected_shipping_option()->id);
307 EXPECT_TRUE(spec()->selected_shipping_option_error().empty());
308 }
309
310 // Test that the last shipping option is selected, even in the case of
311 // updateWith.
312 TEST_F(PaymentRequestSpecTest, ShippingOptionsSelection_NoOptionsAtAll) {
313 // No options are provided at first.
314 mojom::PaymentOptionsPtr options = mojom::PaymentOptions::New();
315 options->request_shipping = true;
316 RecreateSpecWithOptionsAndDetails(std::move(options),
317 mojom::PaymentDetails::New());
318
319 // No option selected, but no error either (the flow just started and no
320 // address has been selected yet).
321 EXPECT_EQ(nullptr, spec()->selected_shipping_option());
322 EXPECT_TRUE(spec()->selected_shipping_option_error().empty());
323
324 // Call updateWith with still no options.
325 spec()->UpdateWith(mojom::PaymentDetails::New());
326
327 // Now it's more serious. No option selected, but there is a generic error.
328 EXPECT_EQ(nullptr, spec()->selected_shipping_option());
329 EXPECT_EQ(
330 l10n_util::GetStringUTF16(IDS_PAYMENTS_UNSUPPORTED_SHIPPING_ADDRESS),
331 spec()->selected_shipping_option_error());
332
333 // Call updateWith with still no options, but a customized error string.
334 mojom::PaymentDetailsPtr details = mojom::PaymentDetails::New();
335 details->error = "No can do shipping.";
336 spec()->UpdateWith(std::move(details));
337
338 // No option selected, but there is an error provided by the mercahnt.
339 EXPECT_EQ(nullptr, spec()->selected_shipping_option());
340 EXPECT_EQ(base::ASCIIToUTF16("No can do shipping."),
341 spec()->selected_shipping_option_error());
300 } 342 }
301 343
302 } // namespace payments 344 } // namespace payments
OLDNEW
« 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