| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_BROWSERTEST_BASE_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_BROWSERTEST_BASE_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_BROWSERTEST_BASE_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_BROWSERTEST_BASE_H_ |
| 7 | 7 |
| 8 #include <list> |
| 8 #include <memory> | 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 17 #include "chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.
h" | 18 #include "chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.
h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 void OnDialogOpened() override; | 80 void OnDialogOpened() override; |
| 80 void OnOrderSummaryOpened() override; | 81 void OnOrderSummaryOpened() override; |
| 81 void OnPaymentMethodOpened() override; | 82 void OnPaymentMethodOpened() override; |
| 82 void OnShippingSectionOpened() override; | 83 void OnShippingSectionOpened() override; |
| 83 void OnCreditCardEditorOpened() override; | 84 void OnCreditCardEditorOpened() override; |
| 84 void OnShippingAddressEditorOpened() override; | 85 void OnShippingAddressEditorOpened() override; |
| 85 void OnBackNavigation() override; | 86 void OnBackNavigation() override; |
| 86 void OnContactInfoOpened() override; | 87 void OnContactInfoOpened() override; |
| 87 void OnEditorViewUpdated() override; | 88 void OnEditorViewUpdated() override; |
| 88 void OnErrorMessageShown() override; | 89 void OnErrorMessageShown() override; |
| 90 void OnSpecDoneUpdating() override; |
| 89 | 91 |
| 90 // views::WidgetObserver | 92 // views::WidgetObserver |
| 91 // Effective way to be warned of all dialog closures. | 93 // Effective way to be warned of all dialog closures. |
| 92 void OnWidgetDestroyed(views::Widget* widget) override; | 94 void OnWidgetDestroyed(views::Widget* widget) override; |
| 93 | 95 |
| 94 // Will call JavaScript to invoke the PaymentRequest dialog and verify that | 96 // Will call JavaScript to invoke the PaymentRequest dialog and verify that |
| 95 // it's open. | 97 // it's open. |
| 96 void InvokePaymentRequestUI(); | 98 void InvokePaymentRequestUI(); |
| 97 | 99 |
| 98 // Will expect that all strings in |expected_strings| are present in output. | 100 // Will expect that all strings in |expected_strings| are present in output. |
| 99 void ExpectBodyContains(const std::vector<base::string16>& expected_strings); | 101 void ExpectBodyContains(const std::vector<base::string16>& expected_strings); |
| 100 | 102 |
| 101 // Utility functions that will click on Dialog views and wait for the | 103 // Utility functions that will click on Dialog views and wait for the |
| 102 // associated action to happen. | 104 // associated action to happen. |
| 103 void OpenOrderSummaryScreen(); | 105 void OpenOrderSummaryScreen(); |
| 104 void OpenPaymentMethodScreen(); | 106 void OpenPaymentMethodScreen(); |
| 105 void OpenShippingSectionScreen(); | 107 void OpenShippingSectionScreen(); |
| 106 void OpenCreditCardEditorScreen(); | 108 void OpenCreditCardEditorScreen(); |
| 107 void OpenShippingAddressEditorScreen(); | 109 void OpenShippingAddressEditorScreen(); |
| 110 void ClickOnBackArrow(); |
| 108 | 111 |
| 109 content::WebContents* GetActiveWebContents(); | 112 content::WebContents* GetActiveWebContents(); |
| 110 | 113 |
| 111 // Convenience method to get a list of PaymentRequest associated with | 114 // Convenience method to get a list of PaymentRequest associated with |
| 112 // |web_contents|. | 115 // |web_contents|. |
| 113 const std::vector<PaymentRequest*> GetPaymentRequests( | 116 const std::vector<PaymentRequest*> GetPaymentRequests( |
| 114 content::WebContents* web_contents); | 117 content::WebContents* web_contents); |
| 115 | 118 |
| 116 autofill::PersonalDataManager* GetDataManager(); | 119 autofill::PersonalDataManager* GetDataManager(); |
| 117 // Adds the various models to the database, waiting until the personal data | 120 // Adds the various models to the database, waiting until the personal data |
| 118 // manager notifies that they are added. | 121 // manager notifies that they are added. |
| 119 // NOTE: If no use_count is specified on the models and multiple items are | 122 // NOTE: If no use_count is specified on the models and multiple items are |
| 120 // inserted, the order in which they are returned is undefined, since they | 123 // inserted, the order in which they are returned is undefined, since they |
| 121 // are added close to each other. | 124 // are added close to each other. |
| 122 void AddAutofillProfile(const autofill::AutofillProfile& profile); | 125 void AddAutofillProfile(const autofill::AutofillProfile& profile); |
| 123 void AddCreditCard(const autofill::CreditCard& card); | 126 void AddCreditCard(const autofill::CreditCard& card); |
| 124 | 127 |
| 125 void CreatePaymentRequestForTest( | 128 void CreatePaymentRequestForTest( |
| 126 content::WebContents* web_contents, | 129 content::WebContents* web_contents, |
| 127 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request); | 130 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request); |
| 128 | 131 |
| 129 // Click on a view from within the dialog and waits for an observed event | 132 // Click on a view from within the dialog and waits for an observed event |
| 130 // to be observed. | 133 // to be observed. |
| 131 void ClickOnDialogViewAndWait(DialogViewID view_id, | 134 void ClickOnDialogViewAndWait(DialogViewID view_id, |
| 132 bool wait_for_animation = true); | 135 bool wait_for_animation = true); |
| 133 void ClickOnDialogViewAndWait(views::View* view, | 136 void ClickOnDialogViewAndWait(views::View* view, |
| 134 bool wait_for_animation = true); | 137 bool wait_for_animation = true); |
| 138 void ClickOnChildInListViewAndWait(int child_index, |
| 139 int total_num_children, |
| 140 DialogViewID list_view_id); |
| 141 // Returns "three-line label" values under |parent_view|. |
| 142 std::vector<base::string16> GetThreeLineLabelValues( |
| 143 DialogViewID parent_view_id); |
| 144 // Returns the shipping option labels under |parent_view_id|. |
| 145 std::vector<base::string16> GetShippingOptionLabelValues( |
| 146 DialogViewID parent_view_id); |
| 135 | 147 |
| 136 // Setting the |value| in the textfield of a given |type|. | 148 // Setting the |value| in the textfield of a given |type|. |
| 137 void SetEditorTextfieldValue(const base::string16& value, | 149 void SetEditorTextfieldValue(const base::string16& value, |
| 138 autofill::ServerFieldType type); | 150 autofill::ServerFieldType type); |
| 139 // Setting the |value| in the combobox of a given |type|. | 151 // Setting the |value| in the combobox of a given |type|. |
| 140 void SetComboboxValue(const base::string16& value, | 152 void SetComboboxValue(const base::string16& value, |
| 141 autofill::ServerFieldType type); | 153 autofill::ServerFieldType type); |
| 142 | 154 |
| 143 // Whether the editor textfield/combobox for the given |type| is currently in | 155 // Whether the editor textfield/combobox for the given |type| is currently in |
| 144 // an invalid state. | 156 // an invalid state. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 167 ORDER_SUMMARY_OPENED, | 179 ORDER_SUMMARY_OPENED, |
| 168 PAYMENT_METHOD_OPENED, | 180 PAYMENT_METHOD_OPENED, |
| 169 SHIPPING_SECTION_OPENED, | 181 SHIPPING_SECTION_OPENED, |
| 170 CREDIT_CARD_EDITOR_OPENED, | 182 CREDIT_CARD_EDITOR_OPENED, |
| 171 SHIPPING_ADDRESS_EDITOR_OPENED, | 183 SHIPPING_ADDRESS_EDITOR_OPENED, |
| 172 BACK_NAVIGATION, | 184 BACK_NAVIGATION, |
| 173 CONTACT_INFO_OPENED, | 185 CONTACT_INFO_OPENED, |
| 174 EDITOR_VIEW_UPDATED, | 186 EDITOR_VIEW_UPDATED, |
| 175 CAN_MAKE_PAYMENT_CALLED, | 187 CAN_MAKE_PAYMENT_CALLED, |
| 176 ERROR_MESSAGE_SHOWN, | 188 ERROR_MESSAGE_SHOWN, |
| 189 SPEC_DONE_UPDATING, |
| 177 }; | 190 }; |
| 178 | 191 |
| 179 // DialogEventObserver is used to wait on specific events that may have | 192 // DialogEventObserver is used to wait on specific events that may have |
| 180 // occured before the call to Wait(), or after, in which case a RunLoop is | 193 // occured before the call to Wait(), or after, in which case a RunLoop is |
| 181 // used. | 194 // used. |
| 182 // | 195 // |
| 183 // Usage: | 196 // Usage: |
| 184 // observer_.reset(new DialogEventObserver([DialogEvent])); | 197 // observer_ = |
| 198 // base::MakeUnique<DialogEventObserver>(std:list<DialogEvent>(...)); |
| 185 // | 199 // |
| 186 // Do stuff, which (a)synchronously calls observer_->Observe([DialogEvent]). | 200 // Do stuff, which (a)synchronously calls observer_->Observe(...). |
| 187 // | 201 // |
| 188 // observer_->Wait(); <- Will either return right away if event was observed, | 202 // observer_->Wait(); <- Will either return right away if events were |
| 189 // <- or use a RunLoop's Run/Quit to wait for the event. | 203 // <- observed, or use a RunLoop's Run/Quit to wait. |
| 190 class DialogEventObserver { | 204 class DialogEventObserver { |
| 191 public: | 205 public: |
| 192 explicit DialogEventObserver(DialogEvent event); | 206 explicit DialogEventObserver(std::list<DialogEvent> event_sequence); |
| 193 ~DialogEventObserver(); | 207 ~DialogEventObserver(); |
| 194 | 208 |
| 195 // Either returns right away if the event was observed between this object's | 209 // Either returns right away if all events were observed between this |
| 196 // construction and this call to Wait(), or use a RunLoop to wait for it. | 210 // object's construction and this call to Wait(), or use a RunLoop to wait |
| 211 // for them. |
| 197 void Wait(); | 212 void Wait(); |
| 198 | 213 |
| 199 // Observes the event (quits the RunLoop if it was running). | 214 // Observes and event (quits the RunLoop if we are done waiting). |
| 200 void Observe(DialogEvent event); | 215 void Observe(DialogEvent event); |
| 201 | 216 |
| 202 private: | 217 private: |
| 203 DialogEvent event_; | 218 std::list<DialogEvent> events_; |
| 204 bool seen_; | |
| 205 base::RunLoop run_loop_; | 219 base::RunLoop run_loop_; |
| 206 | 220 |
| 207 DISALLOW_COPY_AND_ASSIGN(DialogEventObserver); | 221 DISALLOW_COPY_AND_ASSIGN(DialogEventObserver); |
| 208 }; | 222 }; |
| 209 | 223 |
| 210 // Resets the event observer for a given |event|. | 224 // Resets the event observer for a given |event| or |event_sequence|. |
| 211 void ResetEventObserver(DialogEvent event); | 225 void ResetEventObserver(DialogEvent event); |
| 212 // Wait for the event passed to ResetEventObserver() to occur. | 226 void ResetEventObserverForSequence(std::list<DialogEvent> event_sequence); |
| 227 // Wait for the event(s) passed to ResetEventObserver*() to occur. |
| 213 void WaitForObservedEvent(); | 228 void WaitForObservedEvent(); |
| 214 | 229 |
| 215 private: | 230 private: |
| 216 std::unique_ptr<DialogEventObserver> event_observer_; | 231 std::unique_ptr<DialogEventObserver> event_observer_; |
| 217 const std::string test_file_path_; | 232 const std::string test_file_path_; |
| 218 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 233 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
| 219 // Weak, owned by the PaymentRequest object. | 234 // Weak, owned by the PaymentRequest object. |
| 220 TestChromePaymentRequestDelegate* delegate_; | 235 TestChromePaymentRequestDelegate* delegate_; |
| 221 bool incognito_for_testing_; | 236 bool incognito_for_testing_; |
| 222 | 237 |
| 223 DISALLOW_COPY_AND_ASSIGN(PaymentRequestBrowserTestBase); | 238 DISALLOW_COPY_AND_ASSIGN(PaymentRequestBrowserTestBase); |
| 224 }; | 239 }; |
| 225 | 240 |
| 226 } // namespace payments | 241 } // namespace payments |
| 227 | 242 |
| 228 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_BROWSERTEST_BASE_H_ | 243 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_BROWSERTEST_BASE_H_ |
| OLD | NEW |