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

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

Issue 2631133003: [Payments] Introduce basic interactive browsertests for Payment Request (Closed)
Patch Set: ObserverForTest Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_dialog.h" 5 #include "chrome/browser/ui/views/payments/payment_request_dialog.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" 11 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h"
12 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" 12 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h"
13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" 13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
14 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
15 #include "components/constrained_window/constrained_window_views.h" 15 #include "components/constrained_window/constrained_window_views.h"
16 #include "components/payments/payment_request.h" 16 #include "components/payments/payment_request.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/views/layout/fill_layout.h" 19 #include "ui/views/layout/fill_layout.h"
20 20
21 namespace chrome { 21 namespace chrome {
22 22
23 void ShowPaymentRequestDialog(payments::PaymentRequest* request) { 23 void ShowPaymentRequestDialog(payments::PaymentRequest* request) {
24 constrained_window::ShowWebModalDialogViews( 24 payments::PaymentRequestDialog::ShowWebModalPaymentDialog(
25 new payments::PaymentRequestDialog(request), request->web_contents()); 25 new payments::PaymentRequestDialog(request, /* no observer */ nullptr),
26 request);
26 } 27 }
27 28
28 } // namespace chrome 29 } // namespace chrome
29 30
30 namespace payments { 31 namespace payments {
31 namespace { 32 namespace {
32 33
33 // This function creates an instance of a PaymentRequestSheetController 34 // This function creates an instance of a PaymentRequestSheetController
34 // subclass of concrete type |Controller|, passing it non-owned pointers to 35 // subclass of concrete type |Controller|, passing it non-owned pointers to
35 // |dialog| and the |request| that initiated that dialog. |map| should be owned 36 // |dialog| and the |request| that initiated that dialog. |map| should be owned
36 // by |dialog|. 37 // by |dialog|.
37 template <typename Controller> 38 template <typename Controller>
38 std::unique_ptr<views::View> CreateViewAndInstallController( 39 std::unique_ptr<views::View> CreateViewAndInstallController(
39 payments::ControllerMap* map, 40 payments::ControllerMap* map,
40 payments::PaymentRequest* request, 41 payments::PaymentRequest* request,
41 payments::PaymentRequestDialog* dialog) { 42 payments::PaymentRequestDialog* dialog) {
42 std::unique_ptr<Controller> controller = 43 std::unique_ptr<Controller> controller =
43 base::MakeUnique<Controller>(request, dialog); 44 base::MakeUnique<Controller>(request, dialog);
44 std::unique_ptr<views::View> view = controller->CreateView(); 45 std::unique_ptr<views::View> view = controller->CreateView();
45 (*map)[view.get()] = std::move(controller); 46 (*map)[view.get()] = std::move(controller);
46 return view; 47 return view;
47 } 48 }
48 49
49 } // namespace 50 } // namespace
50 51
51 PaymentRequestDialog::PaymentRequestDialog(PaymentRequest* request) 52 PaymentRequestDialog::PaymentRequestDialog(
52 : request_(request) { 53 PaymentRequest* request,
54 PaymentRequestDialog::ObserverForTest* observer)
55 : request_(request), observer_(observer) {
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
54 SetLayoutManager(new views::FillLayout()); 57 SetLayoutManager(new views::FillLayout());
55 58
56 view_stack_.set_owned_by_client(); 59 view_stack_.set_owned_by_client();
57 AddChildView(&view_stack_); 60 AddChildView(&view_stack_);
58 61
59 ShowInitialPaymentSheet(); 62 ShowInitialPaymentSheet();
60 } 63 }
61 64
62 PaymentRequestDialog::~PaymentRequestDialog() {} 65 PaymentRequestDialog::~PaymentRequestDialog() {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 view_stack_.Push( 105 view_stack_.Push(
103 CreateViewAndInstallController<PaymentMethodViewController>( 106 CreateViewAndInstallController<PaymentMethodViewController>(
104 &controller_map_, request_, this), 107 &controller_map_, request_, this),
105 true); 108 true);
106 } 109 }
107 110
108 void PaymentRequestDialog::CloseDialog() { 111 void PaymentRequestDialog::CloseDialog() {
109 GetWidget()->Close(); 112 GetWidget()->Close();
110 } 113 }
111 114
115 // static
116 void PaymentRequestDialog::ShowWebModalPaymentDialog(
117 PaymentRequestDialog* dialog,
118 PaymentRequest* request) {
119 constrained_window::ShowWebModalDialogViews(dialog, request->web_contents());
120 }
121
112 void PaymentRequestDialog::ShowInitialPaymentSheet() { 122 void PaymentRequestDialog::ShowInitialPaymentSheet() {
113 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>( 123 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>(
114 &controller_map_, request_, this), 124 &controller_map_, request_, this),
115 false); 125 false);
126 if (observer_)
127 observer_->OnDialogOpened();
116 } 128 }
117 129
118 gfx::Size PaymentRequestDialog::GetPreferredSize() const { 130 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
119 return gfx::Size(450, 450); 131 return gfx::Size(450, 450);
120 } 132 }
121 133
122 void PaymentRequestDialog::ViewHierarchyChanged( 134 void PaymentRequestDialog::ViewHierarchyChanged(
123 const ViewHierarchyChangedDetails& details) { 135 const ViewHierarchyChangedDetails& details) {
124 // When a view that is associated with a controller is removed from this 136 // When a view that is associated with a controller is removed from this
125 // view's descendants, dispose of the controller. 137 // view's descendants, dispose of the controller.
126 if (!details.is_add && 138 if (!details.is_add &&
127 controller_map_.find(details.child) != controller_map_.end()) { 139 controller_map_.find(details.child) != controller_map_.end()) {
128 DCHECK(!details.move_view); 140 DCHECK(!details.move_view);
129 controller_map_.erase(details.child); 141 controller_map_.erase(details.child);
130 } 142 }
131 } 143 }
132 144
133 } // namespace payments 145 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698