Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 | 90 |
| 90 void PaymentRequestBrowserTestBase::SetIncognitoForTesting() { | 91 void PaymentRequestBrowserTestBase::SetIncognitoForTesting() { |
| 91 incognito_for_testing_ = true; | 92 incognito_for_testing_ = true; |
| 92 } | 93 } |
| 93 | 94 |
| 94 void PaymentRequestBrowserTestBase::OnCanMakePaymentCalled() { | 95 void PaymentRequestBrowserTestBase::OnCanMakePaymentCalled() { |
| 95 if (event_observer_) | 96 if (event_observer_) |
| 96 event_observer_->Observe(DialogEvent::CAN_MAKE_PAYMENT_CALLED); | 97 event_observer_->Observe(DialogEvent::CAN_MAKE_PAYMENT_CALLED); |
| 97 } | 98 } |
| 98 | 99 |
| 100 void PaymentRequestBrowserTestBase::OnNotSupportedError() { | |
| 101 if (event_observer_) | |
| 102 event_observer_->Observe(DialogEvent::NOT_SUPPORTED_ERROR); | |
| 103 } | |
| 104 | |
| 99 void PaymentRequestBrowserTestBase::OnDialogOpened() { | 105 void PaymentRequestBrowserTestBase::OnDialogOpened() { |
| 100 if (event_observer_) | 106 if (event_observer_) |
| 101 event_observer_->Observe(DialogEvent::DIALOG_OPENED); | 107 event_observer_->Observe(DialogEvent::DIALOG_OPENED); |
| 102 } | 108 } |
| 103 | 109 |
| 104 void PaymentRequestBrowserTestBase::OnOrderSummaryOpened() { | 110 void PaymentRequestBrowserTestBase::OnOrderSummaryOpened() { |
| 105 if (event_observer_) | 111 if (event_observer_) |
| 106 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); | 112 event_observer_->Observe(DialogEvent::ORDER_SUMMARY_OPENED); |
| 107 } | 113 } |
| 108 | 114 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 | 187 |
| 182 WaitForObservedEvent(); | 188 WaitForObservedEvent(); |
| 183 | 189 |
| 184 // The web-modal dialog should be open. | 190 // The web-modal dialog should be open. |
| 185 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 191 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 186 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 192 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 187 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 193 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 188 } | 194 } |
| 189 | 195 |
| 190 void PaymentRequestBrowserTestBase::ExpectBodyContains( | 196 void PaymentRequestBrowserTestBase::ExpectBodyContains( |
| 191 const std::vector<base::string16>& expected_strings) { | 197 const std::vector<std::string>& expected_strings) { |
| 192 content::WebContents* web_contents = GetActiveWebContents(); | 198 content::WebContents* web_contents = GetActiveWebContents(); |
| 193 const std::string extract_contents_js = | 199 const std::string extract_contents_js = |
| 194 "(function() { " | 200 "(function() { " |
| 195 "window.domAutomationController.send(window.document.body.textContent); " | 201 "window.domAutomationController.send(window.document.body.textContent); " |
| 196 "})()"; | 202 "})()"; |
| 197 std::string contents; | 203 std::string contents; |
| 198 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 204 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 199 web_contents, extract_contents_js, &contents)); | 205 web_contents, extract_contents_js, &contents)); |
| 200 for (const auto expected_string : expected_strings) { | 206 for (const auto& expected_string : expected_strings) { |
|
Mathieu
2017/04/17 03:20:45
Thanks :) let's use const std::string&
please use gerrit instead
2017/04/17 18:19:54
Done.
| |
| 201 EXPECT_NE(std::string::npos, | 207 EXPECT_NE(std::string::npos, contents.find(expected_string)) |
| 202 contents.find(base::UTF16ToUTF8(expected_string))) | |
| 203 << "String not present: " << expected_string; | 208 << "String not present: " << expected_string; |
| 204 } | 209 } |
| 205 } | 210 } |
| 206 | 211 |
| 212 void PaymentRequestBrowserTestBase::ExpectBodyContains( | |
| 213 const std::vector<base::string16>& expected_strings) { | |
| 214 std::vector<std::string> converted(expected_strings.size()); | |
| 215 std::transform(expected_strings.begin(), expected_strings.end(), | |
| 216 converted.begin(), | |
| 217 [](const base::string16& s) { return base::UTF16ToUTF8(s); }); | |
| 218 ExpectBodyContains(converted); | |
| 219 } | |
| 220 | |
| 207 void PaymentRequestBrowserTestBase::OpenOrderSummaryScreen() { | 221 void PaymentRequestBrowserTestBase::OpenOrderSummaryScreen() { |
| 208 ResetEventObserver(DialogEvent::ORDER_SUMMARY_OPENED); | 222 ResetEventObserver(DialogEvent::ORDER_SUMMARY_OPENED); |
| 209 | 223 |
| 210 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION); | 224 ClickOnDialogViewAndWait(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION); |
| 211 } | 225 } |
| 212 | 226 |
| 213 void PaymentRequestBrowserTestBase::OpenPaymentMethodScreen() { | 227 void PaymentRequestBrowserTestBase::OpenPaymentMethodScreen() { |
| 214 ResetEventObserver(DialogEvent::PAYMENT_METHOD_OPENED); | 228 ResetEventObserver(DialogEvent::PAYMENT_METHOD_OPENED); |
| 215 | 229 |
| 216 views::View* view = delegate_->dialog_view()->GetViewByID( | 230 views::View* view = delegate_->dialog_view()->GetViewByID( |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 std::list<DialogEvent> event_sequence) { | 586 std::list<DialogEvent> event_sequence) { |
| 573 event_observer_ = | 587 event_observer_ = |
| 574 base::MakeUnique<DialogEventObserver>(std::move(event_sequence)); | 588 base::MakeUnique<DialogEventObserver>(std::move(event_sequence)); |
| 575 } | 589 } |
| 576 | 590 |
| 577 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { | 591 void PaymentRequestBrowserTestBase::WaitForObservedEvent() { |
| 578 event_observer_->Wait(); | 592 event_observer_->Wait(); |
| 579 } | 593 } |
| 580 | 594 |
| 581 } // namespace payments | 595 } // namespace payments |
| OLD | NEW |