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

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

Issue 2734693002: [Payments] Convert interactive tests to browsertests (Closed)
Patch Set: Initial 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
(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 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_BASE _H_
6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_BASE _H_
7
8 #include <vector>
9
10 #include "base/command_line.h"
11 #include "base/macros.h"
12 #include "base/run_loop.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
15 #include "chrome/browser/ui/views/payments/test_chrome_payment_request_delegate. h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "components/autofill/core/browser/field_types.h"
18 #include "components/autofill/core/browser/personal_data_manager_observer.h"
19 #include "components/payments/content/payment_request.mojom.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "ui/views/widget/widget_observer.h"
23
24 namespace autofill {
25 class AutofillProfile;
26 class CreditCard;
27 }
28
29 namespace content {
30 class WebContents;
31 } // namespace content
32
33 namespace views {
34 class Widget;
35 }
36
37 namespace payments {
38
39 enum class DialogViewID;
40 class PaymentRequest;
41
42 namespace {
43
44 ACTION_P(QuitMessageLoop, loop) {
45 loop->Quit();
46 }
47
48 } // namespace
49
50 class PersonalDataLoadedObserverMock
51 : public autofill::PersonalDataManagerObserver {
52 public:
53 PersonalDataLoadedObserverMock();
54 ~PersonalDataLoadedObserverMock() override;
55
56 MOCK_METHOD0(OnPersonalDataChanged, void());
57 };
58
59 // Base class for any interactive PaymentRequest test that will need to open
60 // the UI and interact with it.
61 class PaymentRequestInteractiveTestBase
62 : public InProcessBrowserTest,
63 public PaymentRequestDialogView::ObserverForTest,
64 public views::WidgetObserver {
65 protected:
66 // Test will open a browser window to |test_file_path| (relative to
67 // chrome/test/data/payments).
68 explicit PaymentRequestInteractiveTestBase(const std::string& test_file_path);
69 ~PaymentRequestInteractiveTestBase() override;
70
71 void SetUpCommandLine(base::CommandLine* command_line) override;
72 void SetUpOnMainThread() override;
73
74 // PaymentRequestDialogView::ObserverForTest
75 void OnDialogOpened() override;
76 void OnOrderSummaryOpened() override;
77 void OnPaymentMethodOpened() override;
78 void OnCreditCardEditorOpened() override;
79 void OnBackNavigation() override;
80 void OnContactInfoOpened() override;
81
82 // views::WidgetObserver
83 // Effective way to be warned of all dialog closures.
84 void OnWidgetDestroyed(views::Widget* widget) override;
85
86 // Will call JavaScript to invoke the PaymentRequest dialog and verify that
87 // it's open.
88 void InvokePaymentRequestUI();
89
90 // Utility functions that will click on Dialog views and wait for the
91 // associated action to happen.
92 void OpenOrderSummaryScreen();
93 void OpenPaymentMethodScreen();
94 void OpenCreditCardEditorScreen();
95
96 content::WebContents* GetActiveWebContents();
97
98 // Convenience method to get a list of PaymentRequest associated with
99 // |web_contents|.
100 const std::vector<PaymentRequest*> GetPaymentRequests(
101 content::WebContents* web_contents);
102
103 autofill::PersonalDataManager* GetDataManager();
104 // Adds the various models to the database, waiting until the personal data
105 // manager notifies that they are added.
106 // NOTE: If no use_count is specified on the models and multiple items are
107 // inserted, the order in which they are returned is undefined, since they
108 // are added close to each other.
109 void AddAutofillProfile(const autofill::AutofillProfile& profile);
110 void AddCreditCard(const autofill::CreditCard& card);
111
112 void CreatePaymentRequestForTest(
113 content::WebContents* web_contents,
114 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request);
115
116 // Click on a view from within the dialog and waits for an observed event
117 // to be observed.
118 void ClickOnDialogViewAndWait(DialogViewID view_id);
119 void ClickOnDialogViewAndWait(views::View* view);
120
121 // Setting the |value| in the textfield of a given |type|.
122 void SetEditorTextfieldValue(const base::string16& value,
123 autofill::ServerFieldType type);
124 // Setting the |value| in the combobox of a given |type|.
125 void SetComboboxValue(const base::string16& value,
126 autofill::ServerFieldType type);
127
128 // Whether the editor textfield/combobox for the given |type| is currently in
129 // an invalid state.
130 bool IsEditorTextfieldInvalid(autofill::ServerFieldType type);
131 bool IsEditorComboboxInvalid(autofill::ServerFieldType type);
132
133 bool IsPayButtonEnabled();
134
135 // Sets proper animation delegates and waits for animation to finish.
136 void WaitForAnimation();
137
138 // Returns the text of the StyledLabel with the specific |view_id| that is a
139 // child of the Payment Request dialog view.
140 const base::string16& GetStyledLabelText(DialogViewID view_id);
141 // Returns the error label text associated with a given field |type|.
142 const base::string16& GetErrorLabelForType(autofill::ServerFieldType type);
143
144 net::EmbeddedTestServer* https_server() { return https_server_.get(); }
145
146 PaymentRequestDialogView* dialog_view() { return delegate_->dialog_view(); }
147
148 // Various events that can be waited on by the DialogEventObserver.
149 enum DialogEvent : int {
150 DIALOG_OPENED,
151 DIALOG_CLOSED,
152 ORDER_SUMMARY_OPENED,
153 PAYMENT_METHOD_OPENED,
154 CREDIT_CARD_EDITOR_OPENED,
155 BACK_NAVIGATION,
156 CONTACT_INFO_OPENED,
157 };
158
159 // DialogEventObserver is used to wait on specific events that may have
160 // occured before the call to Wait(), or after, in which case a RunLoop is
161 // used.
162 //
163 // Usage:
164 // observer_.reset(new DialogEventObserver([DialogEvent]));
165 //
166 // Do stuff, which (a)synchronously calls observer_->Observe([DialogEvent]).
167 //
168 // observer_->Wait(); <- Will either return right away if event was observed,
169 // <- or use a RunLoop's Run/Quit to wait for the event.
170 class DialogEventObserver {
171 public:
172 explicit DialogEventObserver(DialogEvent event);
173 ~DialogEventObserver();
174
175 // Either returns right away if the event was observed between this object's
176 // construction and this call to Wait(), or use a RunLoop to wait for it.
177 void Wait();
178
179 // Observes the event (quits the RunLoop if it was running).
180 void Observe(DialogEvent event);
181
182 private:
183 DialogEvent event_;
184 bool seen_;
185 base::RunLoop run_loop_;
186
187 DISALLOW_COPY_AND_ASSIGN(DialogEventObserver);
188 };
189
190 // Resets the event observer for a given |event|.
191 void ResetEventObserver(DialogEvent event);
192 // Wait for the event passed to ResetEventObserver() to occur.
193 void WaitForObservedEvent();
194
195 private:
196 std::unique_ptr<DialogEventObserver> event_observer_;
197 const std::string test_file_path_;
198 std::unique_ptr<net::EmbeddedTestServer> https_server_;
199 // Weak, owned by the PaymentRequest object.
200 TestChromePaymentRequestDelegate* delegate_;
201
202 DISALLOW_COPY_AND_ASSIGN(PaymentRequestInteractiveTestBase);
203 };
204
205 } // namespace payments
206
207 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_INTERACTIVE_UITEST_B ASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698