Chromium Code Reviews| Index: chrome/browser/ui/views/payments/profile_list_view_controller_browsertest.cc |
| diff --git a/chrome/browser/ui/views/payments/profile_list_view_controller_browsertest.cc b/chrome/browser/ui/views/payments/profile_list_view_controller_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..adde203adc94c51f0cfd6c482b918468a7f67793 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/payments/profile_list_view_controller_browsertest.cc |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/guid.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" |
| +#include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| +#include "components/autofill/core/browser/autofill_profile.h" |
| +#include "components/autofill/core/browser/autofill_test_utils.h" |
| +#include "components/autofill/core/browser/personal_data_manager.h" |
| +#include "ui/views/controls/label.h" |
| + |
| +namespace payments { |
| + |
| +autofill::AutofillProfile CreateProfileWithCompleteAddress() { |
|
Mathieu
2017/05/19 01:10:41
Could we use autofill::test::GetFullProfile?
tmartino
2017/05/19 18:11:26
Yup, done
|
| + autofill::AutofillProfile profile(base::GenerateGUID(), |
| + "http://www.example.com/"); |
| + autofill::test::SetProfileInfo(&profile, "Snoopy", "", "", "", "", |
| + "123 Doghouse St.", "", "Fakesville", "MN", |
| + "54000", "US", "6512345678"); |
| + return profile; |
| +} |
| + |
| +autofill::AutofillProfile CreateProfileWithPartialAddress() { |
| + autofill::AutofillProfile profile(base::GenerateGUID(), |
|
Mathieu
2017/05/19 01:10:40
could use GetFullProfile and remove things
tmartino
2017/05/19 18:11:26
Done
|
| + "http://www.example.com/"); |
| + autofill::test::SetProfileInfo(&profile, "Woodstock", "", "", "", "", |
| + "9 Nest Ave.", "", "", "", "54001", "", |
| + "6517654321"); |
| + return profile; |
| +} |
| + |
| +class PaymentRequestProfileListTest : public PaymentRequestBrowserTestBase { |
| + protected: |
| + PaymentRequestProfileListTest() |
| + : PaymentRequestBrowserTestBase( |
| + "/payment_request_free_shipping_test.html") {} |
| + |
| + // PersonalDataLoadedObserverMock personal_data_observer_; |
|
Mathieu
2017/05/19 01:10:40
fix
tmartino
2017/05/19 18:11:26
Done
|
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(PaymentRequestProfileListTest, PrioritizeCompleteness) { |
| + autofill::PersonalDataManager* personal_data_manager = GetDataManager(); |
|
Mathieu
2017/05/19 01:10:41
bring closer to where it's used
tmartino
2017/05/19 18:11:27
Done
|
| + // personal_data_manager->AddObserver(&personal_data_observer_); |
|
Mathieu
2017/05/19 01:10:40
fix
tmartino
2017/05/19 18:11:26
Done
|
| + |
| + autofill::AutofillProfile complete = CreateProfileWithCompleteAddress(); |
| + autofill::AutofillProfile partial = CreateProfileWithPartialAddress(); |
| + partial.set_use_count(1000); |
| + |
| + AddAutofillProfile(complete); |
| + AddAutofillProfile(partial); |
| + |
| + // In the Personal Data Manager, the partial address is more frecent. |
| + std::vector<autofill::AutofillProfile*> profiles = |
| + personal_data_manager->GetProfiles(); |
| + ASSERT_EQ(2UL, profiles.size()); |
| + EXPECT_EQ(partial, *profiles[0]); |
| + EXPECT_EQ(complete, *profiles[1]); |
| + |
| + InvokePaymentRequestUI(); |
| + |
| + PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front(); |
| + |
| + // The complete profile should be selected. |
| + ASSERT_TRUE(request->state()->selected_shipping_profile()); |
| + EXPECT_EQ(complete, *request->state()->selected_shipping_profile()); |
| + |
| + // It should appear first in the shipping profiles. |
| + ASSERT_EQ(2UL, request->state()->shipping_profiles().size()); |
| + EXPECT_EQ(complete, *request->state()->shipping_profiles()[0]); |
| + EXPECT_EQ(partial, *request->state()->shipping_profiles()[1]); |
| + |
| + // And both should appear in the UI. |
| + OpenShippingAddressSectionScreen(); |
| + views::View* sheet = dialog_view()->GetViewByID( |
| + static_cast<int>(DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW)); |
| + ASSERT_EQ(2, sheet->child_count()); |
| + views::View* first_label = sheet->child_at(0)->GetViewByID( |
| + static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); |
| + views::View* second_label = sheet->child_at(1)->GetViewByID( |
| + static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); |
| + |
| + EXPECT_EQ(base::ASCIIToUTF16("Snoopy"), |
| + static_cast<views::Label*>(first_label)->text()); |
| + EXPECT_EQ(base::ASCIIToUTF16("Woodstock"), |
| + static_cast<views::Label*>(second_label)->text()); |
| +} |
| + |
| +} // namespace payments |