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

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

Issue 2884393002: [WebPayments] Adding FilterProfilesForShipping to profile comparator (Closed)
Patch Set: rebase 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/guid.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
9 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/autofill_test_utils.h"
11 #include "components/autofill/core/browser/field_types.h"
12 #include "components/autofill/core/browser/personal_data_manager.h"
13 #include "ui/views/controls/label.h"
14
15 namespace payments {
16
17 autofill::AutofillProfile CreateProfileWithPartialAddress() {
18 autofill::AutofillProfile profile = autofill::test::GetFullProfile2();
19 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE1, base::ASCIIToUTF16(""));
20 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE2, base::ASCIIToUTF16(""));
21 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, base::ASCIIToUTF16(""));
22 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, base::ASCIIToUTF16(""));
23 return profile;
24 }
25
26 class PaymentRequestProfileListTest : public PaymentRequestBrowserTestBase {
27 protected:
28 PaymentRequestProfileListTest()
29 : PaymentRequestBrowserTestBase(
30 "/payment_request_free_shipping_test.html") {}
31 };
32
33 IN_PROC_BROWSER_TEST_F(PaymentRequestProfileListTest, PrioritizeCompleteness) {
34 autofill::AutofillProfile complete = autofill::test::GetFullProfile();
35 autofill::AutofillProfile partial = CreateProfileWithPartialAddress();
36 partial.set_use_count(1000);
37
38 AddAutofillProfile(complete);
39 AddAutofillProfile(partial);
40
41 // In the Personal Data Manager, the partial address is more frecent.
42 autofill::PersonalDataManager* personal_data_manager = GetDataManager();
43 std::vector<autofill::AutofillProfile*> profiles =
44 personal_data_manager->GetProfilesToSuggest();
45 ASSERT_EQ(2UL, profiles.size());
46 EXPECT_EQ(partial, *profiles[0]);
47 EXPECT_EQ(complete, *profiles[1]);
48
49 InvokePaymentRequestUI();
50
51 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front();
52
53 // The complete profile should be selected.
54 ASSERT_TRUE(request->state()->selected_shipping_profile());
55 EXPECT_EQ(complete, *request->state()->selected_shipping_profile());
56
57 // It should appear first in the shipping profiles.
58 ASSERT_EQ(2UL, request->state()->shipping_profiles().size());
59 EXPECT_EQ(complete, *request->state()->shipping_profiles()[0]);
60 EXPECT_EQ(partial, *request->state()->shipping_profiles()[1]);
61
62 // And both should appear in the UI.
63 OpenShippingAddressSectionScreen();
64 views::View* sheet = dialog_view()->GetViewByID(
65 static_cast<int>(DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW));
66 ASSERT_EQ(2, sheet->child_count());
67 views::View* first_label = sheet->child_at(0)->GetViewByID(
68 static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1));
69 views::View* second_label = sheet->child_at(1)->GetViewByID(
70 static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1));
71
72 EXPECT_EQ(base::ASCIIToUTF16("John H. Doe"),
73 static_cast<views::Label*>(first_label)->text());
74 EXPECT_EQ(base::ASCIIToUTF16("Jane A. Smith"),
75 static_cast<views::Label*>(second_label)->text());
76 }
77
78 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/contact_info_editor_view_controller_browsertest.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698