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_browsertest_base.h" | 5 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iostream> |
8 #include <memory> | 9 #include <memory> |
9 #include <string> | 10 #include <string> |
10 #include <utility> | 11 #include <utility> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 content::WebContents* web_contents = GetActiveWebContents(); | 75 content::WebContents* web_contents = GetActiveWebContents(); |
75 service_manager::BinderRegistry* registry = | 76 service_manager::BinderRegistry* registry = |
76 web_contents->GetMainFrame()->GetInterfaceRegistry(); | 77 web_contents->GetMainFrame()->GetInterfaceRegistry(); |
77 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); | 78 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); |
78 registry->AddInterface( | 79 registry->AddInterface( |
79 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest, | 80 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest, |
80 base::Unretained(this), web_contents)); | 81 base::Unretained(this), web_contents)); |
81 } | 82 } |
82 | 83 |
83 void PaymentRequestBrowserTestBase::NavigateTo(const std::string& file_path) { | 84 void PaymentRequestBrowserTestBase::NavigateTo(const std::string& file_path) { |
84 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL(file_path)); | 85 ui_test_utils::NavigateToURL(browser(), |
| 86 file_path.find("data:") == 0U |
| 87 ? GURL(file_path) |
| 88 : https_server()->GetURL(file_path)); |
85 } | 89 } |
86 | 90 |
87 void PaymentRequestBrowserTestBase::SetIncognito() { | 91 void PaymentRequestBrowserTestBase::SetIncognito() { |
88 is_incognito_ = true; | 92 is_incognito_ = true; |
89 } | 93 } |
90 | 94 |
91 void PaymentRequestBrowserTestBase::SetInvalidSsl() { | 95 void PaymentRequestBrowserTestBase::SetInvalidSsl() { |
92 is_valid_ssl_ = false; | 96 is_valid_ssl_ = false; |
93 } | 97 } |
94 | 98 |
95 void PaymentRequestBrowserTestBase::OnCanMakePaymentCalled() { | 99 void PaymentRequestBrowserTestBase::OnCanMakePaymentCalled() { |
96 if (event_observer_) | 100 if (event_observer_) |
97 event_observer_->Observe(DialogEvent::CAN_MAKE_PAYMENT_CALLED); | 101 event_observer_->Observe(DialogEvent::CAN_MAKE_PAYMENT_CALLED); |
98 } | 102 } |
99 | 103 |
100 void PaymentRequestBrowserTestBase::OnNotSupportedError() { | 104 void PaymentRequestBrowserTestBase::OnNotSupportedError() { |
101 if (event_observer_) | 105 if (event_observer_) |
102 event_observer_->Observe(DialogEvent::NOT_SUPPORTED_ERROR); | 106 event_observer_->Observe(DialogEvent::NOT_SUPPORTED_ERROR); |
103 } | 107 } |
104 | 108 |
| 109 void PaymentRequestBrowserTestBase::OnConnectionTerminated() { |
| 110 if (event_observer_) |
| 111 event_observer_->Observe(DialogEvent::DIALOG_CLOSED); |
| 112 } |
| 113 |
105 void PaymentRequestBrowserTestBase::OnDialogOpened() { | 114 void PaymentRequestBrowserTestBase::OnDialogOpened() { |
106 if (event_observer_) | 115 if (event_observer_) |
107 event_observer_->Observe(DialogEvent::DIALOG_OPENED); | 116 event_observer_->Observe(DialogEvent::DIALOG_OPENED); |
108 } | 117 } |
109 | 118 |
110 void PaymentRequestBrowserTestBase::OnOrderSummaryOpened() { | 119 void PaymentRequestBrowserTestBase::OnOrderSummaryOpened() { |
111 if (event_observer_) | 120 if (event_observer_) |
112 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); | 121 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); |
113 } | 122 } |
114 | 123 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 void PaymentRequestBrowserTestBase::OnSpecDoneUpdating() { | 179 void PaymentRequestBrowserTestBase::OnSpecDoneUpdating() { |
171 if (event_observer_) | 180 if (event_observer_) |
172 event_observer_->Observe(DialogEvent::SPEC_DONE_UPDATING); | 181 event_observer_->Observe(DialogEvent::SPEC_DONE_UPDATING); |
173 } | 182 } |
174 | 183 |
175 void PaymentRequestBrowserTestBase::OnCvcPromptShown() { | 184 void PaymentRequestBrowserTestBase::OnCvcPromptShown() { |
176 if (event_observer_) | 185 if (event_observer_) |
177 event_observer_->Observe(DialogEvent::CVC_PROMPT_SHOWN); | 186 event_observer_->Observe(DialogEvent::CVC_PROMPT_SHOWN); |
178 } | 187 } |
179 | 188 |
180 void PaymentRequestBrowserTestBase::OnWidgetDestroyed(views::Widget* widget) { | |
181 if (event_observer_) | |
182 event_observer_->Observe(DialogEvent::DIALOG_CLOSED); | |
183 } | |
184 | |
185 void PaymentRequestBrowserTestBase::InvokePaymentRequestUI() { | 189 void PaymentRequestBrowserTestBase::InvokePaymentRequestUI() { |
186 ResetEventObserver(DialogEvent::DIALOG_OPENED); | 190 ResetEventObserver(DialogEvent::DIALOG_OPENED); |
187 | 191 |
188 content::WebContents* web_contents = GetActiveWebContents(); | 192 content::WebContents* web_contents = GetActiveWebContents(); |
189 const std::string click_buy_button_js = | 193 const std::string click_buy_button_js = |
190 "(function() { document.getElementById('buy').click(); })();"; | 194 "(function() { document.getElementById('buy').click(); })();"; |
191 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); | 195 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); |
192 | 196 |
193 WaitForObservedEvent(); | 197 WaitForObservedEvent(); |
194 | 198 |
195 // The web-modal dialog should be open. | 199 // The web-modal dialog should be open. |
196 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 200 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
197 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 201 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
198 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 202 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
199 } | 203 } |
200 | 204 |
201 void PaymentRequestBrowserTestBase::ExpectBodyContains( | 205 void PaymentRequestBrowserTestBase::ExpectBodyContains( |
202 const std::vector<std::string>& expected_strings) { | 206 const std::vector<std::string>& expected_strings) { |
203 content::WebContents* web_contents = GetActiveWebContents(); | 207 content::WebContents* web_contents = GetActiveWebContents(); |
204 const std::string extract_contents_js = | 208 const std::string extract_contents_js = |
205 "(function() { " | 209 "(function() { " |
206 "window.domAutomationController.send(window.document.body.textContent); " | 210 "window.domAutomationController.send(window.document.body.textContent); " |
207 "})()"; | 211 "})()"; |
208 std::string contents; | 212 std::string contents; |
209 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 213 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
210 web_contents, extract_contents_js, &contents)); | 214 web_contents, extract_contents_js, &contents)); |
211 for (const std::string& expected_string : expected_strings) { | 215 for (const std::string& expected_string : expected_strings) { |
212 EXPECT_NE(std::string::npos, contents.find(expected_string)) | 216 EXPECT_NE(std::string::npos, contents.find(expected_string)) |
213 << "String not present: " << expected_string; | 217 << "String \"" << expected_string |
| 218 << "\" is not present in the content \"" << contents << "\""; |
214 } | 219 } |
215 } | 220 } |
216 | 221 |
217 void PaymentRequestBrowserTestBase::ExpectBodyContains( | 222 void PaymentRequestBrowserTestBase::ExpectBodyContains( |
218 const std::vector<base::string16>& expected_strings) { | 223 const std::vector<base::string16>& expected_strings) { |
219 std::vector<std::string> converted(expected_strings.size()); | 224 std::vector<std::string> converted(expected_strings.size()); |
220 std::transform(expected_strings.begin(), expected_strings.end(), | 225 std::transform(expected_strings.begin(), expected_strings.end(), |
221 converted.begin(), | 226 converted.begin(), |
222 [](const base::string16& s) { return base::UTF16ToUTF8(s); }); | 227 [](const base::string16& s) { return base::UTF16ToUTF8(s); }); |
223 ExpectBodyContains(converted); | 228 ExpectBodyContains(converted); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 EXPECT_EQ(card_count + 1, personal_data_manager->GetCreditCards().size()); | 404 EXPECT_EQ(card_count + 1, personal_data_manager->GetCreditCards().size()); |
400 } | 405 } |
401 | 406 |
402 void PaymentRequestBrowserTestBase::CreatePaymentRequestForTest( | 407 void PaymentRequestBrowserTestBase::CreatePaymentRequestForTest( |
403 content::WebContents* web_contents, | 408 content::WebContents* web_contents, |
404 const service_manager::BindSourceInfo& source_info, | 409 const service_manager::BindSourceInfo& source_info, |
405 payments::mojom::PaymentRequestRequest request) { | 410 payments::mojom::PaymentRequestRequest request) { |
406 DCHECK(web_contents); | 411 DCHECK(web_contents); |
407 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = | 412 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = |
408 base::MakeUnique<TestChromePaymentRequestDelegate>( | 413 base::MakeUnique<TestChromePaymentRequestDelegate>( |
409 web_contents, this /* observer */, this /* widget_observer */, | 414 web_contents, this /* observer */, is_incognito_, is_valid_ssl_); |
410 is_incognito_, is_valid_ssl_); | |
411 delegate_ = delegate.get(); | 415 delegate_ = delegate.get(); |
412 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) | 416 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) |
413 ->CreatePaymentRequest(web_contents, std::move(delegate), | 417 ->CreatePaymentRequest(web_contents, std::move(delegate), |
414 std::move(request), this); | 418 std::move(request), this); |
415 } | 419 } |
416 | 420 |
417 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( | 421 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( |
418 DialogViewID view_id, | 422 DialogViewID view_id, |
419 bool wait_for_animation) { | 423 bool wait_for_animation) { |
420 views::View* view = | 424 views::View* view = |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 std::list<DialogEvent> event_sequence) { | 658 std::list<DialogEvent> event_sequence) { |
655 event_observer_ = | 659 event_observer_ = |
656 base::MakeUnique<DialogEventObserver>(std::move(event_sequence)); | 660 base::MakeUnique<DialogEventObserver>(std::move(event_sequence)); |
657 } | 661 } |
658 | 662 |
659 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { | 663 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { |
660 event_observer_->Wait(); | 664 event_observer_->Wait(); |
661 } | 665 } |
662 | 666 |
663 } // namespace payments | 667 } // namespace payments |
| 668 |
| 669 std::ostream& operator<<( |
| 670 std::ostream& out, |
| 671 payments::PaymentRequestBrowserTestBase::DialogEvent event) { |
| 672 using DialogEvent = payments::PaymentRequestBrowserTestBase::DialogEvent; |
| 673 switch (event) { |
| 674 case DialogEvent::DIALOG_OPENED: |
| 675 out << "DIALOG_OPENED"; |
| 676 break; |
| 677 case DialogEvent::DIALOG_CLOSED: |
| 678 out << "DIALOG_CLOSED"; |
| 679 break; |
| 680 case DialogEvent::ORDER_SUMMARY_OPENED: |
| 681 out << "ORDER_SUMMARY_OPENED"; |
| 682 break; |
| 683 case DialogEvent::PAYMENT_METHOD_OPENED: |
| 684 out << "PAYMENT_METHOD_OPENED"; |
| 685 break; |
| 686 case DialogEvent::SHIPPING_ADDRESS_SECTION_OPENED: |
| 687 out << "SHIPPING_ADDRESS_SECTION_OPENED"; |
| 688 break; |
| 689 case DialogEvent::SHIPPING_OPTION_SECTION_OPENED: |
| 690 out << "SHIPPING_OPTION_SECTION_OPENED"; |
| 691 break; |
| 692 case DialogEvent::CREDIT_CARD_EDITOR_OPENED: |
| 693 out << "CREDIT_CARD_EDITOR_OPENED"; |
| 694 break; |
| 695 case DialogEvent::SHIPPING_ADDRESS_EDITOR_OPENED: |
| 696 out << "SHIPPING_ADDRESS_EDITOR_OPENED"; |
| 697 break; |
| 698 case DialogEvent::CONTACT_INFO_EDITOR_OPENED: |
| 699 out << "CONTACT_INFO_EDITOR_OPENED"; |
| 700 break; |
| 701 case DialogEvent::BACK_NAVIGATION: |
| 702 out << "BACK_NAVIGATION"; |
| 703 break; |
| 704 case DialogEvent::BACK_TO_PAYMENT_SHEET_NAVIGATION: |
| 705 out << "BACK_TO_PAYMENT_SHEET_NAVIGATION"; |
| 706 break; |
| 707 case DialogEvent::CONTACT_INFO_OPENED: |
| 708 out << "CONTACT_INFO_OPENED"; |
| 709 break; |
| 710 case DialogEvent::EDITOR_VIEW_UPDATED: |
| 711 out << "EDITOR_VIEW_UPDATED"; |
| 712 break; |
| 713 case DialogEvent::CAN_MAKE_PAYMENT_CALLED: |
| 714 out << "CAN_MAKE_PAYMENT_CALLED"; |
| 715 break; |
| 716 case DialogEvent::ERROR_MESSAGE_SHOWN: |
| 717 out << "ERROR_MESSAGE_SHOWN"; |
| 718 break; |
| 719 case DialogEvent::SPEC_DONE_UPDATING: |
| 720 out << "SPEC_DONE_UPDATING"; |
| 721 break; |
| 722 case DialogEvent::CVC_PROMPT_SHOWN: |
| 723 out << "CVC_PROMPT_SHOWN"; |
| 724 break; |
| 725 case DialogEvent::NOT_SUPPORTED_ERROR: |
| 726 out << "NOT_SUPPORTED_ERROR"; |
| 727 break; |
| 728 } |
| 729 return out; |
| 730 } |
OLD | NEW |