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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 ExpectExistingRequiredFields(/*unset_types=*/nullptr, | 545 ExpectExistingRequiredFields(/*unset_types=*/nullptr, |
542 /*accept_empty_phone_number=*/false); | 546 /*accept_empty_phone_number=*/false); |
543 | 547 |
544 // Still have one shipping address, but now it's selected. | 548 // Still have one shipping address, but now it's selected. |
545 EXPECT_EQ(1U, request->state()->shipping_profiles().size()); | 549 EXPECT_EQ(1U, request->state()->shipping_profiles().size()); |
546 EXPECT_EQ(request->state()->shipping_profiles().back(), | 550 EXPECT_EQ(request->state()->shipping_profiles().back(), |
547 request->state()->selected_shipping_profile()); | 551 request->state()->selected_shipping_profile()); |
548 } | 552 } |
549 | 553 |
550 } // namespace payments | 554 } // namespace payments |
OLD | NEW |