OLD | NEW |
---|---|
(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/personal_data_manager.h" | |
12 #include "ui/views/controls/label.h" | |
13 | |
14 namespace payments { | |
15 | |
16 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
| |
17 autofill::AutofillProfile profile(base::GenerateGUID(), | |
18 "http://www.example.com/"); | |
19 autofill::test::SetProfileInfo(&profile, "Snoopy", "", "", "", "", | |
20 "123 Doghouse St.", "", "Fakesville", "MN", | |
21 "54000", "US", "6512345678"); | |
22 return profile; | |
23 } | |
24 | |
25 autofill::AutofillProfile CreateProfileWithPartialAddress() { | |
26 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
| |
27 "http://www.example.com/"); | |
28 autofill::test::SetProfileInfo(&profile, "Woodstock", "", "", "", "", | |
29 "9 Nest Ave.", "", "", "", "54001", "", | |
30 "6517654321"); | |
31 return profile; | |
32 } | |
33 | |
34 class PaymentRequestProfileListTest : public PaymentRequestBrowserTestBase { | |
35 protected: | |
36 PaymentRequestProfileListTest() | |
37 : PaymentRequestBrowserTestBase( | |
38 "/payment_request_free_shipping_test.html") {} | |
39 | |
40 // PersonalDataLoadedObserverMock personal_data_observer_; | |
Mathieu
2017/05/19 01:10:40
fix
tmartino
2017/05/19 18:11:26
Done
| |
41 }; | |
42 | |
43 IN_PROC_BROWSER_TEST_F(PaymentRequestProfileListTest, PrioritizeCompleteness) { | |
44 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
| |
45 // personal_data_manager->AddObserver(&personal_data_observer_); | |
Mathieu
2017/05/19 01:10:40
fix
tmartino
2017/05/19 18:11:26
Done
| |
46 | |
47 autofill::AutofillProfile complete = CreateProfileWithCompleteAddress(); | |
48 autofill::AutofillProfile partial = CreateProfileWithPartialAddress(); | |
49 partial.set_use_count(1000); | |
50 | |
51 AddAutofillProfile(complete); | |
52 AddAutofillProfile(partial); | |
53 | |
54 // In the Personal Data Manager, the partial address is more frecent. | |
55 std::vector<autofill::AutofillProfile*> profiles = | |
56 personal_data_manager->GetProfiles(); | |
57 ASSERT_EQ(2UL, profiles.size()); | |
58 EXPECT_EQ(partial, *profiles[0]); | |
59 EXPECT_EQ(complete, *profiles[1]); | |
60 | |
61 InvokePaymentRequestUI(); | |
62 | |
63 PaymentRequest* request = GetPaymentRequests(GetActiveWebContents()).front(); | |
64 | |
65 // The complete profile should be selected. | |
66 ASSERT_TRUE(request->state()->selected_shipping_profile()); | |
67 EXPECT_EQ(complete, *request->state()->selected_shipping_profile()); | |
68 | |
69 // It should appear first in the shipping profiles. | |
70 ASSERT_EQ(2UL, request->state()->shipping_profiles().size()); | |
71 EXPECT_EQ(complete, *request->state()->shipping_profiles()[0]); | |
72 EXPECT_EQ(partial, *request->state()->shipping_profiles()[1]); | |
73 | |
74 // And both should appear in the UI. | |
75 OpenShippingAddressSectionScreen(); | |
76 views::View* sheet = dialog_view()->GetViewByID( | |
77 static_cast<int>(DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW)); | |
78 ASSERT_EQ(2, sheet->child_count()); | |
79 views::View* first_label = sheet->child_at(0)->GetViewByID( | |
80 static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); | |
81 views::View* second_label = sheet->child_at(1)->GetViewByID( | |
82 static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); | |
83 | |
84 EXPECT_EQ(base::ASCIIToUTF16("Snoopy"), | |
85 static_cast<views::Label*>(first_label)->text()); | |
86 EXPECT_EQ(base::ASCIIToUTF16("Woodstock"), | |
87 static_cast<views::Label*>(second_label)->text()); | |
88 } | |
89 | |
90 } // namespace payments | |
OLD | NEW |