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

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

Issue 2649683002: [Payments] Improve the closing of the PR dialog. (Closed)
Patch Set: addressed comments from sky Created 3 years, 11 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_interactive_uitest_ba se.h" 5 #include "chrome/browser/ui/views/payments/payment_request_interactive_uitest_ba se.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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 registry->AddInterface(base::Bind( 56 registry->AddInterface(base::Bind(
57 &PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest, 57 &PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest,
58 base::Unretained(this), web_contents)); 58 base::Unretained(this), web_contents));
59 } 59 }
60 60
61 void PaymentRequestInteractiveTestBase::OnDialogOpened() { 61 void PaymentRequestInteractiveTestBase::OnDialogOpened() {
62 if (event_observer_) 62 if (event_observer_)
63 event_observer_->Observe(DialogEvent::DIALOG_OPENED); 63 event_observer_->Observe(DialogEvent::DIALOG_OPENED);
64 } 64 }
65 65
66 void PaymentRequestInteractiveTestBase::OnWidgetDestroyed(
67 views::Widget* widget) {
68 if (event_observer_)
69 event_observer_->Observe(DialogEvent::DIALOG_CLOSED);
70 }
71
66 void PaymentRequestInteractiveTestBase::InvokePaymentRequestUI() { 72 void PaymentRequestInteractiveTestBase::InvokePaymentRequestUI() {
67 event_observer_.reset(new DialogEventObserver(DialogEvent::DIALOG_OPENED)); 73 event_observer_.reset(new DialogEventObserver(DialogEvent::DIALOG_OPENED));
68 74
69 content::WebContents* web_contents = GetActiveWebContents(); 75 content::WebContents* web_contents = GetActiveWebContents();
70 const std::string click_buy_button_js = 76 const std::string click_buy_button_js =
71 "(function() { document.getElementById('buy').click(); })();"; 77 "(function() { document.getElementById('buy').click(); })();";
72 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js)); 78 ASSERT_TRUE(content::ExecuteScript(web_contents, click_buy_button_js));
73 79
74 event_observer_->Wait(); 80 event_observer_->Wait();
75 81
(...skipping 20 matching lines...) Expand all
96 for (const auto& p : manager->payment_requests_) 102 for (const auto& p : manager->payment_requests_)
97 payment_requests_ptrs.push_back(p.first); 103 payment_requests_ptrs.push_back(p.first);
98 return payment_requests_ptrs; 104 return payment_requests_ptrs;
99 } 105 }
100 106
101 void PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest( 107 void PaymentRequestInteractiveTestBase::CreatePaymentRequestForTest(
102 content::WebContents* web_contents, 108 content::WebContents* web_contents,
103 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) { 109 mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) {
104 DCHECK(web_contents); 110 DCHECK(web_contents);
105 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents) 111 PaymentRequestWebContentsManager::GetOrCreateForWebContents(web_contents)
106 ->CreatePaymentRequest(web_contents, 112 ->CreatePaymentRequest(
107 base::MakeUnique<TestChromePaymentRequestDelegate>( 113 web_contents,
108 web_contents, this /* observer */), 114 base::MakeUnique<TestChromePaymentRequestDelegate>(
109 std::move(request)); 115 web_contents, this /* observer */, this /* widget_observer */),
116 std::move(request));
110 } 117 }
111 118
112 PaymentRequestInteractiveTestBase::DialogEventObserver::DialogEventObserver( 119 PaymentRequestInteractiveTestBase::DialogEventObserver::DialogEventObserver(
113 PaymentRequestInteractiveTestBase::DialogEvent event) 120 PaymentRequestInteractiveTestBase::DialogEvent event)
114 : event_(event), seen_(false) {} 121 : event_(event), seen_(false) {}
115 PaymentRequestInteractiveTestBase::DialogEventObserver::~DialogEventObserver() { 122 PaymentRequestInteractiveTestBase::DialogEventObserver::~DialogEventObserver() {
116 } 123 }
117 124
118 void PaymentRequestInteractiveTestBase::DialogEventObserver::Wait() { 125 void PaymentRequestInteractiveTestBase::DialogEventObserver::Wait() {
119 if (seen_) 126 if (seen_)
120 return; 127 return;
121 128
122 DCHECK(!run_loop_.running()); 129 DCHECK(!run_loop_.running());
123 run_loop_.Run(); 130 run_loop_.Run();
124 } 131 }
125 132
126 void PaymentRequestInteractiveTestBase::DialogEventObserver::Observe( 133 void PaymentRequestInteractiveTestBase::DialogEventObserver::Observe(
127 PaymentRequestInteractiveTestBase::DialogEvent event) { 134 PaymentRequestInteractiveTestBase::DialogEvent event) {
135 if (seen_)
136 return;
137
138 DCHECK_EQ(event_, event);
128 seen_ = true; 139 seen_ = true;
129 if (event == event_ && run_loop_.running()) 140 if (run_loop_.running())
130 run_loop_.Quit(); 141 run_loop_.Quit();
131 } 142 }
132 143
144 void PaymentRequestInteractiveTestBase::ResetEventObserver(DialogEvent event) {
145 event_observer_.reset(new DialogEventObserver(event));
146 }
147
148 void PaymentRequestInteractiveTestBase::WaitForObservedEvent() {
149 event_observer_->Wait();
150 }
151
133 } // namespace payments 152 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698