| 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 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba
se.h" | 5 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba
se.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 17 #include "chrome/browser/ui/views/payments/validating_combobox.h" | 19 #include "chrome/browser/ui/views/payments/validating_combobox.h" |
| 18 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 20 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
| 19 #include "chrome/browser/ui/views/payments/view_stack.h" | 21 #include "chrome/browser/ui/views/payments/view_stack.h" |
| 20 #include "chrome/test/base/interactive_test_utils.h" | 22 #include "chrome/test/base/interactive_test_utils.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "components/payments/payment_request.h" | 24 #include "components/payments/payment_request.h" |
| 23 #include "components/payments/payment_request_web_contents_manager.h" | 25 #include "components/payments/payment_request_web_contents_manager.h" |
| 24 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 26 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 30 #include "content/public/test/browser_test_utils.h" |
| 29 #include "services/service_manager/public/cpp/interface_registry.h" | 31 #include "services/service_manager/public/cpp/interface_registry.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "ui/base/test/ui_controls.h" | 33 #include "ui/base/test/ui_controls.h" |
| 32 #include "ui/gfx/animation/test_animation_delegate.h" | 34 #include "ui/gfx/animation/test_animation_delegate.h" |
| 33 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
| 34 #include "ui/views/controls/styled_label.h" | 36 #include "ui/views/controls/styled_label.h" |
| 35 | 37 |
| 36 namespace payments { | 38 namespace payments { |
| 37 | 39 |
| 40 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} |
| 41 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} |
| 42 |
| 38 PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase( | 43 PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase( |
| 39 const std::string& test_file_path) | 44 const std::string& test_file_path) |
| 40 : test_file_path_(test_file_path), | 45 : test_file_path_(test_file_path), |
| 41 delegate_(nullptr) {} | 46 delegate_(nullptr) {} |
| 42 PaymentRequestInteractiveTestBase::~PaymentRequestInteractiveTestBase() {} | 47 PaymentRequestInteractiveTestBase::~PaymentRequestInteractiveTestBase() {} |
| 43 | 48 |
| 44 void PaymentRequestInteractiveTestBase::SetUpCommandLine( | 49 void PaymentRequestInteractiveTestBase::SetUpCommandLine( |
| 45 base::CommandLine* command_line) { | 50 base::CommandLine* command_line) { |
| 46 InProcessBrowserTest::SetUpCommandLine(command_line); | 51 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 47 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | 52 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents); | 151 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents); |
| 147 if (!manager) | 152 if (!manager) |
| 148 return std::vector<PaymentRequest*>(); | 153 return std::vector<PaymentRequest*>(); |
| 149 | 154 |
| 150 std::vector<PaymentRequest*> payment_requests_ptrs; | 155 std::vector<PaymentRequest*> payment_requests_ptrs; |
| 151 for (const auto& p : manager->payment_requests_) | 156 for (const auto& p : manager->payment_requests_) |
| 152 payment_requests_ptrs.push_back(p.first); | 157 payment_requests_ptrs.push_back(p.first); |
| 153 return payment_requests_ptrs; | 158 return payment_requests_ptrs; |
| 154 } | 159 } |
| 155 | 160 |
| 161 autofill::PersonalDataManager* |
| 162 PaymentRequestInteractiveTestBase::GetDataManager() { |
| 163 return autofill::PersonalDataManagerFactory::GetForProfile( |
| 164 Profile::FromBrowserContext(GetActiveWebContents()->GetBrowserContext())); |
| 165 } |
| 166 |
| 156 void PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest( | 167 void PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest( |
| 157 content::WebContents* web_contents, | 168 content::WebContents* web_contents, |
| 158 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | 169 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { |
| 159 DCHECK(web_contents); | 170 DCHECK(web_contents); |
| 160 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = | 171 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = |
| 161 base::MakeUnique<TestChromePaymentRequestDelegate>( | 172 base::MakeUnique<TestChromePaymentRequestDelegate>( |
| 162 web_contents, this /* observer */, this /* widget_observer */); | 173 web_contents, this /* observer */, this /* widget_observer */); |
| 163 delegate_ = delegate.get(); | 174 delegate_ = delegate.get(); |
| 164 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) | 175 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) |
| 165 ->CreatePaymentRequest(web_contents, std::move(delegate), | 176 ->CreatePaymentRequest(web_contents, std::move(delegate), |
| 166 std::move(request)); | 177 std::move(request)); |
| 167 } | 178 } |
| 168 | 179 |
| 169 void PaymentRequestInteractiveTestBase::ClickOnDialogViewAndWait( | 180 void PaymentRequestInteractiveTestBase::ClickOnDialogViewAndWait( |
| 170 DialogViewID view_id) { | 181 DialogViewID view_id) { |
| 171 views::View* view = | 182 views::View* view = |
| 172 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id)); | 183 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id)); |
| 173 DCHECK(view); | 184 DCHECK(view); |
| 185 ClickOnDialogViewAndWait(view); |
| 186 } |
| 187 |
| 188 void PaymentRequestInteractiveTestBase::ClickOnDialogViewAndWait( |
| 189 views::View* view) { |
| 190 DCHECK(view); |
| 174 base::RunLoop run_loop; | 191 base::RunLoop run_loop; |
| 175 ui_test_utils::MoveMouseToCenterAndPress( | 192 ui_test_utils::MoveMouseToCenterAndPress( |
| 176 view, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 193 view, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
| 177 run_loop.QuitClosure()); | 194 run_loop.QuitClosure()); |
| 178 run_loop.Run(); | 195 run_loop.Run(); |
| 179 | 196 |
| 180 WaitForAnimation(); | 197 WaitForAnimation(); |
| 181 | 198 |
| 182 WaitForObservedEvent(); | 199 WaitForObservedEvent(); |
| 183 } | 200 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 296 |
| 280 void PaymentRequestInteractiveTestBase::ResetEventObserver(DialogEvent event) { | 297 void PaymentRequestInteractiveTestBase::ResetEventObserver(DialogEvent event) { |
| 281 event_observer_ = base::MakeUnique<DialogEventObserver>(event); | 298 event_observer_ = base::MakeUnique<DialogEventObserver>(event); |
| 282 } | 299 } |
| 283 | 300 |
| 284 void PaymentRequestInteractiveTestBase::WaitForObservedEvent() { | 301 void PaymentRequestInteractiveTestBase::WaitForObservedEvent() { |
| 285 event_observer_->Wait(); | 302 event_observer_->Wait(); |
| 286 } | 303 } |
| 287 | 304 |
| 288 } // namespace payments | 305 } // namespace payments |
| OLD | NEW |