| 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 <iostream> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/command_line.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 20 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 24 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 24 #include "chrome/browser/ui/views/payments/validating_combobox.h" | 25 #include "chrome/browser/ui/views/payments/validating_combobox.h" |
| 25 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 26 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
| 26 #include "chrome/browser/ui/views/payments/view_stack.h" | 27 #include "chrome/browser/ui/views/payments/view_stack.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "components/autofill/core/browser/autofill_profile.h" | 29 #include "components/autofill/core/browser/autofill_profile.h" |
| 29 #include "components/autofill/core/browser/credit_card.h" | 30 #include "components/autofill/core/browser/credit_card.h" |
| 30 #include "components/autofill/core/browser/personal_data_manager.h" | 31 #include "components/autofill/core/browser/personal_data_manager.h" |
| 31 #include "components/payments/content/payment_request.h" | 32 #include "components/payments/content/payment_request.h" |
| 32 #include "components/payments/content/payment_request_web_contents_manager.h" | 33 #include "components/payments/content/payment_request_web_contents_manager.h" |
| 33 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 34 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 34 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
| 35 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/common/content_switches.h" |
| 36 #include "content/public/test/browser_test_utils.h" | 38 #include "content/public/test/browser_test_utils.h" |
| 39 #include "net/dns/mock_host_resolver.h" |
| 37 #include "services/service_manager/public/cpp/bind_source_info.h" | 40 #include "services/service_manager/public/cpp/bind_source_info.h" |
| 38 #include "services/service_manager/public/cpp/binder_registry.h" | 41 #include "services/service_manager/public/cpp/binder_registry.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "ui/base/test/ui_controls.h" | 43 #include "ui/base/test/ui_controls.h" |
| 41 #include "ui/events/base_event_utils.h" | 44 #include "ui/events/base_event_utils.h" |
| 42 #include "ui/events/event.h" | 45 #include "ui/events/event.h" |
| 43 #include "ui/gfx/animation/test_animation_delegate.h" | 46 #include "ui/gfx/animation/test_animation_delegate.h" |
| 44 #include "ui/gfx/geometry/point.h" | 47 #include "ui/gfx/geometry/point.h" |
| 45 #include "ui/views/controls/button/button.h" | 48 #include "ui/views/controls/button/button.h" |
| 46 #include "ui/views/controls/label.h" | 49 #include "ui/views/controls/label.h" |
| 47 #include "ui/views/controls/styled_label.h" | 50 #include "ui/views/controls/styled_label.h" |
| 48 | 51 |
| 49 namespace payments { | 52 namespace payments { |
| 50 | 53 |
| 51 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} | 54 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} |
| 52 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} | 55 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} |
| 53 | 56 |
| 54 PaymentRequestBrowserTestBase::PaymentRequestBrowserTestBase( | 57 PaymentRequestBrowserTestBase::PaymentRequestBrowserTestBase( |
| 55 const std::string& test_file_path) | 58 const std::string& test_file_path) |
| 56 : test_file_path_(test_file_path), | 59 : test_file_path_(test_file_path), |
| 57 delegate_(nullptr), | 60 delegate_(nullptr), |
| 58 is_incognito_(false), | 61 is_incognito_(false), |
| 59 is_valid_ssl_(true) {} | 62 is_valid_ssl_(true) {} |
| 60 PaymentRequestBrowserTestBase::~PaymentRequestBrowserTestBase() {} | 63 PaymentRequestBrowserTestBase::~PaymentRequestBrowserTestBase() {} |
| 61 | 64 |
| 65 void PaymentRequestBrowserTestBase::SetUpCommandLine( |
| 66 base::CommandLine* command_line) { |
| 67 // HTTPS server only serves a valid cert for localhost, so this is needed to |
| 68 // load pages from "a.com" without an interstitial. |
| 69 command_line->AppendSwitch(switches::kIgnoreCertificateErrors); |
| 70 } |
| 71 |
| 62 void PaymentRequestBrowserTestBase::SetUpOnMainThread() { | 72 void PaymentRequestBrowserTestBase::SetUpOnMainThread() { |
| 63 // Setup the https server. | 73 // Setup the https server. |
| 64 https_server_ = base::MakeUnique<net::EmbeddedTestServer>( | 74 https_server_ = base::MakeUnique<net::EmbeddedTestServer>( |
| 65 net::EmbeddedTestServer::TYPE_HTTPS); | 75 net::EmbeddedTestServer::TYPE_HTTPS); |
| 76 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 66 ASSERT_TRUE(https_server_->InitializeAndListen()); | 77 ASSERT_TRUE(https_server_->InitializeAndListen()); |
| 67 https_server_->ServeFilesFromSourceDirectory("chrome/test/data/payments"); | 78 https_server_->ServeFilesFromSourceDirectory("chrome/test/data/payments"); |
| 68 https_server_->StartAcceptingConnections(); | 79 https_server_->StartAcceptingConnections(); |
| 69 | 80 |
| 70 NavigateTo(test_file_path_); | 81 NavigateTo(test_file_path_); |
| 71 | 82 |
| 72 // Starting now, PaymentRequest Mojo messages sent by the renderer will | 83 // Starting now, PaymentRequest Mojo messages sent by the renderer will |
| 73 // create PaymentRequest objects via this test's CreatePaymentRequestForTest, | 84 // create PaymentRequest objects via this test's CreatePaymentRequestForTest, |
| 74 // allowing the test to inject itself as a dialog observer. | 85 // allowing the test to inject itself as a dialog observer. |
| 75 content::WebContents* web_contents = GetActiveWebContents(); | 86 content::WebContents* web_contents = GetActiveWebContents(); |
| 76 service_manager::BinderRegistry* registry = | 87 service_manager::BinderRegistry* registry = |
| 77 web_contents->GetMainFrame()->GetInterfaceRegistry(); | 88 web_contents->GetMainFrame()->GetInterfaceRegistry(); |
| 78 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); | 89 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); |
| 79 registry->AddInterface( | 90 registry->AddInterface( |
| 80 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest, | 91 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest, |
| 81 base::Unretained(this), web_contents)); | 92 base::Unretained(this), web_contents)); |
| 82 } | 93 } |
| 83 | 94 |
| 84 void PaymentRequestBrowserTestBase::NavigateTo(const std::string& file_path) { | 95 void PaymentRequestBrowserTestBase::NavigateTo(const std::string& file_path) { |
| 85 ui_test_utils::NavigateToURL(browser(), | 96 if (file_path.find("data:") == 0U) { |
| 86 file_path.find("data:") == 0U | 97 ui_test_utils::NavigateToURL(browser(), GURL(file_path)); |
| 87 ? GURL(file_path) | 98 } else { |
| 88 : https_server()->GetURL(file_path)); | 99 ui_test_utils::NavigateToURL(browser(), |
| 100 https_server()->GetURL("a.com", file_path)); |
| 101 } |
| 89 } | 102 } |
| 90 | 103 |
| 91 void PaymentRequestBrowserTestBase::SetIncognito() { | 104 void PaymentRequestBrowserTestBase::SetIncognito() { |
| 92 is_incognito_ = true; | 105 is_incognito_ = true; |
| 93 } | 106 } |
| 94 | 107 |
| 95 void PaymentRequestBrowserTestBase::SetInvalidSsl() { | 108 void PaymentRequestBrowserTestBase::SetInvalidSsl() { |
| 96 is_valid_ssl_ = false; | 109 is_valid_ssl_ = false; |
| 97 } | 110 } |
| 98 | 111 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 void PaymentRequestBrowserTestBase::CreatePaymentRequestForTest( | 420 void PaymentRequestBrowserTestBase::CreatePaymentRequestForTest( |
| 408 content::WebContents* web_contents, | 421 content::WebContents* web_contents, |
| 409 const service_manager::BindSourceInfo& source_info, | 422 const service_manager::BindSourceInfo& source_info, |
| 410 payments::mojom::PaymentRequestRequest request) { | 423 payments::mojom::PaymentRequestRequest request) { |
| 411 DCHECK(web_contents); | 424 DCHECK(web_contents); |
| 412 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = | 425 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = |
| 413 base::MakeUnique<TestChromePaymentRequestDelegate>( | 426 base::MakeUnique<TestChromePaymentRequestDelegate>( |
| 414 web_contents, this /* observer */, is_incognito_, is_valid_ssl_); | 427 web_contents, this /* observer */, is_incognito_, is_valid_ssl_); |
| 415 delegate_ = delegate.get(); | 428 delegate_ = delegate.get(); |
| 416 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) | 429 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) |
| 417 ->CreatePaymentRequest(web_contents, std::move(delegate), | 430 ->CreatePaymentRequest(web_contents->GetMainFrame(), web_contents, |
| 418 std::move(request), this); | 431 std::move(delegate), std::move(request), this); |
| 419 } | 432 } |
| 420 | 433 |
| 421 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( | 434 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( |
| 422 DialogViewID view_id, | 435 DialogViewID view_id, |
| 423 bool wait_for_animation) { | 436 bool wait_for_animation) { |
| 424 views::View* view = | 437 views::View* view = |
| 425 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id)); | 438 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id)); |
| 426 DCHECK(view); | 439 DCHECK(view); |
| 427 ClickOnDialogViewAndWait(view, wait_for_animation); | 440 ClickOnDialogViewAndWait(view, wait_for_animation); |
| 428 } | 441 } |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 break; | 734 break; |
| 722 case DialogEvent::CVC_PROMPT_SHOWN: | 735 case DialogEvent::CVC_PROMPT_SHOWN: |
| 723 out << "CVC_PROMPT_SHOWN"; | 736 out << "CVC_PROMPT_SHOWN"; |
| 724 break; | 737 break; |
| 725 case DialogEvent::NOT_SUPPORTED_ERROR: | 738 case DialogEvent::NOT_SUPPORTED_ERROR: |
| 726 out << "NOT_SUPPORTED_ERROR"; | 739 out << "NOT_SUPPORTED_ERROR"; |
| 727 break; | 740 break; |
| 728 } | 741 } |
| 729 return out; | 742 return out; |
| 730 } | 743 } |
| OLD | NEW |