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

Side by Side Diff: chrome/browser/ui/views/payments/shipping_address_editor_view_controller_browsertest.cc

Issue 2881643002: Focus first invalid field of payment request editor (Closed)
Patch Set: Last final nit :-) 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
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" 9 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
10 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 10 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Add incomplete address. 485 // Add incomplete address.
486 autofill::AutofillProfile profile; 486 autofill::AutofillProfile profile;
487 profile.SetInfo(autofill::AutofillType(autofill::NAME_FULL), 487 profile.SetInfo(autofill::AutofillType(autofill::NAME_FULL),
488 base::ASCIIToUTF16(kNameFull), kLocale); 488 base::ASCIIToUTF16(kNameFull), kLocale);
489 // Also set non-default country, to make sure proper fields will be used. 489 // Also set non-default country, to make sure proper fields will be used.
490 profile.SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY), 490 profile.SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY),
491 base::ASCIIToUTF16(kCountryWithoutStates), kLocale); 491 base::ASCIIToUTF16(kCountryWithoutStates), kLocale);
492 AddAutofillProfile(profile); 492 AddAutofillProfile(profile);
493 493
494 InvokePaymentRequestUI(); 494 InvokePaymentRequestUI();
495 SetRegionDataLoader(&test_region_data_loader_);
495 496
496 // One shipping address is available, but it's not selected. 497 // One shipping address is available, but it's not selected.
497 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front(); 498 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front();
498 EXPECT_EQ(1U, request->state()->shipping_profiles().size()); 499 EXPECT_EQ(1U, request->state()->shipping_profiles().size());
499 EXPECT_EQ(nullptr, request->state()->selected_shipping_profile()); 500 EXPECT_EQ(nullptr, request->state()->selected_shipping_profile());
500 501
502 test_region_data_loader_.set_synchronous_callback(true);
501 OpenShippingAddressSectionScreen(); 503 OpenShippingAddressSectionScreen();
502 504
503 ResetEventObserver(DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED); 505 ResetEventObserver(DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED);
504 ClickOnChildInListViewAndWait(/*child_index=*/0, /*num_children=*/1, 506 ClickOnChildInListViewAndWait(/*child_index=*/0, /*num_children=*/1,
505 DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW); 507 DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW);
506 508
507 EXPECT_EQ(base::ASCIIToUTF16(kNameFull), 509 EXPECT_EQ(base::ASCIIToUTF16(kNameFull),
508 GetEditorTextfieldValue(autofill::NAME_FULL)); 510 GetEditorTextfieldValue(autofill::NAME_FULL));
509 // There are no state field in |kCountryWithoutStates|. 511 // There are no state field in |kCountryWithoutStates|.
510 EXPECT_FALSE( 512 EXPECT_FALSE(
(...skipping 29 matching lines...) Expand all
540 autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY), kLocale)); 542 autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY), kLocale));
541 ExpectExistingRequiredFields(/*unset_types=*/nullptr, 543 ExpectExistingRequiredFields(/*unset_types=*/nullptr,
542 /*accept_empty_phone_number=*/false); 544 /*accept_empty_phone_number=*/false);
543 545
544 // Still have one shipping address, but now it's selected. 546 // Still have one shipping address, but now it's selected.
545 EXPECT_EQ(1U, request->state()->shipping_profiles().size()); 547 EXPECT_EQ(1U, request->state()->shipping_profiles().size());
546 EXPECT_EQ(request->state()->shipping_profiles().back(), 548 EXPECT_EQ(request->state()->shipping_profiles().back(),
547 request->state()->selected_shipping_profile()); 549 request->state()->selected_shipping_profile());
548 } 550 }
549 551
552 IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest,
553 FocusFirstInvalidField_Name) {
554 InvokePaymentRequestUI();
555 SetRegionDataLoader(&test_region_data_loader_);
556
557 test_region_data_loader_.set_synchronous_callback(true);
558 OpenShippingAddressEditorScreen();
559
560 // We know that the name field is always the first one in a shipping address.
561 views::Textfield* textfield = static_cast<views::Textfield*>(
562 dialog_view()->GetViewByID(static_cast<int>(autofill::NAME_FULL)));
563 DCHECK(textfield);
564 EXPECT_TRUE(textfield->text().empty());
565 EXPECT_TRUE(textfield->invalid());
566 EXPECT_TRUE(textfield->HasFocus());
567 }
568
569 IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest,
570 FocusFirstInvalidField_NotName) {
571 // Add address with the name set, so that another view takes focus.
572 autofill::AutofillProfile profile;
573 profile.SetInfo(autofill::AutofillType(autofill::NAME_FULL),
574 base::ASCIIToUTF16(kNameFull), "fr_CA");
575 AddAutofillProfile(profile);
576
577 InvokePaymentRequestUI();
578 SetRegionDataLoader(&test_region_data_loader_);
579 test_region_data_loader_.set_synchronous_callback(true);
580 OpenShippingAddressSectionScreen();
581 ResetEventObserver(DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED);
582 ClickOnChildInListViewAndWait(/*child_index=*/0, /*num_children=*/1,
583 DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW);
584
585 views::Textfield* textfield = static_cast<views::Textfield*>(
586 dialog_view()->GetViewByID(static_cast<int>(autofill::NAME_FULL)));
587 DCHECK(textfield);
588 EXPECT_FALSE(textfield->text().empty());
589 EXPECT_FALSE(textfield->invalid());
590 EXPECT_FALSE(textfield->HasFocus());
591
592 // Since we can't easily tell which field is after name, let's just make sure
593 // that a view has focus. Unfortunately, we can't cast it to a specific type
594 // that we could query for validity (it could be either text or combobox).
595 EXPECT_NE(textfield->GetFocusManager()->GetFocusedView(), nullptr);
596 }
597
550 } // namespace payments 598 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698