Commit ec5f3f8a authored by Nick Burris's avatar Nick Burris Committed by Commit Bot

[SecurePaymentConfirmation] Add body view

Add the body view to complete the secure payment confirmation UI. This
patch adds the title text and the merchant, instrument, and total rows.

Bug: 1110322
Change-Id: Ied9d2c36cf3581108f811d82aab73c207c37dbd3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2365364
Commit-Queue: Nick Burris <nburris@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800280}
parent 5e79d681
...@@ -36,7 +36,19 @@ class SecurePaymentConfirmationDialogView ...@@ -36,7 +36,19 @@ class SecurePaymentConfirmationDialogView
// IDs that identify a view within the secure payment confirmation dialog. // IDs that identify a view within the secure payment confirmation dialog.
// Used to validate views in browsertests. // Used to validate views in browsertests.
enum DialogViewID : int { VIEW_ID_NONE = 0, HEADER_ICON, PROGRESS_BAR }; enum class DialogViewID : int {
VIEW_ID_NONE = 0,
HEADER_ICON,
PROGRESS_BAR,
TITLE,
MERCHANT_LABEL,
MERCHANT_VALUE,
INSTRUMENT_LABEL,
INSTRUMENT_VALUE,
INSTRUMENT_ICON,
TOTAL_LABEL,
TOTAL_VALUE
};
explicit SecurePaymentConfirmationDialogView( explicit SecurePaymentConfirmationDialogView(
ObserverForTest* observer_for_test); ObserverForTest* observer_for_test);
...@@ -68,6 +80,17 @@ class SecurePaymentConfirmationDialogView ...@@ -68,6 +80,17 @@ class SecurePaymentConfirmationDialogView
void InitChildViews(); void InitChildViews();
std::unique_ptr<views::View> CreateHeaderView(); std::unique_ptr<views::View> CreateHeaderView();
std::unique_ptr<views::View> CreateBodyView();
std::unique_ptr<views::View> CreateRows();
std::unique_ptr<views::View> CreateRowView(
const base::string16& label,
DialogViewID label_id,
const base::string16& value,
DialogViewID value_id,
const SkBitmap* icon = nullptr,
DialogViewID icon_id = DialogViewID::VIEW_ID_NONE);
void UpdateLabelView(DialogViewID id, const base::string16& text);
// May be null. // May be null.
ObserverForTest* observer_for_test_ = nullptr; ObserverForTest* observer_for_test_ = nullptr;
...@@ -77,6 +100,13 @@ class SecurePaymentConfirmationDialogView ...@@ -77,6 +100,13 @@ class SecurePaymentConfirmationDialogView
views::ProgressBar* progress_bar_ = nullptr; views::ProgressBar* progress_bar_ = nullptr;
// Cache the instrument icon pointer so we don't needlessly update it in
// OnModelUpdated().
const SkBitmap* instrument_icon_ = nullptr;
// Cache the instrument icon generation ID to check if the instrument_icon_
// has changed pixels.
uint32_t instrument_icon_generation_id_ = 0;
base::WeakPtrFactory<SecurePaymentConfirmationDialogView> weak_ptr_factory_{ base::WeakPtrFactory<SecurePaymentConfirmationDialogView> weak_ptr_factory_{
this}; this};
}; };
......
...@@ -13,8 +13,23 @@ ...@@ -13,8 +13,23 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
namespace payments { namespace payments {
namespace {
constexpr int kInstrumentIconWidth = 32;
constexpr int kInstrumentIconHeight = 20;
const SkBitmap CreateInstrumentIcon(SkColor color) {
SkBitmap bitmap;
bitmap.allocN32Pixels(kInstrumentIconWidth, kInstrumentIconHeight);
bitmap.eraseColor(color);
return bitmap;
}
} // namespace
class SecurePaymentConfirmationDialogViewTest class SecurePaymentConfirmationDialogViewTest
: public InProcessBrowserTest, : public InProcessBrowserTest,
...@@ -30,6 +45,24 @@ class SecurePaymentConfirmationDialogViewTest ...@@ -30,6 +45,24 @@ class SecurePaymentConfirmationDialogViewTest
} }
void CreateModel() { void CreateModel() {
model_.set_title(l10n_util::GetStringUTF16(
IDS_SECURE_PAYMENT_CONFIRMATION_VERIFY_PURCHASE));
model_.set_merchant_label(
l10n_util::GetStringUTF16(IDS_SECURE_PAYMENT_CONFIRMATION_STORE_LABEL));
model_.set_merchant_value(base::UTF8ToUTF16("merchant.com"));
model_.set_instrument_label(l10n_util::GetStringUTF16(
IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME));
model_.set_instrument_value(base::UTF8ToUTF16("Mastercard ****4444"));
instrument_icon_ =
std::make_unique<SkBitmap>(CreateInstrumentIcon(SK_ColorBLUE));
model_.set_instrument_icon(instrument_icon_.get());
model_.set_total_label(
l10n_util::GetStringUTF16(IDS_SECURE_PAYMENT_CONFIRMATION_TOTAL_LABEL));
model_.set_total_value(base::UTF8ToUTF16("$20.00 USD"));
model_.set_verify_button_label(l10n_util::GetStringUTF16( model_.set_verify_button_label(l10n_util::GetStringUTF16(
IDS_SECURE_PAYMENT_CONFIRMATION_VERIFY_BUTTON_LABEL)); IDS_SECURE_PAYMENT_CONFIRMATION_VERIFY_BUTTON_LABEL));
model_.set_cancel_button_label(l10n_util::GetStringUTF16(IDS_CANCEL)); model_.set_cancel_button_label(l10n_util::GetStringUTF16(IDS_CANCEL));
...@@ -54,6 +87,15 @@ class SecurePaymentConfirmationDialogViewTest ...@@ -54,6 +87,15 @@ class SecurePaymentConfirmationDialogViewTest
EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
} }
void ExpectLabelText(
const base::string16& text,
SecurePaymentConfirmationDialogView::DialogViewID view_id) {
EXPECT_EQ(text, static_cast<views::Label*>(
test_delegate_->dialog_view()->GetViewByID(
static_cast<int>(view_id)))
->GetText());
}
void ExpectViewMatchesModel() { void ExpectViewMatchesModel() {
ASSERT_NE(test_delegate_->dialog_view(), nullptr); ASSERT_NE(test_delegate_->dialog_view(), nullptr);
...@@ -65,15 +107,50 @@ class SecurePaymentConfirmationDialogViewTest ...@@ -65,15 +107,50 @@ class SecurePaymentConfirmationDialogViewTest
test_delegate_->dialog_view()->GetDialogButtonLabel( test_delegate_->dialog_view()->GetDialogButtonLabel(
ui::DIALOG_BUTTON_CANCEL)); ui::DIALOG_BUTTON_CANCEL));
EXPECT_TRUE(test_delegate_->dialog_view()->GetViewByID( EXPECT_TRUE(test_delegate_->dialog_view()->GetViewByID(static_cast<int>(
SecurePaymentConfirmationDialogView::DialogViewID::HEADER_ICON)); SecurePaymentConfirmationDialogView::DialogViewID::HEADER_ICON)));
EXPECT_EQ( EXPECT_EQ(
model_.progress_bar_visible(), model_.progress_bar_visible(),
test_delegate_->dialog_view() test_delegate_->dialog_view()
->GetViewByID( ->GetViewByID(static_cast<int>(SecurePaymentConfirmationDialogView::
SecurePaymentConfirmationDialogView::DialogViewID::PROGRESS_BAR) DialogViewID::PROGRESS_BAR))
->GetVisible()); ->GetVisible());
ExpectLabelText(model_.title(),
SecurePaymentConfirmationDialogView::DialogViewID::TITLE);
ExpectLabelText(
model_.merchant_label(),
SecurePaymentConfirmationDialogView::DialogViewID::MERCHANT_LABEL);
ExpectLabelText(
model_.merchant_value(),
SecurePaymentConfirmationDialogView::DialogViewID::MERCHANT_VALUE);
ExpectLabelText(
model_.instrument_label(),
SecurePaymentConfirmationDialogView::DialogViewID::INSTRUMENT_LABEL);
ExpectLabelText(
model_.instrument_value(),
SecurePaymentConfirmationDialogView::DialogViewID::INSTRUMENT_VALUE);
ASSERT_EQ(instrument_icon_.get(), model_.instrument_icon());
EXPECT_TRUE(cc::MatchesBitmap(
*model_.instrument_icon(),
*(static_cast<views::ImageView*>(
test_delegate_->dialog_view()->GetViewByID(
static_cast<int>(SecurePaymentConfirmationDialogView::
DialogViewID::INSTRUMENT_ICON)))
->GetImage()
.bitmap()),
cc::ExactPixelComparator(/*discard_alpha=*/false)));
ExpectLabelText(
model_.total_label(),
SecurePaymentConfirmationDialogView::DialogViewID::TOTAL_LABEL);
ExpectLabelText(
model_.total_value(),
SecurePaymentConfirmationDialogView::DialogViewID::TOTAL_VALUE);
} }
void ClickAcceptAndWait() { void ClickAcceptAndWait() {
...@@ -133,6 +210,8 @@ class SecurePaymentConfirmationDialogViewTest ...@@ -133,6 +210,8 @@ class SecurePaymentConfirmationDialogViewTest
std::unique_ptr<TestSecurePaymentConfirmationPaymentRequestDelegate> std::unique_ptr<TestSecurePaymentConfirmationPaymentRequestDelegate>
test_delegate_; test_delegate_;
std::unique_ptr<SkBitmap> instrument_icon_;
bool confirm_pressed_ = false; bool confirm_pressed_ = false;
bool cancel_pressed_ = false; bool cancel_pressed_ = false;
}; };
...@@ -200,4 +279,54 @@ IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest, ...@@ -200,4 +279,54 @@ IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
CloseDialogAndWait(); CloseDialogAndWait();
} }
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
OnModelUpdated) {
CreateModel();
InvokeSecurePaymentConfirmationUI();
ExpectViewMatchesModel();
model_.set_title(base::UTF8ToUTF16("Test Title"));
model_.set_merchant_label(base::UTF8ToUTF16("Test merchant"));
model_.set_merchant_value(base::UTF8ToUTF16("Test merchant value"));
model_.set_instrument_label(base::UTF8ToUTF16("Test instrument"));
model_.set_instrument_value(base::UTF8ToUTF16("Test instrument value"));
model_.set_total_label(base::UTF8ToUTF16("Test total"));
model_.set_total_value(base::UTF8ToUTF16("Test total value"));
model_.set_verify_button_label(base::UTF8ToUTF16("Test verify"));
model_.set_cancel_button_label(base::UTF8ToUTF16("Test cancel"));
test_delegate_->dialog_view()->OnModelUpdated();
ExpectViewMatchesModel();
CloseDialogAndWait();
}
// Test the two reasons an instrument icon is updated: The model's bitmap
// pointer changed, or the bitmap itself changed.
IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationDialogViewTest,
InstrumentIconUpdated) {
CreateModel();
InvokeSecurePaymentConfirmationUI();
ExpectViewMatchesModel();
// Change the bitmap pointer
instrument_icon_ =
std::make_unique<SkBitmap>(CreateInstrumentIcon(SK_ColorGREEN));
model_.set_instrument_icon(instrument_icon_.get());
test_delegate_->dialog_view()->OnModelUpdated();
ExpectViewMatchesModel();
// Change the bitmap itself without touching the model's pointer
*instrument_icon_ = CreateInstrumentIcon(SK_ColorRED);
test_delegate_->dialog_view()->OnModelUpdated();
ExpectViewMatchesModel();
CloseDialogAndWait();
}
} // namespace payments } // namespace payments
...@@ -34,6 +34,19 @@ void SecurePaymentConfirmationController::ShowDialog( ...@@ -34,6 +34,19 @@ void SecurePaymentConfirmationController::ShowDialog(
model_.set_cancel_button_label(l10n_util::GetStringUTF16(IDS_CANCEL)); model_.set_cancel_button_label(l10n_util::GetStringUTF16(IDS_CANCEL));
model_.set_progress_bar_visible(false); model_.set_progress_bar_visible(false);
model_.set_title(l10n_util::GetStringUTF16(
IDS_SECURE_PAYMENT_CONFIRMATION_VERIFY_PURCHASE));
// TODO(crbug/1110322): Set the field values based on |request|.
model_.set_merchant_label(
l10n_util::GetStringUTF16(IDS_SECURE_PAYMENT_CONFIRMATION_STORE_LABEL));
model_.set_instrument_label(l10n_util::GetStringUTF16(
IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME));
model_.set_total_label(
l10n_util::GetStringUTF16(IDS_SECURE_PAYMENT_CONFIRMATION_TOTAL_LABEL));
view_->ShowDialog( view_->ShowDialog(
request->web_contents(), model_.GetWeakPtr(), request->web_contents(), model_.GetWeakPtr(),
base::BindOnce(&SecurePaymentConfirmationController::OnConfirm, base::BindOnce(&SecurePaymentConfirmationController::OnConfirm,
......
...@@ -126,7 +126,7 @@ class SecurePaymentConfirmationModel { ...@@ -126,7 +126,7 @@ class SecurePaymentConfirmationModel {
base::string16 instrument_label_; base::string16 instrument_label_;
base::string16 instrument_value_; base::string16 instrument_value_;
const SkBitmap* instrument_icon_; const SkBitmap* instrument_icon_ = nullptr;
base::string16 total_label_; base::string16 total_label_;
base::string16 total_value_; base::string16 total_value_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment