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 <memory> | 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 #include <utility> | 10 #include <utility> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
(...skipping 30 matching lines...) Expand all Loading... |
47 | 48 |
48 namespace payments { | 49 namespace payments { |
49 | 50 |
50 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} | 51 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} |
51 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} | 52 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} |
52 | 53 |
53 PaymentRequestBrowserTestBase::PaymentRequestBrowserTestBase( | 54 PaymentRequestBrowserTestBase::PaymentRequestBrowserTestBase( |
54 const std::string& test_file_path) | 55 const std::string& test_file_path) |
55 : test_file_path_(test_file_path), | 56 : test_file_path_(test_file_path), |
56 delegate_(nullptr), | 57 delegate_(nullptr), |
57 incognito_for_testing_(false) {} | 58 is_incognito_(false), |
| 59 is_valid_ssl_(true) {} |
58 PaymentRequestBrowserTestBase::~PaymentRequestBrowserTestBase() {} | 60 PaymentRequestBrowserTestBase::~PaymentRequestBrowserTestBase() {} |
59 | 61 |
60 void PaymentRequestBrowserTestBase::SetUpCommandLine( | 62 void PaymentRequestBrowserTestBase::SetUpCommandLine( |
61 base::CommandLine* command_line) { | 63 base::CommandLine* command_line) { |
62 InProcessBrowserTest::SetUpCommandLine(command_line); | 64 InProcessBrowserTest::SetUpCommandLine(command_line); |
63 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); | 65 command_line->AppendSwitch(switches::kEnableExperimentalWebPlatformFeatures); |
64 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 66 command_line->AppendSwitchASCII(switches::kEnableFeatures, |
65 features::kWebPayments.name); | 67 features::kWebPayments.name); |
66 } | 68 } |
67 | 69 |
(...skipping 12 matching lines...) Expand all Loading... |
80 // allowing the test to inject itself as a dialog observer. | 82 // allowing the test to inject itself as a dialog observer. |
81 content::WebContents* web_contents = GetActiveWebContents(); | 83 content::WebContents* web_contents = GetActiveWebContents(); |
82 service_manager::InterfaceRegistry* registry = | 84 service_manager::InterfaceRegistry* registry = |
83 web_contents->GetMainFrame()->GetInterfaceRegistry(); | 85 web_contents->GetMainFrame()->GetInterfaceRegistry(); |
84 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); | 86 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); |
85 registry->AddInterface( | 87 registry->AddInterface( |
86 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest, | 88 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest, |
87 base::Unretained(this), web_contents)); | 89 base::Unretained(this), web_contents)); |
88 } | 90 } |
89 | 91 |
90 void PaymentRequestBrowserTestBase::SetIncognitoForTesting() { | 92 void PaymentRequestBrowserTestBase::SetIncognito() { |
91 incognito_for_testing_ = true; | 93 is_incognito_ = true; |
| 94 } |
| 95 |
| 96 void PaymentRequestBrowserTestBase::SetInvalidSsl() { |
| 97 is_valid_ssl_ = false; |
92 } | 98 } |
93 | 99 |
94 void PaymentRequestBrowserTestBase::OnCanMakePaymentCalled() { | 100 void PaymentRequestBrowserTestBase::OnCanMakePaymentCalled() { |
95 if (event_observer_) | 101 if (event_observer_) |
96 event_observer_->Observe(DialogEvent::CAN_MAKE_PAYMENT_CALLED); | 102 event_observer_->Observe(DialogEvent::CAN_MAKE_PAYMENT_CALLED); |
97 } | 103 } |
98 | 104 |
| 105 void PaymentRequestBrowserTestBase::OnNotSupportedError() { |
| 106 if (event_observer_) |
| 107 event_observer_->Observe(DialogEvent::NOT_SUPPORTED_ERROR); |
| 108 } |
| 109 |
99 void PaymentRequestBrowserTestBase::OnDialogOpened() { | 110 void PaymentRequestBrowserTestBase::OnDialogOpened() { |
100 if (event_observer_) | 111 if (event_observer_) |
101 event_observer_->Observe(DialogEvent::DIALOG_OPENED); | 112 event_observer_->Observe(DialogEvent::DIALOG_OPENED); |
102 } | 113 } |
103 | 114 |
104 void PaymentRequestBrowserTestBase::OnOrderSummaryOpened() { | 115 void PaymentRequestBrowserTestBase::OnOrderSummaryOpened() { |
105 if (event_observer_) | 116 if (event_observer_) |
106 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); | 117 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); |
107 } | 118 } |
108 | 119 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 192 |
182 WaitForObservedEvent(); | 193 WaitForObservedEvent(); |
183 | 194 |
184 // The web-modal dialog should be open. | 195 // The web-modal dialog should be open. |
185 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 196 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
186 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 197 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
187 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 198 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
188 } | 199 } |
189 | 200 |
190 void PaymentRequestBrowserTestBase::ExpectBodyContains( | 201 void PaymentRequestBrowserTestBase::ExpectBodyContains( |
191 const std::vector<base::string16>& expected_strings) { | 202 const std::vector<std::string>& expected_strings) { |
192 content::WebContents* web_contents = GetActiveWebContents(); | 203 content::WebContents* web_contents = GetActiveWebContents(); |
193 const std::string extract_contents_js = | 204 const std::string extract_contents_js = |
194 "(function() { " | 205 "(function() { " |
195 "window.domAutomationController.send(window.document.body.textContent); " | 206 "window.domAutomationController.send(window.document.body.textContent); " |
196 "})()"; | 207 "})()"; |
197 std::string contents; | 208 std::string contents; |
198 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 209 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
199 web_contents, extract_contents_js, &contents)); | 210 web_contents, extract_contents_js, &contents)); |
200 for (const auto expected_string : expected_strings) { | 211 for (const std::string& expected_string : expected_strings) { |
201 EXPECT_NE(std::string::npos, | 212 EXPECT_NE(std::string::npos, contents.find(expected_string)) |
202 contents.find(base::UTF16ToUTF8(expected_string))) | |
203 << "String not present: " << expected_string; | 213 << "String not present: " << expected_string; |
204 } | 214 } |
205 } | 215 } |
206 | 216 |
| 217 void PaymentRequestBrowserTestBase::ExpectBodyContains( |
| 218 const std::vector<base::string16>& expected_strings) { |
| 219 std::vector<std::string> converted(expected_strings.size()); |
| 220 std::transform(expected_strings.begin(), expected_strings.end(), |
| 221 converted.begin(), |
| 222 [](const base::string16& s) { return base::UTF16ToUTF8(s); }); |
| 223 ExpectBodyContains(converted); |
| 224 } |
| 225 |
207 void PaymentRequestBrowserTestBase::OpenOrderSummaryScreen() { | 226 void PaymentRequestBrowserTestBase::OpenOrderSummaryScreen() { |
208 ResetEventObserver(DialogEvent::ORDER_SUMMARY_OPENED); | 227 ResetEventObserver(DialogEvent::ORDER_SUMMARY_OPENED); |
209 | 228 |
210 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION); | 229 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION); |
211 } | 230 } |
212 | 231 |
213 void PaymentRequestBrowserTestBase::OpenPaymentMethodScreen() { | 232 void PaymentRequestBrowserTestBase::OpenPaymentMethodScreen() { |
214 ResetEventObserver(DialogEvent::PAYMENT_METHOD_OPENED); | 233 ResetEventObserver(DialogEvent::PAYMENT_METHOD_OPENED); |
215 | 234 |
216 views::View* view = delegate_->dialog_view()->GetViewByID( | 235 views::View* view = delegate_->dialog_view()->GetViewByID( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 EXPECT_EQ(card_count + 1, personal_data_manager->GetCreditCards().size()); | 348 EXPECT_EQ(card_count + 1, personal_data_manager->GetCreditCards().size()); |
330 } | 349 } |
331 | 350 |
332 void PaymentRequestBrowserTestBase::CreatePaymentRequestForTest( | 351 void PaymentRequestBrowserTestBase::CreatePaymentRequestForTest( |
333 content::WebContents* web_contents, | 352 content::WebContents* web_contents, |
334 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { | 353 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { |
335 DCHECK(web_contents); | 354 DCHECK(web_contents); |
336 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = | 355 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = |
337 base::MakeUnique<TestChromePaymentRequestDelegate>( | 356 base::MakeUnique<TestChromePaymentRequestDelegate>( |
338 web_contents, this /* observer */, this /* widget_observer */, | 357 web_contents, this /* observer */, this /* widget_observer */, |
339 incognito_for_testing_); | 358 is_incognito_, is_valid_ssl_); |
340 delegate_ = delegate.get(); | 359 delegate_ = delegate.get(); |
341 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) | 360 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) |
342 ->CreatePaymentRequest(web_contents, std::move(delegate), | 361 ->CreatePaymentRequest(web_contents, std::move(delegate), |
343 std::move(request), this); | 362 std::move(request), this); |
344 } | 363 } |
345 | 364 |
346 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( | 365 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( |
347 DialogViewID view_id, | 366 DialogViewID view_id, |
348 bool wait_for_animation) { | 367 bool wait_for_animation) { |
349 views::View* view = | 368 views::View* view = |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 std::list<DialogEvent> event_sequence) { | 591 std::list<DialogEvent> event_sequence) { |
573 event_observer_ = | 592 event_observer_ = |
574 base::MakeUnique<DialogEventObserver>(std::move(event_sequence)); | 593 base::MakeUnique<DialogEventObserver>(std::move(event_sequence)); |
575 } | 594 } |
576 | 595 |
577 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { | 596 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { |
578 event_observer_->Wait(); | 597 event_observer_->Wait(); |
579 } | 598 } |
580 | 599 |
581 } // namespace payments | 600 } // namespace payments |
OLD | NEW |