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

[SecurePaymentConfirmation] Create the SecurePaymentConfirmationModel

This patch adds the model for the secure payment confirmation UI. This
model holds all of the cross-platform data to be displayed in the UI.

Bug: 1110322
Change-Id: I4bc041b3712e7795028f37dcd8d883a4aee0d32b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333211Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Nick Burris <nburris@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795590}
parent 3f1ce093
......@@ -73,6 +73,8 @@ static_library("content") {
"payment_response_helper.h",
"secure_payment_confirmation_controller.cc",
"secure_payment_confirmation_controller.h",
"secure_payment_confirmation_model.cc",
"secure_payment_confirmation_model.h",
"secure_payment_confirmation_payment_request_delegate.cc",
"secure_payment_confirmation_payment_request_delegate.h",
]
......@@ -150,6 +152,7 @@ source_set("unit_tests") {
"payment_request_spec_unittest.cc",
"payment_request_state_unittest.cc",
"payment_response_helper_unittest.cc",
"secure_payment_confirmation_model_unittest.cc",
"service_worker_payment_app_unittest.cc",
]
}
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/payments/content/secure_payment_confirmation_model.h"
namespace payments {
SecurePaymentConfirmationModel::SecurePaymentConfirmationModel() = default;
SecurePaymentConfirmationModel::~SecurePaymentConfirmationModel() = default;
} // namespace payments
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_MODEL_H_
#define COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_MODEL_H_
#include "base/strings/string16.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace gfx {
struct VectorIcon;
}
namespace payments {
// The data model for the secure payment confirmation flow. Owned by the
// SecurePaymentConfirmationController.
class SecurePaymentConfirmationModel {
public:
SecurePaymentConfirmationModel();
~SecurePaymentConfirmationModel();
// Disallow copy and assign.
SecurePaymentConfirmationModel(const SecurePaymentConfirmationModel& other) =
delete;
SecurePaymentConfirmationModel& operator=(
const SecurePaymentConfirmationModel& other) = delete;
// The header icon to be displayed, e.g. a fingerprint icon.
const gfx::VectorIcon* header_icon() const { return header_icon_; }
void set_header_icon(const gfx::VectorIcon* header_icon) {
header_icon_ = header_icon;
}
// Title, e.g. "Use TouchID to verify and complete your purchase?"
const base::string16& title() const { return title_; }
void set_title(const base::string16& title) { title_ = title; }
// Label for the merchant row, e.g. "Store".
const base::string16& merchant_label() const { return merchant_label_; }
void set_merchant_label(const base::string16& merchant_label) {
merchant_label_ = merchant_label;
}
// Label for the merchant row value, e.g. "merchant.com"
const base::string16& merchant_value() const { return merchant_value_; }
void set_merchant_value(const base::string16& merchant_value) {
merchant_value_ = merchant_value;
}
// Label for the instrument row, e.g. "Payment".
const base::string16& instrument_label() const { return instrument_label_; }
void set_instrument_label(const base::string16& instrument_label) {
instrument_label_ = instrument_label;
}
// Label for the instrument row value, e.g. "Mastercard ****4444"
const base::string16& instrument_value() const { return instrument_value_; }
void set_instrument_value(const base::string16& instrument_value) {
instrument_value_ = instrument_value;
}
// Instrument icon.
const SkBitmap* instrument_icon() const { return instrument_icon_; }
void set_instrument_icon(const SkBitmap* instrument_icon) {
instrument_icon_ = instrument_icon;
}
// Label for the total row, e.g. "Total".
const base::string16& total_label() const { return total_label_; }
void set_total_label(const base::string16& total_label) {
total_label_ = total_label;
}
// Label for the total row value, e.g. "$20.00 USD"
const base::string16& total_value() const { return total_value_; }
void set_total_value(const base::string16& total_value) {
total_value_ = total_value;
}
// Label for the verify button, e.g. "Verify".
const base::string16& verify_button_label() const {
return verify_button_label_;
}
void set_verify_button_label(const base::string16& verify_button_label) {
verify_button_label_ = verify_button_label;
}
// Label for the cancel button, e.g. "Cancel".
const base::string16& cancel_button_label() const {
return cancel_button_label_;
}
void set_cancel_button_label(const base::string16& cancel_button_label) {
cancel_button_label_ = cancel_button_label;
}
// Progress bar visibility.
bool progress_bar_visible() const { return progress_bar_visible_; }
void set_progress_bar_visible(bool progress_bar_visible) {
progress_bar_visible_ = progress_bar_visible;
}
// Verify button enabled state.
bool verify_button_enabled() const { return verify_button_enabled_; }
void set_verify_button_enabled(bool verify_button_enabled) {
verify_button_enabled_ = verify_button_enabled;
}
// Verify button visibility.
bool verify_button_visible() const { return verify_button_visible_; }
void set_verify_button_visible(bool verify_button_visible) {
verify_button_visible_ = verify_button_visible;
}
// Cancel button enabled state.
bool cancel_button_enabled() const { return cancel_button_enabled_; }
void set_cancel_button_enabled(bool cancel_button_enabled) {
cancel_button_enabled_ = cancel_button_enabled;
}
// Cancel button visibility.
bool cancel_button_visible() const { return cancel_button_visible_; }
void set_cancel_button_visible(bool cancel_button_visible) {
cancel_button_visible_ = cancel_button_visible;
}
private:
const gfx::VectorIcon* header_icon_ = nullptr;
base::string16 title_;
base::string16 merchant_label_;
base::string16 merchant_value_;
base::string16 instrument_label_;
base::string16 instrument_value_;
const SkBitmap* instrument_icon_;
base::string16 total_label_;
base::string16 total_value_;
base::string16 verify_button_label_;
base::string16 cancel_button_label_;
bool progress_bar_visible_ = false;
bool verify_button_enabled_ = true;
bool verify_button_visible_ = true;
bool cancel_button_enabled_ = true;
bool cancel_button_visible_ = true;
};
} // namespace payments
#endif // COMPONENTS_PAYMENTS_CONTENT_SECURE_PAYMENT_CONFIRMATION_MODEL_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/payments/content/secure_payment_confirmation_model.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/vector_icon_types.h"
namespace payments {
class SecurePaymentConfirmationModelTest : public testing::Test {};
TEST_F(SecurePaymentConfirmationModelTest, SmokeTest) {
SecurePaymentConfirmationModel model;
gfx::VectorIcon header_icon;
base::string16 title(
base::UTF8ToUTF16("Use Touch ID to verify and complete your purchase?"));
base::string16 merchant_label(base::UTF8ToUTF16("Store"));
base::string16 merchant_value(base::UTF8ToUTF16("merchant.com"));
base::string16 instrument_label(base::UTF8ToUTF16("Payment"));
base::string16 instrument_value(base::UTF8ToUTF16("Mastercard ****4444"));
SkBitmap instrument_icon;
base::string16 total_label(base::UTF8ToUTF16("Total"));
base::string16 total_value(base::UTF8ToUTF16("$20.00 USD"));
base::string16 verify_button_label(base::UTF8ToUTF16("Verify"));
base::string16 cancel_button_label(base::UTF8ToUTF16("Cancel"));
model.set_header_icon(&header_icon);
EXPECT_EQ(model.header_icon(), &header_icon);
model.set_title(title);
EXPECT_EQ(title, model.title());
model.set_merchant_label(merchant_label);
EXPECT_EQ(merchant_label, model.merchant_label());
model.set_merchant_value(merchant_value);
EXPECT_EQ(merchant_value, model.merchant_value());
model.set_instrument_label(instrument_label);
EXPECT_EQ(instrument_label, model.instrument_label());
model.set_instrument_value(instrument_value);
EXPECT_EQ(instrument_value, model.instrument_value());
model.set_instrument_icon(&instrument_icon);
EXPECT_EQ(&instrument_icon, model.instrument_icon());
model.set_total_label(total_label);
EXPECT_EQ(total_label, model.total_label());
model.set_total_value(total_value);
EXPECT_EQ(total_value, model.total_value());
model.set_verify_button_label(verify_button_label);
EXPECT_EQ(verify_button_label, model.verify_button_label());
model.set_cancel_button_label(cancel_button_label);
EXPECT_EQ(cancel_button_label, model.cancel_button_label());
// Default values for visibility and enabled states
EXPECT_FALSE(model.progress_bar_visible());
EXPECT_TRUE(model.verify_button_enabled());
EXPECT_TRUE(model.verify_button_visible());
EXPECT_TRUE(model.cancel_button_enabled());
EXPECT_TRUE(model.cancel_button_visible());
model.set_progress_bar_visible(true);
model.set_verify_button_enabled(false);
model.set_verify_button_visible(false);
model.set_cancel_button_enabled(false);
model.set_cancel_button_visible(false);
EXPECT_TRUE(model.progress_bar_visible());
EXPECT_FALSE(model.verify_button_enabled());
EXPECT_FALSE(model.verify_button_visible());
EXPECT_FALSE(model.cancel_button_enabled());
EXPECT_FALSE(model.cancel_button_visible());
}
} // namespace payments
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