| 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_browsertest_base.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" | 14 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #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" |
| 19 #include "chrome/browser/ui/views/payments/validating_combobox.h" | 19 #include "chrome/browser/ui/views/payments/validating_combobox.h" |
| 20 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 20 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
| 21 #include "chrome/browser/ui/views/payments/view_stack.h" | 21 #include "chrome/browser/ui/views/payments/view_stack.h" |
| 22 #include "chrome/test/base/interactive_test_utils.h" | |
| 23 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "components/autofill/core/browser/autofill_profile.h" | 23 #include "components/autofill/core/browser/autofill_profile.h" |
| 25 #include "components/autofill/core/browser/credit_card.h" | 24 #include "components/autofill/core/browser/credit_card.h" |
| 26 #include "components/autofill/core/browser/personal_data_manager.h" | 25 #include "components/autofill/core/browser/personal_data_manager.h" |
| 27 #include "components/payments/content/payment_request.h" | 26 #include "components/payments/content/payment_request.h" |
| 28 #include "components/payments/content/payment_request_web_contents_manager.h" | 27 #include "components/payments/content/payment_request_web_contents_manager.h" |
| 29 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 28 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 30 #include "content/public/browser/render_frame_host.h" | 29 #include "content/public/browser/render_frame_host.h" |
| 31 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/common/content_features.h" | 31 #include "content/public/common/content_features.h" |
| 33 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/test/browser_test_utils.h" | 33 #include "content/public/test/browser_test_utils.h" |
| 35 #include "services/service_manager/public/cpp/interface_registry.h" | 34 #include "services/service_manager/public/cpp/interface_registry.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "ui/base/test/ui_controls.h" | 36 #include "ui/base/test/ui_controls.h" |
| 37 #include "ui/events/base_event_utils.h" |
| 38 #include "ui/events/event.h" |
| 38 #include "ui/gfx/animation/test_animation_delegate.h" | 39 #include "ui/gfx/animation/test_animation_delegate.h" |
| 40 #include "ui/gfx/geometry/point.h" |
| 39 #include "ui/views/controls/button/button.h" | 41 #include "ui/views/controls/button/button.h" |
| 40 #include "ui/views/controls/label.h" | 42 #include "ui/views/controls/label.h" |
| 41 #include "ui/views/controls/styled_label.h" | 43 #include "ui/views/controls/styled_label.h" |
| 42 | 44 |
| 43 namespace payments { | 45 namespace payments { |
| 44 | 46 |
| 45 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} | 47 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} |
| 46 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} | 48 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} |
| 47 | 49 |
| 48 PaymentRequestInteractiveTestBase::PaymentRequestInteractiveTestBase( | 50 PaymentRequestBrowserTestBase::PaymentRequestBrowserTestBase( |
| 49 const std::string& test_file_path) | 51 const std::string& test_file_path) |
| 50 : test_file_path_(test_file_path), | 52 : test_file_path_(test_file_path), delegate_(nullptr) {} |
| 51 delegate_(nullptr) {} | 53 PaymentRequestBrowserTestBase::~PaymentRequestBrowserTestBase() {} |
| 52 PaymentRequestInteractiveTestBase::~PaymentRequestInteractiveTestBase() {} | |
| 53 | 54 |
| 54 void PaymentRequestInteractiveTestBase::SetUpCommandLine( | 55 void PaymentRequestBrowserTestBase::SetUpCommandLine( |
| 55 base::CommandLine* command_line) { | 56 base::CommandLine* command_line) { |
| 56 InProcessBrowserTest::SetUpCommandLine(command_line); | 57 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 57 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | 58 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
| 58 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 59 command_line->AppendSwitchASCII(switches::kEnableFeatures, |
| 59 features::kWebPayments.name); | 60 features::kWebPayments.name); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void PaymentRequestInteractiveTestBase::SetUpOnMainThread() { | 63 void PaymentRequestBrowserTestBase::SetUpOnMainThread() { |
| 63 https_server_ = base::MakeUnique<net::EmbeddedTestServer>( | 64 https_server_ = base::MakeUnique<net::EmbeddedTestServer>( |
| 64 net::EmbeddedTestServer::TYPE_HTTPS); | 65 net::EmbeddedTestServer::TYPE_HTTPS); |
| 65 ASSERT_TRUE(https_server_->InitializeAndListen()); | 66 ASSERT_TRUE(https_server_->InitializeAndListen()); |
| 66 https_server_->ServeFilesFromSourceDirectory("chrome/test/data/payments"); | 67 https_server_->ServeFilesFromSourceDirectory("chrome/test/data/payments"); |
| 67 https_server_->StartAcceptingConnections(); | 68 https_server_->StartAcceptingConnections(); |
| 68 | 69 |
| 69 GURL url = https_server()->GetURL(test_file_path_); | 70 GURL url = https_server()->GetURL(test_file_path_); |
| 70 ui_test_utils::NavigateToURL(browser(), url); | 71 ui_test_utils::NavigateToURL(browser(), url); |
| 71 | 72 |
| 72 // Starting now, PaymentRequest Mojo messages sent by the renderer will | 73 // Starting now, PaymentRequest Mojo messages sent by the renderer will |
| 73 // create PaymentRequest objects via this test's CreatePaymentRequestForTest, | 74 // create PaymentRequest objects via this test's CreatePaymentRequestForTest, |
| 74 // allowing the test to inject itself as a dialog observer. | 75 // allowing the test to inject itself as a dialog observer. |
| 75 content::WebContents* web_contents = GetActiveWebContents(); | 76 content::WebContents* web_contents = GetActiveWebContents(); |
| 76 service_manager::InterfaceRegistry* registry = | 77 service_manager::InterfaceRegistry* registry = |
| 77 web_contents->GetMainFrame()->GetInterfaceRegistry(); | 78 web_contents->GetMainFrame()->GetInterfaceRegistry(); |
| 78 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); | 79 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); |
| 79 registry->AddInterface(base::Bind( | 80 registry->AddInterface( |
| 80 &PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest, | 81 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest, |
| 81 base::Unretained(this), web_contents)); | 82 base::Unretained(this), web_contents)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void PaymentRequestInteractiveTestBase::OnDialogOpened() { | 85 void PaymentRequestBrowserTestBase::OnDialogOpened() { |
| 85 if (event_observer_) | 86 if (event_observer_) |
| 86 event_observer_->Observe(DialogEvent::DIALOG_OPENED); | 87 event_observer_->Observe(DialogEvent::DIALOG_OPENED); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void PaymentRequestInteractiveTestBase::OnOrderSummaryOpened() { | 90 void PaymentRequestBrowserTestBase::OnOrderSummaryOpened() { |
| 90 if (event_observer_) | 91 if (event_observer_) |
| 91 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); | 92 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void PaymentRequestInteractiveTestBase::OnPaymentMethodOpened() { | 95 void PaymentRequestBrowserTestBase::OnPaymentMethodOpened() { |
| 95 if (event_observer_) | 96 if (event_observer_) |
| 96 event_observer_->Observe(DialogEvent::PAYMENT_METHOD_OPENED); | 97 event_observer_->Observe(DialogEvent::PAYMENT_METHOD_OPENED); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void PaymentRequestInteractiveTestBase::OnCreditCardEditorOpened() { | 100 void PaymentRequestBrowserTestBase::OnCreditCardEditorOpened() { |
| 100 if (event_observer_) | 101 if (event_observer_) |
| 101 event_observer_->Observe(DialogEvent::CREDIT_CARD_EDITOR_OPENED); | 102 event_observer_->Observe(DialogEvent::CREDIT_CARD_EDITOR_OPENED); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void PaymentRequestInteractiveTestBase::OnBackNavigation() { | 105 void PaymentRequestBrowserTestBase::OnBackNavigation() { |
| 105 if (event_observer_) | 106 if (event_observer_) |
| 106 event_observer_->Observe(DialogEvent::BACK_NAVIGATION); | 107 event_observer_->Observe(DialogEvent::BACK_NAVIGATION); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void PaymentRequestInteractiveTestBase::OnContactInfoOpened() { | 110 void PaymentRequestBrowserTestBase::OnContactInfoOpened() { |
| 110 if (event_observer_) | 111 if (event_observer_) |
| 111 event_observer_->Observe(DialogEvent::CONTACT_INFO_OPENED); | 112 event_observer_->Observe(DialogEvent::CONTACT_INFO_OPENED); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void PaymentRequestInteractiveTestBase::OnWidgetDestroyed( | 115 void PaymentRequestBrowserTestBase::OnWidgetDestroyed(views::Widget* widget) { |
| 115 views::Widget* widget) { | |
| 116 if (event_observer_) | 116 if (event_observer_) |
| 117 event_observer_->Observe(DialogEvent::DIALOG_CLOSED); | 117 event_observer_->Observe(DialogEvent::DIALOG_CLOSED); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void PaymentRequestInteractiveTestBase::InvokePaymentRequestUI() { | 120 void PaymentRequestBrowserTestBase::InvokePaymentRequestUI() { |
| 121 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 121 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
| 122 | 122 |
| 123 content::WebContents* web_contents = GetActiveWebContents(); | 123 content::WebContents* web_contents = GetActiveWebContents(); |
| 124 const std::string click_buy_button_js = | 124 const std::string click_buy_button_js = |
| 125 "(function() { document.getElementById('buy').click(); })();"; | 125 "(function() { document.getElementById('buy').click(); })();"; |
| 126 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); | 126 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); |
| 127 | 127 |
| 128 WaitForObservedEvent(); | 128 WaitForObservedEvent(); |
| 129 | 129 |
| 130 // The web-modal dialog should be open. | 130 // The web-modal dialog should be open. |
| 131 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 131 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 132 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 132 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 133 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 133 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void PaymentRequestInteractiveTestBase::OpenOrderSummaryScreen() { | 136 void PaymentRequestBrowserTestBase::OpenOrderSummaryScreen() { |
| 137 ResetEventObserver(DialogEvent::ORDER_SUMMARY_OPENED); | 137 ResetEventObserver(DialogEvent::ORDER_SUMMARY_OPENED); |
| 138 | 138 |
| 139 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION); | 139 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void PaymentRequestInteractiveTestBase::OpenPaymentMethodScreen() { | 142 void PaymentRequestBrowserTestBase::OpenPaymentMethodScreen() { |
| 143 ResetEventObserver(DialogEvent::PAYMENT_METHOD_OPENED); | 143 ResetEventObserver(DialogEvent::PAYMENT_METHOD_OPENED); |
| 144 | 144 |
| 145 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION); | 145 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void PaymentRequestInteractiveTestBase::OpenCreditCardEditorScreen() { | 148 void PaymentRequestBrowserTestBase::OpenCreditCardEditorScreen() { |
| 149 ResetEventObserver(DialogEvent::CREDIT_CARD_EDITOR_OPENED); | 149 ResetEventObserver(DialogEvent::CREDIT_CARD_EDITOR_OPENED); |
| 150 | 150 |
| 151 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON); | 151 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON); |
| 152 } | 152 } |
| 153 | 153 |
| 154 content::WebContents* | 154 content::WebContents* PaymentRequestBrowserTestBase::GetActiveWebContents() { |
| 155 PaymentRequestInteractiveTestBase::GetActiveWebContents() { | |
| 156 return browser()->tab_strip_model()->GetActiveWebContents(); | 155 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 157 } | 156 } |
| 158 | 157 |
| 159 const std::vector<PaymentRequest*> | 158 const std::vector<PaymentRequest*> |
| 160 PaymentRequestInteractiveTestBase::GetPaymentRequests( | 159 PaymentRequestBrowserTestBase::GetPaymentRequests( |
| 161 content::WebContents* web_contents) { | 160 content::WebContents* web_contents) { |
| 162 PaymentRequestWebContentsManager* manager = | 161 PaymentRequestWebContentsManager* manager = |
| 163 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents); | 162 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents); |
| 164 if (!manager) | 163 if (!manager) |
| 165 return std::vector<PaymentRequest*>(); | 164 return std::vector<PaymentRequest*>(); |
| 166 | 165 |
| 167 std::vector<PaymentRequest*> payment_requests_ptrs; | 166 std::vector<PaymentRequest*> payment_requests_ptrs; |
| 168 for (const auto& p : manager->payment_requests_) | 167 for (const auto& p : manager->payment_requests_) |
| 169 payment_requests_ptrs.push_back(p.first); | 168 payment_requests_ptrs.push_back(p.first); |
| 170 return payment_requests_ptrs; | 169 return payment_requests_ptrs; |
| 171 } | 170 } |
| 172 | 171 |
| 173 autofill::PersonalDataManager* | 172 autofill::PersonalDataManager* PaymentRequestBrowserTestBase::GetDataManager() { |
| 174 PaymentRequestInteractiveTestBase::GetDataManager() { | |
| 175 return autofill::PersonalDataManagerFactory::GetForProfile( | 173 return autofill::PersonalDataManagerFactory::GetForProfile( |
| 176 Profile::FromBrowserContext(GetActiveWebContents()->GetBrowserContext())); | 174 Profile::FromBrowserContext(GetActiveWebContents()->GetBrowserContext())); |
| 177 } | 175 } |
| 178 | 176 |
| 179 void PaymentRequestInteractiveTestBase::AddAutofillProfile( | 177 void PaymentRequestBrowserTestBase::AddAutofillProfile( |
| 180 const autofill::AutofillProfile& profile) { | 178 const autofill::AutofillProfile& profile) { |
| 181 autofill::PersonalDataManager* personal_data_manager = GetDataManager(); | 179 autofill::PersonalDataManager* personal_data_manager = GetDataManager(); |
| 182 size_t profile_count = personal_data_manager->GetProfiles().size(); | 180 size_t profile_count = personal_data_manager->GetProfiles().size(); |
| 183 | 181 |
| 184 PersonalDataLoadedObserverMock personal_data_observer; | 182 PersonalDataLoadedObserverMock personal_data_observer; |
| 185 personal_data_manager->AddObserver(&personal_data_observer); | 183 personal_data_manager->AddObserver(&personal_data_observer); |
| 186 base::RunLoop data_loop; | 184 base::RunLoop data_loop; |
| 187 EXPECT_CALL(personal_data_observer, OnPersonalDataChanged()) | 185 EXPECT_CALL(personal_data_observer, OnPersonalDataChanged()) |
| 188 .WillOnce(QuitMessageLoop(&data_loop)); | 186 .WillOnce(QuitMessageLoop(&data_loop)); |
| 189 personal_data_manager->AddProfile(profile); | 187 personal_data_manager->AddProfile(profile); |
| 190 data_loop.Run(); | 188 data_loop.Run(); |
| 191 | 189 |
| 192 personal_data_manager->RemoveObserver(&personal_data_observer); | 190 personal_data_manager->RemoveObserver(&personal_data_observer); |
| 193 EXPECT_EQ(profile_count + 1, personal_data_manager->GetProfiles().size()); | 191 EXPECT_EQ(profile_count + 1, personal_data_manager->GetProfiles().size()); |
| 194 } | 192 } |
| 195 | 193 |
| 196 void PaymentRequestInteractiveTestBase::AddCreditCard( | 194 void PaymentRequestBrowserTestBase::AddCreditCard( |
| 197 const autofill::CreditCard& card) { | 195 const autofill::CreditCard& card) { |
| 198 autofill::PersonalDataManager* personal_data_manager = GetDataManager(); | 196 autofill::PersonalDataManager* personal_data_manager = GetDataManager(); |
| 199 size_t card_count = personal_data_manager->GetCreditCards().size(); | 197 size_t card_count = personal_data_manager->GetCreditCards().size(); |
| 200 | 198 |
| 201 PersonalDataLoadedObserverMock personal_data_observer; | 199 PersonalDataLoadedObserverMock personal_data_observer; |
| 202 personal_data_manager->AddObserver(&personal_data_observer); | 200 personal_data_manager->AddObserver(&personal_data_observer); |
| 203 base::RunLoop data_loop; | 201 base::RunLoop data_loop; |
| 204 EXPECT_CALL(personal_data_observer, OnPersonalDataChanged()) | 202 EXPECT_CALL(personal_data_observer, OnPersonalDataChanged()) |
| 205 .WillOnce(QuitMessageLoop(&data_loop)); | 203 .WillOnce(QuitMessageLoop(&data_loop)); |
| 206 personal_data_manager->AddCreditCard(card); | 204 personal_data_manager->AddCreditCard(card); |
| 207 data_loop.Run(); | 205 data_loop.Run(); |
| 208 | 206 |
| 209 personal_data_manager->RemoveObserver(&personal_data_observer); | 207 personal_data_manager->RemoveObserver(&personal_data_observer); |
| 210 EXPECT_EQ(card_count + 1, personal_data_manager->GetCreditCards().size()); | 208 EXPECT_EQ(card_count + 1, personal_data_manager->GetCreditCards().size()); |
| 211 } | 209 } |
| 212 | 210 |
| 213 void PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest( | 211 void PaymentRequestBrowserTestBase::CreatePaymentRequestForTest( |
| 214 content::WebContents* web_contents, | 212 content::WebContents* web_contents, |
| 215 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | 213 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { |
| 216 DCHECK(web_contents); | 214 DCHECK(web_contents); |
| 217 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = | 215 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = |
| 218 base::MakeUnique<TestChromePaymentRequestDelegate>( | 216 base::MakeUnique<TestChromePaymentRequestDelegate>( |
| 219 web_contents, this /* observer */, this /* widget_observer */); | 217 web_contents, this /* observer */, this /* widget_observer */); |
| 220 delegate_ = delegate.get(); | 218 delegate_ = delegate.get(); |
| 221 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) | 219 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) |
| 222 ->CreatePaymentRequest(web_contents, std::move(delegate), | 220 ->CreatePaymentRequest(web_contents, std::move(delegate), |
| 223 std::move(request)); | 221 std::move(request)); |
| 224 } | 222 } |
| 225 | 223 |
| 226 void PaymentRequestInteractiveTestBase::ClickOnDialogViewAndWait( | 224 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( |
| 227 DialogViewID view_id) { | 225 DialogViewID view_id) { |
| 228 views::View* view = | 226 views::View* view = |
| 229 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id)); | 227 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id)); |
| 230 DCHECK(view); | 228 DCHECK(view); |
| 231 ClickOnDialogViewAndWait(view); | 229 ClickOnDialogViewAndWait(view); |
| 232 } | 230 } |
| 233 | 231 |
| 234 void PaymentRequestInteractiveTestBase::ClickOnDialogViewAndWait( | 232 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( |
| 235 views::View* view) { | 233 views::View* view) { |
| 236 DCHECK(view); | 234 DCHECK(view); |
| 237 base::RunLoop run_loop; | 235 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 238 ui_test_utils::MoveMouseToCenterAndPress( | 236 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 239 view, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 237 ui::EF_LEFT_MOUSE_BUTTON); |
| 240 run_loop.QuitClosure()); | 238 view->OnMousePressed(pressed); |
| 241 run_loop.Run(); | 239 ui::MouseEvent released_event = ui::MouseEvent( |
| 240 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 241 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 242 view->OnMouseReleased(released_event); |
| 242 | 243 |
| 243 WaitForAnimation(); | 244 WaitForAnimation(); |
| 244 | 245 |
| 245 WaitForObservedEvent(); | 246 WaitForObservedEvent(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 void PaymentRequestInteractiveTestBase::SetEditorTextfieldValue( | 249 void PaymentRequestBrowserTestBase::SetEditorTextfieldValue( |
| 249 const base::string16& value, | 250 const base::string16& value, |
| 250 autofill::ServerFieldType type) { | 251 autofill::ServerFieldType type) { |
| 251 ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>( | 252 ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>( |
| 252 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); | 253 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); |
| 253 DCHECK(textfield); | 254 DCHECK(textfield); |
| 254 textfield->SetText(value); | 255 textfield->SetText(value); |
| 255 textfield->OnContentsChanged(); | 256 textfield->OnContentsChanged(); |
| 256 textfield->OnBlur(); | 257 textfield->OnBlur(); |
| 257 } | 258 } |
| 258 | 259 |
| 259 void PaymentRequestInteractiveTestBase::SetComboboxValue( | 260 void PaymentRequestBrowserTestBase::SetComboboxValue( |
| 260 const base::string16& value, | 261 const base::string16& value, |
| 261 autofill::ServerFieldType type) { | 262 autofill::ServerFieldType type) { |
| 262 ValidatingCombobox* combobox = static_cast<ValidatingCombobox*>( | 263 ValidatingCombobox* combobox = static_cast<ValidatingCombobox*>( |
| 263 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); | 264 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); |
| 264 DCHECK(combobox); | 265 DCHECK(combobox); |
| 265 combobox->SelectValue(value); | 266 combobox->SelectValue(value); |
| 266 combobox->OnContentsChanged(); | 267 combobox->OnContentsChanged(); |
| 267 combobox->OnBlur(); | 268 combobox->OnBlur(); |
| 268 } | 269 } |
| 269 | 270 |
| 270 bool PaymentRequestInteractiveTestBase::IsEditorTextfieldInvalid( | 271 bool PaymentRequestBrowserTestBase::IsEditorTextfieldInvalid( |
| 271 autofill::ServerFieldType type) { | 272 autofill::ServerFieldType type) { |
| 272 ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>( | 273 ValidatingTextfield* textfield = static_cast<ValidatingTextfield*>( |
| 273 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); | 274 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); |
| 274 DCHECK(textfield); | 275 DCHECK(textfield); |
| 275 return textfield->invalid(); | 276 return textfield->invalid(); |
| 276 } | 277 } |
| 277 | 278 |
| 278 bool PaymentRequestInteractiveTestBase::IsEditorComboboxInvalid( | 279 bool PaymentRequestBrowserTestBase::IsEditorComboboxInvalid( |
| 279 autofill::ServerFieldType type) { | 280 autofill::ServerFieldType type) { |
| 280 ValidatingCombobox* combobox = static_cast<ValidatingCombobox*>( | 281 ValidatingCombobox* combobox = static_cast<ValidatingCombobox*>( |
| 281 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); | 282 delegate_->dialog_view()->GetViewByID(static_cast<int>(type))); |
| 282 DCHECK(combobox); | 283 DCHECK(combobox); |
| 283 return combobox->invalid(); | 284 return combobox->invalid(); |
| 284 } | 285 } |
| 285 | 286 |
| 286 bool PaymentRequestInteractiveTestBase::IsPayButtonEnabled() { | 287 bool PaymentRequestBrowserTestBase::IsPayButtonEnabled() { |
| 287 views::Button* button = | 288 views::Button* button = |
| 288 static_cast<views::Button*>(delegate_->dialog_view()->GetViewByID( | 289 static_cast<views::Button*>(delegate_->dialog_view()->GetViewByID( |
| 289 static_cast<int>(DialogViewID::PAY_BUTTON))); | 290 static_cast<int>(DialogViewID::PAY_BUTTON))); |
| 290 DCHECK(button); | 291 DCHECK(button); |
| 291 return button->enabled(); | 292 return button->enabled(); |
| 292 } | 293 } |
| 293 | 294 |
| 294 void PaymentRequestInteractiveTestBase::WaitForAnimation() { | 295 void PaymentRequestBrowserTestBase::WaitForAnimation() { |
| 295 ViewStack* view_stack = dialog_view()->view_stack_for_testing(); | 296 ViewStack* view_stack = dialog_view()->view_stack_for_testing(); |
| 296 if (view_stack->slide_in_animator_->IsAnimating()) { | 297 if (view_stack->slide_in_animator_->IsAnimating()) { |
| 297 view_stack->slide_in_animator_->SetAnimationDuration(1); | 298 view_stack->slide_in_animator_->SetAnimationDuration(1); |
| 298 view_stack->slide_in_animator_->SetAnimationDelegate( | 299 view_stack->slide_in_animator_->SetAnimationDelegate( |
| 299 view_stack->top(), std::unique_ptr<gfx::AnimationDelegate>( | 300 view_stack->top(), std::unique_ptr<gfx::AnimationDelegate>( |
| 300 new gfx::TestAnimationDelegate())); | 301 new gfx::TestAnimationDelegate())); |
| 301 base::RunLoop().Run(); | 302 base::RunLoop().Run(); |
| 302 } else if (view_stack->slide_out_animator_->IsAnimating()) { | 303 } else if (view_stack->slide_out_animator_->IsAnimating()) { |
| 303 view_stack->slide_out_animator_->SetAnimationDuration(1); | 304 view_stack->slide_out_animator_->SetAnimationDuration(1); |
| 304 view_stack->slide_out_animator_->SetAnimationDelegate( | 305 view_stack->slide_out_animator_->SetAnimationDelegate( |
| 305 view_stack->top(), std::unique_ptr<gfx::AnimationDelegate>( | 306 view_stack->top(), std::unique_ptr<gfx::AnimationDelegate>( |
| 306 new gfx::TestAnimationDelegate())); | 307 new gfx::TestAnimationDelegate())); |
| 307 base::RunLoop().Run(); | 308 base::RunLoop().Run(); |
| 308 } | 309 } |
| 309 } | 310 } |
| 310 | 311 |
| 311 const base::string16& PaymentRequestInteractiveTestBase::GetStyledLabelText( | 312 const base::string16& PaymentRequestBrowserTestBase::GetStyledLabelText( |
| 312 DialogViewID view_id) { | 313 DialogViewID view_id) { |
| 313 views::View* view = dialog_view()->GetViewByID(static_cast<int>(view_id)); | 314 views::View* view = dialog_view()->GetViewByID(static_cast<int>(view_id)); |
| 314 DCHECK(view); | 315 DCHECK(view); |
| 315 return static_cast<views::StyledLabel*>(view)->text(); | 316 return static_cast<views::StyledLabel*>(view)->text(); |
| 316 } | 317 } |
| 317 | 318 |
| 318 const base::string16& PaymentRequestInteractiveTestBase::GetErrorLabelForType( | 319 const base::string16& PaymentRequestBrowserTestBase::GetErrorLabelForType( |
| 319 autofill::ServerFieldType type) { | 320 autofill::ServerFieldType type) { |
| 320 views::View* view = dialog_view()->GetViewByID( | 321 views::View* view = dialog_view()->GetViewByID( |
| 321 static_cast<int>(DialogViewID::ERROR_LABEL_OFFSET) + type); | 322 static_cast<int>(DialogViewID::ERROR_LABEL_OFFSET) + type); |
| 322 DCHECK(view); | 323 DCHECK(view); |
| 323 return static_cast<views::Label*>(view)->text(); | 324 return static_cast<views::Label*>(view)->text(); |
| 324 } | 325 } |
| 325 | 326 |
| 326 PaymentRequestInteractiveTestBase::DialogEventObserver::DialogEventObserver( | 327 PaymentRequestBrowserTestBase::DialogEventObserver::DialogEventObserver( |
| 327 PaymentRequestInteractiveTestBase::DialogEvent event) | 328 PaymentRequestBrowserTestBase::DialogEvent event) |
| 328 : event_(event), seen_(false) {} | 329 : event_(event), seen_(false) {} |
| 329 PaymentRequestInteractiveTestBase::DialogEventObserver::~DialogEventObserver() { | 330 PaymentRequestBrowserTestBase::DialogEventObserver::~DialogEventObserver() {} |
| 330 } | |
| 331 | 331 |
| 332 void PaymentRequestInteractiveTestBase::DialogEventObserver::Wait() { | 332 void PaymentRequestBrowserTestBase::DialogEventObserver::Wait() { |
| 333 if (seen_) | 333 if (seen_) |
| 334 return; | 334 return; |
| 335 | 335 |
| 336 DCHECK(!run_loop_.running()); | 336 DCHECK(!run_loop_.running()); |
| 337 run_loop_.Run(); | 337 run_loop_.Run(); |
| 338 } | 338 } |
| 339 | 339 |
| 340 void PaymentRequestInteractiveTestBase::DialogEventObserver::Observe( | 340 void PaymentRequestBrowserTestBase::DialogEventObserver::Observe( |
| 341 PaymentRequestInteractiveTestBase::DialogEvent event) { | 341 PaymentRequestBrowserTestBase::DialogEvent event) { |
| 342 if (seen_) | 342 if (seen_) |
| 343 return; | 343 return; |
| 344 | 344 |
| 345 DCHECK_EQ(event_, event); | 345 DCHECK_EQ(event_, event); |
| 346 seen_ = true; | 346 seen_ = true; |
| 347 if (run_loop_.running()) | 347 if (run_loop_.running()) |
| 348 run_loop_.Quit(); | 348 run_loop_.Quit(); |
| 349 } | 349 } |
| 350 | 350 |
| 351 void PaymentRequestInteractiveTestBase::ResetEventObserver(DialogEvent event) { | 351 void PaymentRequestBrowserTestBase::ResetEventObserver(DialogEvent event) { |
| 352 event_observer_ = base::MakeUnique<DialogEventObserver>(event); | 352 event_observer_ = base::MakeUnique<DialogEventObserver>(event); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void PaymentRequestInteractiveTestBase::WaitForObservedEvent() { | 355 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { |
| 356 event_observer_->Wait(); | 356 event_observer_->Wait(); |
| 357 } | 357 } |
| 358 | 358 |
| 359 } // namespace payments | 359 } // namespace payments |
| OLD | NEW |