OLD | NEW |
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/editor_view_controller.h" |
9 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" |
10 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 11 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
11 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 12 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
12 #include "components/autofill/core/browser/autofill_country.h" | 13 #include "components/autofill/core/browser/autofill_country.h" |
13 #include "components/autofill/core/browser/country_combobox_model.h" | 14 #include "components/autofill/core/browser/country_combobox_model.h" |
14 #include "components/autofill/core/browser/personal_data_manager.h" | 15 #include "components/autofill/core/browser/personal_data_manager.h" |
15 #include "components/autofill/core/browser/region_combobox_model.h" | 16 #include "components/autofill/core/browser/region_combobox_model.h" |
16 #include "components/autofill/core/browser/test_region_data_loader.h" | 17 #include "components/autofill/core/browser/test_region_data_loader.h" |
17 #include "components/payments/content/payment_request_spec.h" | 18 #include "components/payments/content/payment_request_spec.h" |
18 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 SetFieldTestValue(autofill::ADDRESS_HOME_STREET_ADDRESS); | 84 SetFieldTestValue(autofill::ADDRESS_HOME_STREET_ADDRESS); |
84 SetFieldTestValue(autofill::ADDRESS_HOME_CITY); | 85 SetFieldTestValue(autofill::ADDRESS_HOME_CITY); |
85 SetFieldTestValue(autofill::ADDRESS_HOME_ZIP); | 86 SetFieldTestValue(autofill::ADDRESS_HOME_ZIP); |
86 SetFieldTestValue(autofill::PHONE_HOME_WHOLE_NUMBER); | 87 SetFieldTestValue(autofill::PHONE_HOME_WHOLE_NUMBER); |
87 } | 88 } |
88 | 89 |
89 // First check if the requested field of |type| exists, if so, set its value | 90 // First check if the requested field of |type| exists, if so, set its value |
90 // in |textfield_text| if it's not null, and return true. | 91 // in |textfield_text| if it's not null, and return true. |
91 bool GetEditorTextfieldValueIfExists(autofill::ServerFieldType type, | 92 bool GetEditorTextfieldValueIfExists(autofill::ServerFieldType type, |
92 base::string16* textfield_text) { | 93 base::string16* textfield_text) { |
93 ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>( | 94 ValidatingTextfield* textfield = |
94 dialog_view()->GetViewByID(static_cast<int>(type))); | 95 static_cast<ValidatingTextfield*>(dialog_view()->GetViewByID( |
| 96 EditorViewController::GetInputFieldViewId(type))); |
95 if (!textfield) | 97 if (!textfield) |
96 return false; | 98 return false; |
97 if (textfield_text) | 99 if (textfield_text) |
98 *textfield_text = textfield->text(); | 100 *textfield_text = textfield->text(); |
99 return true; | 101 return true; |
100 } | 102 } |
101 | 103 |
102 // |unset_types| can be null, but when it's not, the fields that are not set | 104 // |unset_types| can be null, but when it's not, the fields that are not set |
103 // get their type added to it, so that the caller can tell which types are not | 105 // get their type added to it, so that the caller can tell which types are not |
104 // set for a given country. |accept_empty_phone_number| can be set to true to | 106 // set for a given country. |accept_empty_phone_number| can be set to true to |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 unset_types->insert(autofill::PHONE_HOME_WHOLE_NUMBER); | 147 unset_types->insert(autofill::PHONE_HOME_WHOLE_NUMBER); |
146 } else if (textfield_text != base::ASCIIToUTF16(kHomePhone)) { | 148 } else if (textfield_text != base::ASCIIToUTF16(kHomePhone)) { |
147 EXPECT_EQ(base::ASCIIToUTF16(kFormattedHomePhone), textfield_text); | 149 EXPECT_EQ(base::ASCIIToUTF16(kFormattedHomePhone), textfield_text); |
148 } | 150 } |
149 } else if (unset_types) { | 151 } else if (unset_types) { |
150 unset_types->insert(autofill::PHONE_HOME_WHOLE_NUMBER); | 152 unset_types->insert(autofill::PHONE_HOME_WHOLE_NUMBER); |
151 } | 153 } |
152 } | 154 } |
153 | 155 |
154 std::string GetSelectedCountryCode() { | 156 std::string GetSelectedCountryCode() { |
155 views::Combobox* country_combobox = | 157 views::Combobox* country_combobox = static_cast<views::Combobox*>( |
156 static_cast<views::Combobox*>(dialog_view()->GetViewByID( | 158 dialog_view()->GetViewByID(EditorViewController::GetInputFieldViewId( |
157 static_cast<int>(autofill::ADDRESS_HOME_COUNTRY))); | 159 autofill::ADDRESS_HOME_COUNTRY))); |
158 DCHECK(country_combobox); | 160 DCHECK(country_combobox); |
159 int selected_country_row = country_combobox->GetSelectedRow(); | 161 int selected_country_row = country_combobox->GetSelectedRow(); |
160 autofill::CountryComboboxModel* country_model = | 162 autofill::CountryComboboxModel* country_model = |
161 static_cast<autofill::CountryComboboxModel*>(country_combobox->model()); | 163 static_cast<autofill::CountryComboboxModel*>(country_combobox->model()); |
162 | 164 |
163 return country_model->countries()[selected_country_row]->country_code(); | 165 return country_model->countries()[selected_country_row]->country_code(); |
164 } | 166 } |
165 | 167 |
166 PersonalDataLoadedObserverMock personal_data_observer_; | 168 PersonalDataLoadedObserverMock personal_data_observer_; |
167 autofill::TestRegionDataLoader test_region_data_loader_; | 169 autofill::TestRegionDataLoader test_region_data_loader_; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 SetRegionDataLoader(&test_region_data_loader_); | 311 SetRegionDataLoader(&test_region_data_loader_); |
310 | 312 |
311 test_region_data_loader_.set_synchronous_callback(false); | 313 test_region_data_loader_.set_synchronous_callback(false); |
312 OpenShippingAddressEditorScreen(); | 314 OpenShippingAddressEditorScreen(); |
313 std::vector<std::pair<std::string, std::string>> regions1; | 315 std::vector<std::pair<std::string, std::string>> regions1; |
314 regions1.push_back(std::make_pair("1a", "region1a")); | 316 regions1.push_back(std::make_pair("1a", "region1a")); |
315 test_region_data_loader_.SendAsynchronousData(regions1); | 317 test_region_data_loader_.SendAsynchronousData(regions1); |
316 | 318 |
317 SetCommonFields(); | 319 SetCommonFields(); |
318 | 320 |
319 views::Combobox* country_combobox = | 321 views::Combobox* country_combobox = static_cast<views::Combobox*>( |
320 static_cast<views::Combobox*>(dialog_view()->GetViewByID( | 322 dialog_view()->GetViewByID(EditorViewController::GetInputFieldViewId( |
321 static_cast<int>(autofill::ADDRESS_HOME_COUNTRY))); | 323 autofill::ADDRESS_HOME_COUNTRY))); |
322 ASSERT_NE(nullptr, country_combobox); | 324 ASSERT_NE(nullptr, country_combobox); |
323 ASSERT_EQ(0, country_combobox->GetSelectedRow()); | 325 ASSERT_EQ(0, country_combobox->GetSelectedRow()); |
324 autofill::CountryComboboxModel* country_model = | 326 autofill::CountryComboboxModel* country_model = |
325 static_cast<autofill::CountryComboboxModel*>(country_combobox->model()); | 327 static_cast<autofill::CountryComboboxModel*>(country_combobox->model()); |
326 size_t num_countries = country_model->countries().size(); | 328 size_t num_countries = country_model->countries().size(); |
327 ASSERT_GT(num_countries, 10UL); | 329 ASSERT_GT(num_countries, 10UL); |
328 | 330 |
329 bool use_regions1 = true; | 331 bool use_regions1 = true; |
330 std::vector<std::pair<std::string, std::string>> regions2; | 332 std::vector<std::pair<std::string, std::string>> regions2; |
331 regions2.push_back(std::make_pair("2a", "region2a")); | 333 regions2.push_back(std::make_pair("2a", "region2a")); |
332 regions2.push_back(std::make_pair("2b", "region2b")); | 334 regions2.push_back(std::make_pair("2b", "region2b")); |
333 std::set<autofill::ServerFieldType> unset_types; | 335 std::set<autofill::ServerFieldType> unset_types; |
334 for (size_t country_index = 10; country_index < num_countries; | 336 for (size_t country_index = 10; country_index < num_countries; |
335 country_index += num_countries / 10) { | 337 country_index += num_countries / 10) { |
336 // The editor updates asynchronously when the country changes. | 338 // The editor updates asynchronously when the country changes. |
337 ResetEventObserver(DialogEvent::EDITOR_VIEW_UPDATED); | 339 ResetEventObserver(DialogEvent::EDITOR_VIEW_UPDATED); |
338 | 340 |
339 views::Combobox* region_combobox = | 341 views::Combobox* region_combobox = static_cast<views::Combobox*>( |
340 static_cast<views::Combobox*>(dialog_view()->GetViewByID( | 342 dialog_view()->GetViewByID(EditorViewController::GetInputFieldViewId( |
341 static_cast<int>(autofill::ADDRESS_HOME_STATE))); | 343 autofill::ADDRESS_HOME_STATE))); |
342 autofill::RegionComboboxModel* region_model = nullptr; | 344 autofill::RegionComboboxModel* region_model = nullptr; |
343 // Some countries don't have a state combobox. | 345 // Some countries don't have a state combobox. |
344 if (region_combobox) { | 346 if (region_combobox) { |
345 autofill::RegionComboboxModel* region_model = | 347 autofill::RegionComboboxModel* region_model = |
346 static_cast<autofill::RegionComboboxModel*>(region_combobox->model()); | 348 static_cast<autofill::RegionComboboxModel*>(region_combobox->model()); |
347 if (use_regions1) { | 349 if (use_regions1) { |
348 ASSERT_EQ(1, region_model->GetItemCount()); | 350 ASSERT_EQ(1, region_model->GetItemCount()); |
349 EXPECT_EQ(base::ASCIIToUTF16("region1a"), region_model->GetItemAt(0)); | 351 EXPECT_EQ(base::ASCIIToUTF16("region1a"), region_model->GetItemAt(0)); |
350 } else { | 352 } else { |
351 ASSERT_EQ(2, region_model->GetItemCount()); | 353 ASSERT_EQ(2, region_model->GetItemCount()); |
(...skipping 10 matching lines...) Expand all Loading... |
362 country_combobox = nullptr; | 364 country_combobox = nullptr; |
363 country_model = nullptr; | 365 country_model = nullptr; |
364 region_combobox = nullptr; | 366 region_combobox = nullptr; |
365 region_model = nullptr; | 367 region_model = nullptr; |
366 WaitForObservedEvent(); | 368 WaitForObservedEvent(); |
367 | 369 |
368 // Some types could have been lost in previous countries and may now | 370 // Some types could have been lost in previous countries and may now |
369 // available in this country. | 371 // available in this country. |
370 std::set<autofill::ServerFieldType> set_types; | 372 std::set<autofill::ServerFieldType> set_types; |
371 for (auto type : unset_types) { | 373 for (auto type : unset_types) { |
372 ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>( | 374 ValidatingTextfield* textfield = |
373 dialog_view()->GetViewByID(static_cast<int>(type))); | 375 static_cast<ValidatingTextfield*>(dialog_view()->GetViewByID( |
| 376 EditorViewController::GetInputFieldViewId(type))); |
374 if (textfield) { | 377 if (textfield) { |
375 EXPECT_TRUE(textfield->text().empty()) << type; | 378 EXPECT_TRUE(textfield->text().empty()) << type; |
376 SetFieldTestValue(type); | 379 SetFieldTestValue(type); |
377 set_types.insert(type); | 380 set_types.insert(type); |
378 } | 381 } |
379 } | 382 } |
380 for (auto type : set_types) { | 383 for (auto type : set_types) { |
381 unset_types.erase(type); | 384 unset_types.erase(type); |
382 } | 385 } |
383 | 386 |
384 // Make sure the country combobox was properly reset to the chosen country. | 387 // Make sure the country combobox was properly reset to the chosen country. |
385 country_combobox = static_cast<views::Combobox*>(dialog_view()->GetViewByID( | 388 country_combobox = static_cast<views::Combobox*>( |
386 static_cast<int>(autofill::ADDRESS_HOME_COUNTRY))); | 389 dialog_view()->GetViewByID(EditorViewController::GetInputFieldViewId( |
| 390 autofill::ADDRESS_HOME_COUNTRY))); |
387 DCHECK(country_combobox); | 391 DCHECK(country_combobox); |
388 EXPECT_EQ(country_index, | 392 EXPECT_EQ(country_index, |
389 static_cast<size_t>(country_combobox->GetSelectedRow())); | 393 static_cast<size_t>(country_combobox->GetSelectedRow())); |
390 country_model = | 394 country_model = |
391 static_cast<autofill::CountryComboboxModel*>(country_combobox->model()); | 395 static_cast<autofill::CountryComboboxModel*>(country_combobox->model()); |
392 ASSERT_EQ(num_countries, country_model->countries().size()); | 396 ASSERT_EQ(num_countries, country_model->countries().size()); |
393 | 397 |
394 // Update regions. | 398 // Update regions. |
395 test_region_data_loader_.SendAsynchronousData(use_regions1 ? regions1 | 399 test_region_data_loader_.SendAsynchronousData(use_regions1 ? regions1 |
396 : regions2); | 400 : regions2); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 | 555 |
552 IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest, | 556 IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest, |
553 FocusFirstInvalidField_Name) { | 557 FocusFirstInvalidField_Name) { |
554 InvokePaymentRequestUI(); | 558 InvokePaymentRequestUI(); |
555 SetRegionDataLoader(&test_region_data_loader_); | 559 SetRegionDataLoader(&test_region_data_loader_); |
556 | 560 |
557 test_region_data_loader_.set_synchronous_callback(true); | 561 test_region_data_loader_.set_synchronous_callback(true); |
558 OpenShippingAddressEditorScreen(); | 562 OpenShippingAddressEditorScreen(); |
559 | 563 |
560 // We know that the name field is always the first one in a shipping address. | 564 // We know that the name field is always the first one in a shipping address. |
561 views::Textfield* textfield = static_cast<views::Textfield*>( | 565 views::Textfield* textfield = |
562 dialog_view()->GetViewByID(static_cast<int>(autofill::NAME_FULL))); | 566 static_cast<views::Textfield*>(dialog_view()->GetViewByID( |
| 567 EditorViewController::GetInputFieldViewId(autofill::NAME_FULL))); |
563 DCHECK(textfield); | 568 DCHECK(textfield); |
564 EXPECT_TRUE(textfield->text().empty()); | 569 EXPECT_TRUE(textfield->text().empty()); |
565 EXPECT_TRUE(textfield->invalid()); | 570 EXPECT_TRUE(textfield->invalid()); |
566 EXPECT_TRUE(textfield->HasFocus()); | 571 EXPECT_TRUE(textfield->HasFocus()); |
567 } | 572 } |
568 | 573 |
569 IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest, | 574 IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressEditorTest, |
570 FocusFirstInvalidField_NotName) { | 575 FocusFirstInvalidField_NotName) { |
571 // Add address with the name set, so that another view takes focus. | 576 // Add address with the name set, so that another view takes focus. |
572 autofill::AutofillProfile profile; | 577 autofill::AutofillProfile profile; |
573 profile.SetInfo(autofill::AutofillType(autofill::NAME_FULL), | 578 profile.SetInfo(autofill::AutofillType(autofill::NAME_FULL), |
574 base::ASCIIToUTF16(kNameFull), "fr_CA"); | 579 base::ASCIIToUTF16(kNameFull), "fr_CA"); |
575 AddAutofillProfile(profile); | 580 AddAutofillProfile(profile); |
576 | 581 |
577 InvokePaymentRequestUI(); | 582 InvokePaymentRequestUI(); |
578 SetRegionDataLoader(&test_region_data_loader_); | 583 SetRegionDataLoader(&test_region_data_loader_); |
579 test_region_data_loader_.set_synchronous_callback(true); | 584 test_region_data_loader_.set_synchronous_callback(true); |
580 OpenShippingAddressSectionScreen(); | 585 OpenShippingAddressSectionScreen(); |
581 ResetEventObserver(DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED); | 586 ResetEventObserver(DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED); |
582 ClickOnChildInListViewAndWait(/*child_index=*/0, /*num_children=*/1, | 587 ClickOnChildInListViewAndWait(/*child_index=*/0, /*num_children=*/1, |
583 DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW); | 588 DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW); |
584 | 589 |
585 views::Textfield* textfield = static_cast<views::Textfield*>( | 590 views::Textfield* textfield = |
586 dialog_view()->GetViewByID(static_cast<int>(autofill::NAME_FULL))); | 591 static_cast<views::Textfield*>(dialog_view()->GetViewByID( |
| 592 EditorViewController::GetInputFieldViewId(autofill::NAME_FULL))); |
587 DCHECK(textfield); | 593 DCHECK(textfield); |
588 EXPECT_FALSE(textfield->text().empty()); | 594 EXPECT_FALSE(textfield->text().empty()); |
589 EXPECT_FALSE(textfield->invalid()); | 595 EXPECT_FALSE(textfield->invalid()); |
590 EXPECT_FALSE(textfield->HasFocus()); | 596 EXPECT_FALSE(textfield->HasFocus()); |
591 | 597 |
592 // Since we can't easily tell which field is after name, let's just make sure | 598 // 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 | 599 // 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). | 600 // that we could query for validity (it could be either text or combobox). |
595 EXPECT_NE(textfield->GetFocusManager()->GetFocusedView(), nullptr); | 601 EXPECT_NE(textfield->GetFocusManager()->GetFocusedView(), nullptr); |
596 } | 602 } |
597 | 603 |
598 } // namespace payments | 604 } // namespace payments |
OLD | NEW |