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

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

Issue 2676663002: [Payments] Implements the credit card editor for Desktop UI (Closed)
Patch Set: formatting Created 3 years, 10 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/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
17 #include "chrome/browser/ui/views/payments/view_stack.h"
17 #include "chrome/test/base/interactive_test_utils.h" 18 #include "chrome/test/base/interactive_test_utils.h"
18 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
19 #include "components/payments/payment_request.h" 20 #include "components/payments/payment_request.h"
20 #include "components/payments/payment_request_web_contents_manager.h" 21 #include "components/payments/payment_request_web_contents_manager.h"
21 #include "components/web_modal/web_contents_modal_dialog_manager.h" 22 #include "components/web_modal/web_contents_modal_dialog_manager.h"
22 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "content/public/common/content_switches.h" 25 #include "content/public/common/content_switches.h"
25 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
26 #include "services/service_manager/public/cpp/interface_registry.h" 27 #include "services/service_manager/public/cpp/interface_registry.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/base/test/ui_controls.h" 29 #include "ui/base/test/ui_controls.h"
30 #include "ui/gfx/animation/test_animation_delegate.h"
29 #include "ui/views/controls/styled_label.h" 31 #include "ui/views/controls/styled_label.h"
30 32
31 namespace payments { 33 namespace payments {
32 34
33 PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase( 35 PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase(
34 const std::string& test_file_path) 36 const std::string& test_file_path)
35 : test_file_path_(test_file_path), 37 : test_file_path_(test_file_path),
36 delegate_(nullptr) {} 38 delegate_(nullptr) {}
37 PaymentRequestInteractiveTestBase::~PaymentRequestInteractiveTestBase() {} 39 PaymentRequestInteractiveTestBase::~PaymentRequestInteractiveTestBase() {}
38 40
(...skipping 28 matching lines...) Expand all
67 void PaymentRequestInteractiveTestBase::OnDialogOpened() { 69 void PaymentRequestInteractiveTestBase::OnDialogOpened() {
68 if (event_observer_) 70 if (event_observer_)
69 event_observer_->Observe(DialogEvent::DIALOG_OPENED); 71 event_observer_->Observe(DialogEvent::DIALOG_OPENED);
70 } 72 }
71 73
72 void PaymentRequestInteractiveTestBase::OnOrderSummaryOpened() { 74 void PaymentRequestInteractiveTestBase::OnOrderSummaryOpened() {
73 if (event_observer_) 75 if (event_observer_)
74 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); 76 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED);
75 } 77 }
76 78
79 void PaymentRequestInteractiveTestBase::OnPaymentMethodOpened() {
80 if (event_observer_)
81 event_observer_->Observe(DialogEvent::PAYMENT_METHOD_OPENED);
82 }
83
84 void PaymentRequestInteractiveTestBase::OnCreditCardEditorOpened() {
85 if (event_observer_)
86 event_observer_->Observe(DialogEvent::CREDIT_CARD_EDITOR_OPENED);
87 }
88
89 void PaymentRequestInteractiveTestBase::OnBackNavigation() {
90 if (event_observer_)
91 event_observer_->Observe(DialogEvent::BACK_NAVIGATION);
92 }
93
77 void PaymentRequestInteractiveTestBase::OnWidgetDestroyed( 94 void PaymentRequestInteractiveTestBase::OnWidgetDestroyed(
78 views::Widget* widget) { 95 views::Widget* widget) {
79 if (event_observer_) 96 if (event_observer_)
80 event_observer_->Observe(DialogEvent::DIALOG_CLOSED); 97 event_observer_->Observe(DialogEvent::DIALOG_CLOSED);
81 } 98 }
82 99
83 void PaymentRequestInteractiveTestBase::InvokePaymentRequestUI() { 100 void PaymentRequestInteractiveTestBase::InvokePaymentRequestUI() {
84 ResetEventObserver(DialogEvent::DIALOG_OPENED); 101 ResetEventObserver(DialogEvent::DIALOG_OPENED);
85 102
86 content::WebContents* web_contents = GetActiveWebContents(); 103 content::WebContents* web_contents = GetActiveWebContents();
87 const std::string click_buy_button_js = 104 const std::string click_buy_button_js =
88 "(function() { document.getElementById('buy').click(); })();"; 105 "(function() { document.getElementById('buy').click(); })();";
89 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); 106 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js));
90 107
91 WaitForObservedEvent(); 108 WaitForObservedEvent();
92 109
93 // The web-modal dialog should be open. 110 // The web-modal dialog should be open.
94 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = 111 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager =
95 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); 112 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents);
96 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); 113 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
97 } 114 }
98 115
99 void PaymentRequestInteractiveTestBase::OpenOrderSummaryScreen() { 116 void PaymentRequestInteractiveTestBase::OpenOrderSummaryScreen() {
100 ResetEventObserver(DialogEvent::ORDER_SUMMARY_OPENED); 117 ResetEventObserver(DialogEvent::ORDER_SUMMARY_OPENED);
101 118
102 ClickOnDialogView(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION); 119 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION);
120 }
103 121
104 WaitForObservedEvent(); 122 void PaymentRequestInteractiveTestBase::OpenPaymentMethodScreen() {
123 ResetEventObserver(DialogEvent::PAYMENT_METHOD_OPENED);
124
125 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION);
126 }
127
128 void PaymentRequestInteractiveTestBase::OpenCreditCardEditorScreen() {
129 ResetEventObserver(DialogEvent::CREDIT_CARD_EDITOR_OPENED);
130
131 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON);
105 } 132 }
106 133
107 content::WebContents* 134 content::WebContents*
108 PaymentRequestInteractiveTestBase::GetActiveWebContents() { 135 PaymentRequestInteractiveTestBase::GetActiveWebContents() {
109 return browser()->tab_strip_model()->GetActiveWebContents(); 136 return browser()->tab_strip_model()->GetActiveWebContents();
110 } 137 }
111 138
112 const std::vector<PaymentRequest*> 139 const std::vector<PaymentRequest*>
113 PaymentRequestInteractiveTestBase::GetPaymentRequests( 140 PaymentRequestInteractiveTestBase::GetPaymentRequests(
114 content::WebContents* web_contents) { 141 content::WebContents* web_contents) {
(...skipping 14 matching lines...) Expand all
129 DCHECK(web_contents); 156 DCHECK(web_contents);
130 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = 157 std::unique_ptr<TestChromePaymentRequestDelegate> delegate =
131 base::MakeUnique<TestChromePaymentRequestDelegate>( 158 base::MakeUnique<TestChromePaymentRequestDelegate>(
132 web_contents, this /* observer */, this /* widget_observer */); 159 web_contents, this /* observer */, this /* widget_observer */);
133 delegate_ = delegate.get(); 160 delegate_ = delegate.get();
134 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) 161 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents)
135 ->CreatePaymentRequest(web_contents, std::move(delegate), 162 ->CreatePaymentRequest(web_contents, std::move(delegate),
136 std::move(request)); 163 std::move(request));
137 } 164 }
138 165
139 void PaymentRequestInteractiveTestBase::ClickOnDialogView( 166 void PaymentRequestInteractiveTestBase::ClickOnDialogViewAndWait(
140 DialogViewID view_id) { 167 DialogViewID view_id) {
141 views::View* view = 168 views::View* view =
142 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id)); 169 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id));
143 DCHECK(view); 170 DCHECK(view);
144 base::RunLoop run_loop; 171 base::RunLoop run_loop;
145 ui_test_utils::MoveMouseToCenterAndPress( 172 ui_test_utils::MoveMouseToCenterAndPress(
146 view, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, 173 view, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
147 run_loop.QuitClosure()); 174 run_loop.QuitClosure());
148 run_loop.Run(); 175 run_loop.Run();
176
177 WaitForAnimation();
178
179 WaitForObservedEvent();
180 }
181
182 void PaymentRequestInteractiveTestBase::WaitForAnimation() {
183 ViewStack* view_stack = dialog_view()->view_stack_for_testing();
184 if (view_stack->slide_in_animator_->IsAnimating()) {
185 view_stack->slide_in_animator_->SetAnimationDuration(1);
186 view_stack->slide_in_animator_->SetAnimationDelegate(
187 view_stack->top(), std::unique_ptr<gfx::AnimationDelegate>(
188 new gfx::TestAnimationDelegate()));
189 base::RunLoop().Run();
190 } else if (view_stack->slide_out_animator_->IsAnimating()) {
191 view_stack->slide_out_animator_->SetAnimationDuration(1);
192 view_stack->slide_out_animator_->SetAnimationDelegate(
193 view_stack->top(), std::unique_ptr<gfx::AnimationDelegate>(
194 new gfx::TestAnimationDelegate()));
195 base::RunLoop().Run();
196 }
149 } 197 }
150 198
151 const base::string16& PaymentRequestInteractiveTestBase::GetStyledLabelText( 199 const base::string16& PaymentRequestInteractiveTestBase::GetStyledLabelText(
152 DialogViewID view_id) { 200 DialogViewID view_id) {
153 views::View* view = dialog_view()->GetViewByID(static_cast<int>(view_id)); 201 views::View* view = dialog_view()->GetViewByID(static_cast<int>(view_id));
154 DCHECK(view); 202 DCHECK(view);
155 return static_cast<views::StyledLabel*>(view)->text(); 203 return static_cast<views::StyledLabel*>(view)->text();
156 } 204 }
157 205
158 PaymentRequestInteractiveTestBase::DialogEventObserver::DialogEventObserver( 206 PaymentRequestInteractiveTestBase::DialogEventObserver::DialogEventObserver(
(...skipping 23 matching lines...) Expand all
182 230
183 void PaymentRequestInteractiveTestBase::ResetEventObserver(DialogEvent event) { 231 void PaymentRequestInteractiveTestBase::ResetEventObserver(DialogEvent event) {
184 event_observer_ = base::MakeUnique<DialogEventObserver>(event); 232 event_observer_ = base::MakeUnique<DialogEventObserver>(event);
185 } 233 }
186 234
187 void PaymentRequestInteractiveTestBase::WaitForObservedEvent() { 235 void PaymentRequestInteractiveTestBase::WaitForObservedEvent() {
188 event_observer_->Wait(); 236 event_observer_->Wait();
189 } 237 }
190 238
191 } // namespace payments 239 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698