| 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 <iosfwd> |
| 8 #include <list> | 9 #include <list> |
| 9 #include <memory> | 10 #include <memory> |
| 10 #include <string> | 11 #include <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 18 #include "chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.
h" | 19 #include "chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.
h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "components/autofill/core/browser/field_types.h" | 21 #include "components/autofill/core/browser/field_types.h" |
| 21 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 22 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 22 #include "components/payments/content/payment_request.h" | 23 #include "components/payments/content/payment_request.h" |
| 23 #include "components/payments/mojom/payment_request.mojom.h" | 24 #include "components/payments/mojom/payment_request.mojom.h" |
| 24 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "ui/views/widget/widget_observer.h" | |
| 27 | 27 |
| 28 namespace autofill { | 28 namespace autofill { |
| 29 class AutofillProfile; | 29 class AutofillProfile; |
| 30 class CreditCard; | 30 class CreditCard; |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 class WebContents; | 34 class WebContents; |
| 35 } // namespace content | 35 } // namespace content |
| 36 | 36 |
| 37 namespace service_manager { | 37 namespace service_manager { |
| 38 struct BindSourceInfo; | 38 struct BindSourceInfo; |
| 39 } | 39 } |
| 40 | 40 |
| 41 namespace views { | |
| 42 class Widget; | |
| 43 } | |
| 44 | |
| 45 namespace payments { | 41 namespace payments { |
| 46 | 42 |
| 47 enum class DialogViewID; | 43 enum class DialogViewID; |
| 48 | 44 |
| 49 ACTION_P(QuitMessageLoop, loop) { | 45 ACTION_P(QuitMessageLoop, loop) { |
| 50 loop->Quit(); | 46 loop->Quit(); |
| 51 } | 47 } |
| 52 | 48 |
| 53 class PersonalDataLoadedObserverMock | 49 class PersonalDataLoadedObserverMock |
| 54 : public autofill::PersonalDataManagerObserver { | 50 : public autofill::PersonalDataManagerObserver { |
| 55 public: | 51 public: |
| 56 PersonalDataLoadedObserverMock(); | 52 PersonalDataLoadedObserverMock(); |
| 57 ~PersonalDataLoadedObserverMock() override; | 53 ~PersonalDataLoadedObserverMock() override; |
| 58 | 54 |
| 59 MOCK_METHOD0(OnPersonalDataChanged, void()); | 55 MOCK_METHOD0(OnPersonalDataChanged, void()); |
| 60 }; | 56 }; |
| 61 | 57 |
| 62 // Base class for any interactive PaymentRequest test that will need to open | 58 // Base class for any interactive PaymentRequest test that will need to open |
| 63 // the UI and interact with it. | 59 // the UI and interact with it. |
| 64 class PaymentRequestBrowserTestBase | 60 class PaymentRequestBrowserTestBase |
| 65 : public InProcessBrowserTest, | 61 : public InProcessBrowserTest, |
| 66 public PaymentRequest::ObserverForTest, | 62 public PaymentRequest::ObserverForTest, |
| 67 public PaymentRequestDialogView::ObserverForTest, | 63 public PaymentRequestDialogView::ObserverForTest { |
| 68 public views::WidgetObserver { | 64 public: |
| 65 // Various events that can be waited on by the DialogEventObserver. |
| 66 enum DialogEvent : int { |
| 67 DIALOG_OPENED, |
| 68 DIALOG_CLOSED, |
| 69 ORDER_SUMMARY_OPENED, |
| 70 PAYMENT_METHOD_OPENED, |
| 71 SHIPPING_ADDRESS_SECTION_OPENED, |
| 72 SHIPPING_OPTION_SECTION_OPENED, |
| 73 CREDIT_CARD_EDITOR_OPENED, |
| 74 SHIPPING_ADDRESS_EDITOR_OPENED, |
| 75 CONTACT_INFO_EDITOR_OPENED, |
| 76 BACK_NAVIGATION, |
| 77 BACK_TO_PAYMENT_SHEET_NAVIGATION, |
| 78 CONTACT_INFO_OPENED, |
| 79 EDITOR_VIEW_UPDATED, |
| 80 CAN_MAKE_PAYMENT_CALLED, |
| 81 ERROR_MESSAGE_SHOWN, |
| 82 SPEC_DONE_UPDATING, |
| 83 CVC_PROMPT_SHOWN, |
| 84 NOT_SUPPORTED_ERROR, |
| 85 }; |
| 86 |
| 69 protected: | 87 protected: |
| 70 // Test will open a browser window to |test_file_path| (relative to | 88 // Test will open a browser window to |test_file_path| (relative to |
| 71 // chrome/test/data/payments). | 89 // chrome/test/data/payments). |
| 72 explicit PaymentRequestBrowserTestBase(const std::string& test_file_path); | 90 explicit PaymentRequestBrowserTestBase(const std::string& test_file_path); |
| 73 ~PaymentRequestBrowserTestBase() override; | 91 ~PaymentRequestBrowserTestBase() override; |
| 74 | 92 |
| 75 void SetUpOnMainThread() override; | 93 void SetUpOnMainThread() override; |
| 76 | 94 |
| 77 void NavigateTo(const std::string& file_path); | 95 void NavigateTo(const std::string& file_path); |
| 78 | 96 |
| 79 void SetIncognito(); | 97 void SetIncognito(); |
| 80 void SetInvalidSsl(); | 98 void SetInvalidSsl(); |
| 81 | 99 |
| 82 // PaymentRequest::ObserverForTest: | 100 // PaymentRequest::ObserverForTest: |
| 83 void OnCanMakePaymentCalled() override; | 101 void OnCanMakePaymentCalled() override; |
| 84 void OnNotSupportedError() override; | 102 void OnNotSupportedError() override; |
| 103 void OnConnectionTerminated() override; |
| 85 | 104 |
| 86 // PaymentRequestDialogView::ObserverForTest: | 105 // PaymentRequestDialogView::ObserverForTest: |
| 87 void OnDialogOpened() override; | 106 void OnDialogOpened() override; |
| 88 void OnOrderSummaryOpened() override; | 107 void OnOrderSummaryOpened() override; |
| 89 void OnPaymentMethodOpened() override; | 108 void OnPaymentMethodOpened() override; |
| 90 void OnShippingAddressSectionOpened() override; | 109 void OnShippingAddressSectionOpened() override; |
| 91 void OnShippingOptionSectionOpened() override; | 110 void OnShippingOptionSectionOpened() override; |
| 92 void OnCreditCardEditorOpened() override; | 111 void OnCreditCardEditorOpened() override; |
| 93 void OnShippingAddressEditorOpened() override; | 112 void OnShippingAddressEditorOpened() override; |
| 94 void OnContactInfoEditorOpened() override; | 113 void OnContactInfoEditorOpened() override; |
| 95 void OnBackNavigation() override; | 114 void OnBackNavigation() override; |
| 96 void OnBackToPaymentSheetNavigation() override; | 115 void OnBackToPaymentSheetNavigation() override; |
| 97 void OnContactInfoOpened() override; | 116 void OnContactInfoOpened() override; |
| 98 void OnEditorViewUpdated() override; | 117 void OnEditorViewUpdated() override; |
| 99 void OnErrorMessageShown() override; | 118 void OnErrorMessageShown() override; |
| 100 void OnSpecDoneUpdating() override; | 119 void OnSpecDoneUpdating() override; |
| 101 void OnCvcPromptShown() override; | 120 void OnCvcPromptShown() override; |
| 102 | 121 |
| 103 // views::WidgetObserver | |
| 104 // Effective way to be warned of all dialog closures. | |
| 105 void OnWidgetDestroyed(views::Widget* widget) override; | |
| 106 | |
| 107 // Will call JavaScript to invoke the PaymentRequest dialog and verify that | 122 // Will call JavaScript to invoke the PaymentRequest dialog and verify that |
| 108 // it's open. | 123 // it's open. |
| 109 void InvokePaymentRequestUI(); | 124 void InvokePaymentRequestUI(); |
| 110 | 125 |
| 111 // Will expect that all strings in |expected_strings| are present in output. | 126 // Will expect that all strings in |expected_strings| are present in output. |
| 112 void ExpectBodyContains(const std::vector<std::string>& expected_strings); | 127 void ExpectBodyContains(const std::vector<std::string>& expected_strings); |
| 113 void ExpectBodyContains(const std::vector<base::string16>& expected_strings); | 128 void ExpectBodyContains(const std::vector<base::string16>& expected_strings); |
| 114 | 129 |
| 115 // Utility functions that will click on Dialog views and wait for the | 130 // Utility functions that will click on Dialog views and wait for the |
| 116 // associated action to happen. | 131 // associated action to happen. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 const base::string16& GetErrorLabelForType(autofill::ServerFieldType type); | 207 const base::string16& GetErrorLabelForType(autofill::ServerFieldType type); |
| 193 | 208 |
| 194 net::EmbeddedTestServer* https_server() { return https_server_.get(); } | 209 net::EmbeddedTestServer* https_server() { return https_server_.get(); } |
| 195 | 210 |
| 196 PaymentRequestDialogView* dialog_view() { return delegate_->dialog_view(); } | 211 PaymentRequestDialogView* dialog_view() { return delegate_->dialog_view(); } |
| 197 | 212 |
| 198 void SetRegionDataLoader(autofill::RegionDataLoader* region_data_loader) { | 213 void SetRegionDataLoader(autofill::RegionDataLoader* region_data_loader) { |
| 199 delegate_->SetRegionDataLoader(region_data_loader); | 214 delegate_->SetRegionDataLoader(region_data_loader); |
| 200 } | 215 } |
| 201 | 216 |
| 202 // Various events that can be waited on by the DialogEventObserver. | |
| 203 enum DialogEvent : int { | |
| 204 DIALOG_OPENED, | |
| 205 DIALOG_CLOSED, | |
| 206 ORDER_SUMMARY_OPENED, | |
| 207 PAYMENT_METHOD_OPENED, | |
| 208 SHIPPING_ADDRESS_SECTION_OPENED, | |
| 209 SHIPPING_OPTION_SECTION_OPENED, | |
| 210 CREDIT_CARD_EDITOR_OPENED, | |
| 211 SHIPPING_ADDRESS_EDITOR_OPENED, | |
| 212 CONTACT_INFO_EDITOR_OPENED, | |
| 213 BACK_NAVIGATION, | |
| 214 BACK_TO_PAYMENT_SHEET_NAVIGATION, | |
| 215 CONTACT_INFO_OPENED, | |
| 216 EDITOR_VIEW_UPDATED, | |
| 217 CAN_MAKE_PAYMENT_CALLED, | |
| 218 ERROR_MESSAGE_SHOWN, | |
| 219 SPEC_DONE_UPDATING, | |
| 220 CVC_PROMPT_SHOWN, | |
| 221 NOT_SUPPORTED_ERROR, | |
| 222 }; | |
| 223 | |
| 224 // DialogEventObserver is used to wait on specific events that may have | 217 // DialogEventObserver is used to wait on specific events that may have |
| 225 // occured before the call to Wait(), or after, in which case a RunLoop is | 218 // occured before the call to Wait(), or after, in which case a RunLoop is |
| 226 // used. | 219 // used. |
| 227 // | 220 // |
| 228 // Usage: | 221 // Usage: |
| 229 // observer_ = | 222 // observer_ = |
| 230 // base::MakeUnique<DialogEventObserver>(std:list<DialogEvent>(...)); | 223 // base::MakeUnique<DialogEventObserver>(std:list<DialogEvent>(...)); |
| 231 // | 224 // |
| 232 // Do stuff, which (a)synchronously calls observer_->Observe(...). | 225 // Do stuff, which (a)synchronously calls observer_->Observe(...). |
| 233 // | 226 // |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // Weak, owned by the PaymentRequest object. | 259 // Weak, owned by the PaymentRequest object. |
| 267 TestChromePaymentRequestDelegate* delegate_; | 260 TestChromePaymentRequestDelegate* delegate_; |
| 268 bool is_incognito_; | 261 bool is_incognito_; |
| 269 bool is_valid_ssl_; | 262 bool is_valid_ssl_; |
| 270 | 263 |
| 271 DISALLOW_COPY_AND_ASSIGN(PaymentRequestBrowserTestBase); | 264 DISALLOW_COPY_AND_ASSIGN(PaymentRequestBrowserTestBase); |
| 272 }; | 265 }; |
| 273 | 266 |
| 274 } // namespace payments | 267 } // namespace payments |
| 275 | 268 |
| 269 std::ostream& operator<<( |
| 270 std::ostream& out, |
| 271 payments::PaymentRequestBrowserTestBase::DialogEvent event); |
| 272 |
| 276 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_BROWSERTEST_BASE_H_ | 273 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_BROWSERTEST_BASE_H_ |
| OLD | NEW |