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

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

Issue 2715213005: [Payments] Add the pay button, and control its enabled state (Closed)
Patch Set: addressed comments Created 3 years, 9 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
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 "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba se.h" 5 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba se.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "chrome/browser/autofill/personal_data_manager_factory.h" 14 #include "chrome/browser/autofill/personal_data_manager_factory.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
19 #include "chrome/browser/ui/views/payments/validating_combobox.h" 19 #include "chrome/browser/ui/views/payments/validating_combobox.h"
20 #include "chrome/browser/ui/views/payments/validating_textfield.h" 20 #include "chrome/browser/ui/views/payments/validating_textfield.h"
21 #include "chrome/browser/ui/views/payments/view_stack.h" 21 #include "chrome/browser/ui/views/payments/view_stack.h"
22 #include "chrome/test/base/interactive_test_utils.h" 22 #include "chrome/test/base/interactive_test_utils.h"
23 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/autofill/core/browser/autofill_profile.h"
25 #include "components/autofill/core/browser/credit_card.h"
26 #include "components/autofill/core/browser/personal_data_manager.h"
24 #include "components/payments/content/payment_request.h" 27 #include "components/payments/content/payment_request.h"
25 #include "components/payments/content/payment_request_web_contents_manager.h" 28 #include "components/payments/content/payment_request_web_contents_manager.h"
26 #include "components/web_modal/web_contents_modal_dialog_manager.h" 29 #include "components/web_modal/web_contents_modal_dialog_manager.h"
27 #include "content/public/browser/render_frame_host.h" 30 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/content_switches.h" 32 #include "content/public/common/content_switches.h"
30 #include "content/public/test/browser_test_utils.h" 33 #include "content/public/test/browser_test_utils.h"
31 #include "services/service_manager/public/cpp/interface_registry.h" 34 #include "services/service_manager/public/cpp/interface_registry.h"
32 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
33 #include "ui/base/test/ui_controls.h" 36 #include "ui/base/test/ui_controls.h"
34 #include "ui/gfx/animation/test_animation_delegate.h" 37 #include "ui/gfx/animation/test_animation_delegate.h"
38 #include "ui/views/controls/button/button.h"
35 #include "ui/views/controls/label.h" 39 #include "ui/views/controls/label.h"
36 #include "ui/views/controls/styled_label.h" 40 #include "ui/views/controls/styled_label.h"
37 41
38 namespace payments { 42 namespace payments {
39 43
40 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} 44 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {}
41 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} 45 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {}
42 46
43 PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase( 47 PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase(
44 const std::string& test_file_path) 48 const std::string& test_file_path)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 payment_requests_ptrs.push_back(p.first); 161 payment_requests_ptrs.push_back(p.first);
158 return payment_requests_ptrs; 162 return payment_requests_ptrs;
159 } 163 }
160 164
161 autofill::PersonalDataManager* 165 autofill::PersonalDataManager*
162 PaymentRequestInteractiveTestBase::GetDataManager() { 166 PaymentRequestInteractiveTestBase::GetDataManager() {
163 return autofill::PersonalDataManagerFactory::GetForProfile( 167 return autofill::PersonalDataManagerFactory::GetForProfile(
164 Profile::FromBrowserContext(GetActiveWebContents()->GetBrowserContext())); 168 Profile::FromBrowserContext(GetActiveWebContents()->GetBrowserContext()));
165 } 169 }
166 170
171 void PaymentRequestInteractiveTestBase::AddAutofillProfile(
172 const autofill::AutofillProfile& profile) {
173 autofill::PersonalDataManager* personal_data_manager = GetDataManager();
174 size_t profile_count = personal_data_manager->GetProfiles().size();
175
176 PersonalDataLoadedObserverMock personal_data_observer;
177 personal_data_manager->AddObserver(&personal_data_observer);
178 base::RunLoop data_loop;
179 EXPECT_CALL(personal_data_observer, OnPersonalDataChanged())
180 .WillOnce(QuitMessageLoop(&data_loop));
181 personal_data_manager->AddProfile(profile);
182 data_loop.Run();
183
184 personal_data_manager->RemoveObserver(&personal_data_observer);
185 EXPECT_EQ(profile_count + 1, personal_data_manager->GetProfiles().size());
186 }
187
188 void PaymentRequestInteractiveTestBase::AddCreditCard(
189 const autofill::CreditCard& card) {
190 autofill::PersonalDataManager* personal_data_manager = GetDataManager();
191 size_t card_count = personal_data_manager->GetCreditCards().size();
192
193 PersonalDataLoadedObserverMock personal_data_observer;
194 personal_data_manager->AddObserver(&personal_data_observer);
195 base::RunLoop data_loop;
196 EXPECT_CALL(personal_data_observer, OnPersonalDataChanged())
197 .WillOnce(QuitMessageLoop(&data_loop));
198 personal_data_manager->AddCreditCard(card);
199 data_loop.Run();
200
201 personal_data_manager->RemoveObserver(&personal_data_observer);
202 EXPECT_EQ(card_count + 1, personal_data_manager->GetCreditCards().size());
203 }
204
167 void PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest( 205 void PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest(
168 content::WebContents* web_contents, 206 content::WebContents* web_contents,
169 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { 207 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) {
170 DCHECK(web_contents); 208 DCHECK(web_contents);
171 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = 209 std::unique_ptr<TestChromePaymentRequestDelegate> delegate =
172 base::MakeUnique<TestChromePaymentRequestDelegate>( 210 base::MakeUnique<TestChromePaymentRequestDelegate>(
173 web_contents, this /* observer */, this /* widget_observer */); 211 web_contents, this /* observer */, this /* widget_observer */);
174 delegate_ = delegate.get(); 212 delegate_ = delegate.get();
175 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) 213 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents)
176 ->CreatePaymentRequest(web_contents, std::move(delegate), 214 ->CreatePaymentRequest(web_contents, std::move(delegate),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 268 }
231 269
232 bool PaymentRequestInteractiveTestBase::IsEditorComboboxInvalid( 270 bool PaymentRequestInteractiveTestBase::IsEditorComboboxInvalid(
233 autofill::ServerFieldType type) { 271 autofill::ServerFieldType type) {
234 ValidatingCombobox* combobox = static_cast<ValidatingCombobox*>( 272 ValidatingCombobox* combobox = static_cast<ValidatingCombobox*>(
235 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); 273 delegate_->dialog_view()->GetViewByID(static_cast<int>(type)));
236 DCHECK(combobox); 274 DCHECK(combobox);
237 return combobox->invalid(); 275 return combobox->invalid();
238 } 276 }
239 277
278 bool PaymentRequestInteractiveTestBase::IsPayButtonEnabled() {
279 views::Button* button =
280 static_cast<views::Button*>(delegate_->dialog_view()->GetViewByID(
281 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAY_BUTTON)));
282 DCHECK(button);
283 return button->enabled();
284 }
285
240 void PaymentRequestInteractiveTestBase::WaitForAnimation() { 286 void PaymentRequestInteractiveTestBase::WaitForAnimation() {
241 ViewStack* view_stack = dialog_view()->view_stack_for_testing(); 287 ViewStack* view_stack = dialog_view()->view_stack_for_testing();
242 if (view_stack->slide_in_animator_->IsAnimating()) { 288 if (view_stack->slide_in_animator_->IsAnimating()) {
243 view_stack->slide_in_animator_->SetAnimationDuration(1); 289 view_stack->slide_in_animator_->SetAnimationDuration(1);
244 view_stack->slide_in_animator_->SetAnimationDelegate( 290 view_stack->slide_in_animator_->SetAnimationDelegate(
245 view_stack->top(), std::unique_ptr<gfx::AnimationDelegate>( 291 view_stack->top(), std::unique_ptr<gfx::AnimationDelegate>(
246 new gfx::TestAnimationDelegate())); 292 new gfx::TestAnimationDelegate()));
247 base::RunLoop().Run(); 293 base::RunLoop().Run();
248 } else if (view_stack->slide_out_animator_->IsAnimating()) { 294 } else if (view_stack->slide_out_animator_->IsAnimating()) {
249 view_stack->slide_out_animator_->SetAnimationDuration(1); 295 view_stack->slide_out_animator_->SetAnimationDuration(1);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 342
297 void PaymentRequestInteractiveTestBase::ResetEventObserver(DialogEvent event) { 343 void PaymentRequestInteractiveTestBase::ResetEventObserver(DialogEvent event) {
298 event_observer_ = base::MakeUnique<DialogEventObserver>(event); 344 event_observer_ = base::MakeUnique<DialogEventObserver>(event);
299 } 345 }
300 346
301 void PaymentRequestInteractiveTestBase::WaitForObservedEvent() { 347 void PaymentRequestInteractiveTestBase::WaitForObservedEvent() {
302 event_observer_->Wait(); 348 event_observer_->Wait();
303 } 349 }
304 350
305 } // namespace payments 351 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698