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

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

Issue 2789093002: [Payments] Desktop: implement shipping address/option change (Closed)
Patch Set: compile fix Created 3 years, 8 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_browsertest_base.h" 5 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 void PaymentRequestBrowserTestBase::OnEditorViewUpdated() { 139 void PaymentRequestBrowserTestBase::OnEditorViewUpdated() {
140 if (event_observer_) 140 if (event_observer_)
141 event_observer_->Observe(DialogEvent::EDITOR_VIEW_UPDATED); 141 event_observer_->Observe(DialogEvent::EDITOR_VIEW_UPDATED);
142 } 142 }
143 143
144 void PaymentRequestBrowserTestBase::OnErrorMessageShown() { 144 void PaymentRequestBrowserTestBase::OnErrorMessageShown() {
145 if (event_observer_) 145 if (event_observer_)
146 event_observer_->Observe(DialogEvent::ERROR_MESSAGE_SHOWN); 146 event_observer_->Observe(DialogEvent::ERROR_MESSAGE_SHOWN);
147 } 147 }
148 148
149 void PaymentRequestBrowserTestBase::OnSpecDoneUpdating() {
150 if (event_observer_)
151 event_observer_->Observe(DialogEvent::SPEC_DONE_UPDATING);
152 }
153
149 void PaymentRequestBrowserTestBase::OnWidgetDestroyed(views::Widget* widget) { 154 void PaymentRequestBrowserTestBase::OnWidgetDestroyed(views::Widget* widget) {
150 if (event_observer_) 155 if (event_observer_)
151 event_observer_->Observe(DialogEvent::DIALOG_CLOSED); 156 event_observer_->Observe(DialogEvent::DIALOG_CLOSED);
152 } 157 }
153 158
154 void PaymentRequestBrowserTestBase::InvokePaymentRequestUI() { 159 void PaymentRequestBrowserTestBase::InvokePaymentRequestUI() {
155 ResetEventObserver(DialogEvent::DIALOG_OPENED); 160 ResetEventObserver(DialogEvent::DIALOG_OPENED);
156 161
157 content::WebContents* web_contents = GetActiveWebContents(); 162 content::WebContents* web_contents = GetActiveWebContents();
158 const std::string click_buy_button_js = 163 const std::string click_buy_button_js =
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 212
208 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON); 213 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON);
209 } 214 }
210 215
211 void PaymentRequestBrowserTestBase::OpenShippingAddressEditorScreen() { 216 void PaymentRequestBrowserTestBase::OpenShippingAddressEditorScreen() {
212 ResetEventObserver(DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED); 217 ResetEventObserver(DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED);
213 218
214 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON); 219 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON);
215 } 220 }
216 221
222 void PaymentRequestBrowserTestBase::ClickOnBackArrow() {
223 ResetEventObserver(DialogEvent::BACK_NAVIGATION);
224
225 ClickOnDialogViewAndWait(DialogViewID::BACK_BUTTON);
226 }
227
217 content::WebContents* PaymentRequestBrowserTestBase::GetActiveWebContents() { 228 content::WebContents* PaymentRequestBrowserTestBase::GetActiveWebContents() {
218 return browser()->tab_strip_model()->GetActiveWebContents(); 229 return browser()->tab_strip_model()->GetActiveWebContents();
219 } 230 }
220 231
221 const std::vector<PaymentRequest*> 232 const std::vector<PaymentRequest*>
222 PaymentRequestBrowserTestBase::GetPaymentRequests( 233 PaymentRequestBrowserTestBase::GetPaymentRequests(
223 content::WebContents* web_contents) { 234 content::WebContents* web_contents) {
224 PaymentRequestWebContentsManager* manager = 235 PaymentRequestWebContentsManager* manager =
225 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents); 236 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents);
226 if (!manager) 237 if (!manager)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), 317 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
307 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 318 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
308 view->OnMouseReleased(released_event); 319 view->OnMouseReleased(released_event);
309 320
310 if (wait_for_animation) 321 if (wait_for_animation)
311 WaitForAnimation(); 322 WaitForAnimation();
312 323
313 WaitForObservedEvent(); 324 WaitForObservedEvent();
314 } 325 }
315 326
327 void PaymentRequestBrowserTestBase::ClickOnChildInListViewAndWait(
328 int child_index,
329 int total_num_children,
330 DialogViewID list_view_id) {
331 views::View* list_view =
332 dialog_view()->GetViewByID(static_cast<int>(list_view_id));
333 EXPECT_TRUE(list_view);
334 EXPECT_EQ(total_num_children, list_view->child_count());
335 ClickOnDialogViewAndWait(list_view->child_at(child_index));
336 }
337
338 std::vector<base::string16>
339 PaymentRequestBrowserTestBase::GetThreeLineLabelValues(
340 DialogViewID parent_view_id) {
341 std::vector<base::string16> line_labels;
342 views::View* parent_view =
343 dialog_view()->GetViewByID(static_cast<int>(parent_view_id));
344 EXPECT_TRUE(parent_view);
345
346 views::View* view = parent_view->GetViewByID(
347 static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_1));
348 if (view)
349 line_labels.push_back(static_cast<views::Label*>(view)->text());
350 view = parent_view->GetViewByID(
351 static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_2));
352 if (view)
353 line_labels.push_back(static_cast<views::Label*>(view)->text());
354 view = parent_view->GetViewByID(
355 static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_3));
356 if (view)
357 line_labels.push_back(static_cast<views::Label*>(view)->text());
358
359 return line_labels;
360 }
361
362 std::vector<base::string16>
363 PaymentRequestBrowserTestBase::GetShippingOptionLabelValues(
364 DialogViewID parent_view_id) {
365 std::vector<base::string16> labels;
366 views::View* parent_view =
367 dialog_view()->GetViewByID(static_cast<int>(parent_view_id));
368 EXPECT_TRUE(parent_view);
369
370 views::View* view = parent_view->GetViewByID(
371 static_cast<int>(DialogViewID::SHIPPING_OPTION_DESCRIPTION));
372 DCHECK(view);
373 labels.push_back(static_cast<views::Label*>(view)->text());
374 view = parent_view->GetViewByID(
375 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT));
376 DCHECK(view);
377 labels.push_back(static_cast<views::Label*>(view)->text());
378 return labels;
379 }
380
316 void PaymentRequestBrowserTestBase::SetEditorTextfieldValue( 381 void PaymentRequestBrowserTestBase::SetEditorTextfieldValue(
317 const base::string16& value, 382 const base::string16& value,
318 autofill::ServerFieldType type) { 383 autofill::ServerFieldType type) {
319 ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>( 384 ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>(
320 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); 385 delegate_->dialog_view()->GetViewByID(static_cast<int>(type)));
321 DCHECK(textfield); 386 DCHECK(textfield);
322 textfield->SetText(value); 387 textfield->SetText(value);
323 textfield->OnContentsChanged(); 388 textfield->OnContentsChanged();
324 textfield->OnBlur(); 389 textfield->OnBlur();
325 } 390 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 450
386 const base::string16& PaymentRequestBrowserTestBase::GetErrorLabelForType( 451 const base::string16& PaymentRequestBrowserTestBase::GetErrorLabelForType(
387 autofill::ServerFieldType type) { 452 autofill::ServerFieldType type) {
388 views::View* view = dialog_view()->GetViewByID( 453 views::View* view = dialog_view()->GetViewByID(
389 static_cast<int>(DialogViewID::ERROR_LABEL_OFFSET) + type); 454 static_cast<int>(DialogViewID::ERROR_LABEL_OFFSET) + type);
390 DCHECK(view); 455 DCHECK(view);
391 return static_cast<views::Label*>(view)->text(); 456 return static_cast<views::Label*>(view)->text();
392 } 457 }
393 458
394 PaymentRequestBrowserTestBase::DialogEventObserver::DialogEventObserver( 459 PaymentRequestBrowserTestBase::DialogEventObserver::DialogEventObserver(
395 PaymentRequestBrowserTestBase::DialogEvent event) 460 std::list<PaymentRequestBrowserTestBase::DialogEvent> event_sequence)
396 : event_(event), seen_(false) {} 461 : events_(std::move(event_sequence)) {}
397 PaymentRequestBrowserTestBase::DialogEventObserver::~DialogEventObserver() {} 462 PaymentRequestBrowserTestBase::DialogEventObserver::~DialogEventObserver() {}
398 463
399 void PaymentRequestBrowserTestBase::DialogEventObserver::Wait() { 464 void PaymentRequestBrowserTestBase::DialogEventObserver::Wait() {
400 if (seen_) 465 if (events_.empty())
401 return; 466 return;
402 467
403 DCHECK(!run_loop_.running()); 468 DCHECK(!run_loop_.running());
404 run_loop_.Run(); 469 run_loop_.Run();
405 } 470 }
406 471
407 void PaymentRequestBrowserTestBase::DialogEventObserver::Observe( 472 void PaymentRequestBrowserTestBase::DialogEventObserver::Observe(
408 PaymentRequestBrowserTestBase::DialogEvent event) { 473 PaymentRequestBrowserTestBase::DialogEvent event) {
409 if (seen_) 474 if (events_.empty())
410 return; 475 return;
411 476
412 DCHECK_EQ(event_, event); 477 DCHECK_EQ(events_.front(), event);
413 seen_ = true; 478 events_.pop_front();
414 if (run_loop_.running()) 479 // Only quit the loop if no other events are expected.
480 if (events_.empty() && run_loop_.running())
415 run_loop_.Quit(); 481 run_loop_.Quit();
416 } 482 }
417 483
418 void PaymentRequestBrowserTestBase::ResetEventObserver(DialogEvent event) { 484 void PaymentRequestBrowserTestBase::ResetEventObserver(DialogEvent event) {
419 event_observer_ = base::MakeUnique<DialogEventObserver>(event); 485 event_observer_ =
486 base::MakeUnique<DialogEventObserver>(std::list<DialogEvent>{event});
487 }
488
489 void PaymentRequestBrowserTestBase::ResetEventObserverForSequence(
490 std::list<DialogEvent> event_sequence) {
491 event_observer_ =
492 base::MakeUnique<DialogEventObserver>(std::move(event_sequence));
420 } 493 }
421 494
422 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { 495 void PaymentRequestBrowserTestBase::WaitForObservedEvent() {
423 event_observer_->Wait(); 496 event_observer_->Wait();
424 } 497 }
425 498
426 } // namespace payments 499 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698