Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_browsertest_base.cc

Issue 2866623003: PaymentRequest.canMakePayment() query quota on desktop. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/command_line.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"
18 #include "chrome/browser/autofill/personal_data_manager_factory.h" 19 #include "chrome/browser/autofill/personal_data_manager_factory.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 23 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
23 #include "chrome/browser/ui/views/payments/validating_combobox.h" 24 #include "chrome/browser/ui/views/payments/validating_combobox.h"
24 #include "chrome/browser/ui/views/payments/validating_textfield.h" 25 #include "chrome/browser/ui/views/payments/validating_textfield.h"
25 #include "chrome/browser/ui/views/payments/view_stack.h" 26 #include "chrome/browser/ui/views/payments/view_stack.h"
26 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
27 #include "components/autofill/core/browser/autofill_profile.h" 28 #include "components/autofill/core/browser/autofill_profile.h"
28 #include "components/autofill/core/browser/credit_card.h" 29 #include "components/autofill/core/browser/credit_card.h"
29 #include "components/autofill/core/browser/personal_data_manager.h" 30 #include "components/autofill/core/browser/personal_data_manager.h"
30 #include "components/payments/content/payment_request.h" 31 #include "components/payments/content/payment_request.h"
31 #include "components/payments/content/payment_request_web_contents_manager.h" 32 #include "components/payments/content/payment_request_web_contents_manager.h"
32 #include "components/web_modal/web_contents_modal_dialog_manager.h" 33 #include "components/web_modal/web_contents_modal_dialog_manager.h"
33 #include "content/public/browser/render_frame_host.h" 34 #include "content/public/browser/render_frame_host.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "content/public/common/content_switches.h"
35 #include "content/public/test/browser_test_utils.h" 37 #include "content/public/test/browser_test_utils.h"
38 #include "net/dns/mock_host_resolver.h"
36 #include "services/service_manager/public/cpp/bind_source_info.h" 39 #include "services/service_manager/public/cpp/bind_source_info.h"
37 #include "services/service_manager/public/cpp/binder_registry.h" 40 #include "services/service_manager/public/cpp/binder_registry.h"
38 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
39 #include "ui/base/test/ui_controls.h" 42 #include "ui/base/test/ui_controls.h"
40 #include "ui/events/base_event_utils.h" 43 #include "ui/events/base_event_utils.h"
41 #include "ui/events/event.h" 44 #include "ui/events/event.h"
42 #include "ui/gfx/animation/test_animation_delegate.h" 45 #include "ui/gfx/animation/test_animation_delegate.h"
43 #include "ui/gfx/geometry/point.h" 46 #include "ui/gfx/geometry/point.h"
44 #include "ui/views/controls/button/button.h" 47 #include "ui/views/controls/button/button.h"
45 #include "ui/views/controls/label.h" 48 #include "ui/views/controls/label.h"
46 #include "ui/views/controls/styled_label.h" 49 #include "ui/views/controls/styled_label.h"
47 50
48 namespace payments { 51 namespace payments {
49 52
50 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {} 53 PersonalDataLoadedObserverMock::PersonalDataLoadedObserverMock() {}
51 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {} 54 PersonalDataLoadedObserverMock::~PersonalDataLoadedObserverMock() {}
52 55
53 PaymentRequestBrowserTestBase::PaymentRequestBrowserTestBase( 56 PaymentRequestBrowserTestBase::PaymentRequestBrowserTestBase(
54 const std::string& test_file_path) 57 const std::string& test_file_path)
55 : test_file_path_(test_file_path), 58 : test_file_path_(test_file_path),
56 delegate_(nullptr), 59 delegate_(nullptr),
57 is_incognito_(false), 60 is_incognito_(false),
58 is_valid_ssl_(true) {} 61 is_valid_ssl_(true) {}
59 PaymentRequestBrowserTestBase::~PaymentRequestBrowserTestBase() {} 62 PaymentRequestBrowserTestBase::~PaymentRequestBrowserTestBase() {}
60 63
64 void PaymentRequestBrowserTestBase::SetUpCommandLine(
65 base::CommandLine* command_line) {
66 // HTTPS server only serves a valid cert for localhost, so this is needed to
67 // load pages from "a.com" without an interstitial.
68 command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
69 }
70
61 void PaymentRequestBrowserTestBase::SetUpOnMainThread() { 71 void PaymentRequestBrowserTestBase::SetUpOnMainThread() {
62 // Setup the https server. 72 // Setup the https server.
63 https_server_ = base::MakeUnique<net::EmbeddedTestServer>( 73 https_server_ = base::MakeUnique<net::EmbeddedTestServer>(
64 net::EmbeddedTestServer::TYPE_HTTPS); 74 net::EmbeddedTestServer::TYPE_HTTPS);
75 host_resolver()->AddRule("a.com", "127.0.0.1");
65 ASSERT_TRUE(https_server_->InitializeAndListen()); 76 ASSERT_TRUE(https_server_->InitializeAndListen());
66 https_server_->ServeFilesFromSourceDirectory("chrome/test/data/payments"); 77 https_server_->ServeFilesFromSourceDirectory("chrome/test/data/payments");
67 https_server_->StartAcceptingConnections(); 78 https_server_->StartAcceptingConnections();
68 79
69 NavigateTo(test_file_path_); 80 NavigateTo(test_file_path_);
70 81
71 // Starting now, PaymentRequest Mojo messages sent by the renderer will 82 // Starting now, PaymentRequest Mojo messages sent by the renderer will
72 // create PaymentRequest objects via this test's CreatePaymentRequestForTest, 83 // create PaymentRequest objects via this test's CreatePaymentRequestForTest,
73 // allowing the test to inject itself as a dialog observer. 84 // allowing the test to inject itself as a dialog observer.
74 content::WebContents* web_contents = GetActiveWebContents(); 85 content::WebContents* web_contents = GetActiveWebContents();
75 service_manager::BinderRegistry* registry = 86 service_manager::BinderRegistry* registry =
76 web_contents->GetMainFrame()->GetInterfaceRegistry(); 87 web_contents->GetMainFrame()->GetInterfaceRegistry();
77 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_); 88 registry->RemoveInterface(payments::mojom::PaymentRequest::Name_);
78 registry->AddInterface( 89 registry->AddInterface(
79 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest, 90 base::Bind(&PaymentRequestBrowserTestBase::CreatePaymentRequestForTest,
80 base::Unretained(this), web_contents)); 91 base::Unretained(this), web_contents));
81 } 92 }
82 93
83 void PaymentRequestBrowserTestBase::NavigateTo(const std::string& file_path) { 94 void PaymentRequestBrowserTestBase::NavigateTo(const std::string& file_path) {
84 ui_test_utils::NavigateToURL(browser(), https_server()->GetURL(file_path)); 95 ui_test_utils::NavigateToURL(browser(),
96 https_server()->GetURL("a.com", file_path));
85 } 97 }
86 98
87 void PaymentRequestBrowserTestBase::SetIncognito() { 99 void PaymentRequestBrowserTestBase::SetIncognito() {
88 is_incognito_ = true; 100 is_incognito_ = true;
89 } 101 }
90 102
91 void PaymentRequestBrowserTestBase::SetInvalidSsl() { 103 void PaymentRequestBrowserTestBase::SetInvalidSsl() {
92 is_valid_ssl_ = false; 104 is_valid_ssl_ = false;
93 } 105 }
94 106
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 content::WebContents* web_contents, 415 content::WebContents* web_contents,
404 const service_manager::BindSourceInfo& source_info, 416 const service_manager::BindSourceInfo& source_info,
405 payments::mojom::PaymentRequestRequest request) { 417 payments::mojom::PaymentRequestRequest request) {
406 DCHECK(web_contents); 418 DCHECK(web_contents);
407 std::unique_ptr<TestChromePaymentRequestDelegate> delegate = 419 std::unique_ptr<TestChromePaymentRequestDelegate> delegate =
408 base::MakeUnique<TestChromePaymentRequestDelegate>( 420 base::MakeUnique<TestChromePaymentRequestDelegate>(
409 web_contents, this /* observer */, this /* widget_observer */, 421 web_contents, this /* observer */, this /* widget_observer */,
410 is_incognito_, is_valid_ssl_); 422 is_incognito_, is_valid_ssl_);
411 delegate_ = delegate.get(); 423 delegate_ = delegate.get();
412 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) 424 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents)
413 ->CreatePaymentRequest(web_contents, std::move(delegate), 425 ->CreatePaymentRequest(web_contents->GetMainFrame(), web_contents,
414 std::move(request), this); 426 std::move(delegate), std::move(request), this);
415 } 427 }
416 428
417 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait( 429 void PaymentRequestBrowserTestBase::ClickOnDialogViewAndWait(
418 DialogViewID view_id, 430 DialogViewID view_id,
419 bool wait_for_animation) { 431 bool wait_for_animation) {
420 views::View* view = 432 views::View* view =
421 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id)); 433 delegate_->dialog_view()->GetViewByID(static_cast<int>(view_id));
422 DCHECK(view); 434 DCHECK(view);
423 ClickOnDialogViewAndWait(view, wait_for_animation); 435 ClickOnDialogViewAndWait(view, wait_for_animation);
424 } 436 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 std::list<DialogEvent> event_sequence) { 666 std::list<DialogEvent> event_sequence) {
655 event_observer_ = 667 event_observer_ =
656 base::MakeUnique<DialogEventObserver>(std::move(event_sequence)); 668 base::MakeUnique<DialogEventObserver>(std::move(event_sequence));
657 } 669 }
658 670
659 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { 671 void PaymentRequestBrowserTestBase::WaitForObservedEvent() {
660 event_observer_->Wait(); 672 event_observer_->Wait();
661 } 673 }
662 674
663 } // namespace payments 675 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698