Bug 1432079 - Implement PaymentItemType. r?baku
MozReview-Commit-ID: Jpj9arQ9MaE
--- a/dom/interfaces/payments/nsIPaymentRequest.idl
+++ b/dom/interfaces/payments/nsIPaymentRequest.idl
@@ -25,16 +25,17 @@ interface nsIPaymentCurrencyAmount : nsI
};
[scriptable, builtinclass, uuid(4f78a59f-b5ff-4fb5-ab48-3b37d0101b02)]
interface nsIPaymentItem : nsISupports
{
readonly attribute AString label;
readonly attribute nsIPaymentCurrencyAmount amount;
readonly attribute boolean pending;
+ readonly attribute AString type;
};
[scriptable, builtinclass, uuid(74259861-c318-40e8-b3d5-518e701bed80)]
interface nsIPaymentDetailsModifier : nsISupports
{
readonly attribute AString supportedMethods;
readonly attribute nsIPaymentItem total;
readonly attribute nsIArray additionalDisplayItems;
--- a/dom/payments/PaymentRequestData.cpp
+++ b/dom/payments/PaymentRequestData.cpp
@@ -103,35 +103,37 @@ PaymentCurrencyAmount::GetValue(nsAStrin
/* PaymentItem */
NS_IMPL_ISUPPORTS(PaymentItem,
nsIPaymentItem)
PaymentItem::PaymentItem(const nsAString& aLabel,
nsIPaymentCurrencyAmount* aAmount,
- const bool aPending)
+ const bool aPending,
+ const nsAString& aType)
: mLabel(aLabel)
, mAmount(aAmount)
, mPending(aPending)
+ , mType(aType)
{
}
nsresult
PaymentItem::Create(const IPCPaymentItem& aIPCItem, nsIPaymentItem** aItem)
{
NS_ENSURE_ARG_POINTER(aItem);
nsCOMPtr<nsIPaymentCurrencyAmount> amount;
nsresult rv = PaymentCurrencyAmount::Create(aIPCItem.amount(),
getter_AddRefs(amount));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIPaymentItem> item =
- new PaymentItem(aIPCItem.label(), amount, aIPCItem.pending());
+ new PaymentItem(aIPCItem.label(), amount, aIPCItem.pending(), aIPCItem.type());
item.forget(aItem);
return NS_OK;
}
NS_IMETHODIMP
PaymentItem::GetLabel(nsAString& aLabel)
{
aLabel = mLabel;
@@ -151,16 +153,23 @@ PaymentItem::GetAmount(nsIPaymentCurrenc
NS_IMETHODIMP
PaymentItem::GetPending(bool* aPending)
{
NS_ENSURE_ARG_POINTER(aPending);
*aPending = mPending;
return NS_OK;
}
+NS_IMETHODIMP
+PaymentItem::GetType(nsAString& aType)
+{
+ aType = mType;
+ return NS_OK;
+}
+
/* PaymentDetailsModifier */
NS_IMPL_ISUPPORTS(PaymentDetailsModifier,
nsIPaymentDetailsModifier)
PaymentDetailsModifier::PaymentDetailsModifier(const nsAString& aSupportedMethods,
nsIPaymentItem* aTotal,
nsIArray* aAdditionalDisplayItems,
--- a/dom/payments/PaymentRequestData.h
+++ b/dom/payments/PaymentRequestData.h
@@ -60,23 +60,25 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPAYMENTITEM
static nsresult Create(const IPCPaymentItem& aIPCItem, nsIPaymentItem** aItem);
private:
PaymentItem(const nsAString& aLabel,
nsIPaymentCurrencyAmount* aAmount,
- const bool aPending);
+ const bool aPending,
+ const nsAString& aType);
~PaymentItem() = default;
nsString mLabel;
nsCOMPtr<nsIPaymentCurrencyAmount> mAmount;
bool mPending;
+ nsString mType;
};
class PaymentDetailsModifier final : public nsIPaymentDetailsModifier
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPAYMENTDETAILSMODIFIER
--- a/dom/payments/PaymentRequestManager.cpp
+++ b/dom/payments/PaymentRequestManager.cpp
@@ -46,19 +46,28 @@ ConvertCurrencyAmount(const PaymentCurre
IPCPaymentCurrencyAmount& aIPCCurrencyAmount)
{
aIPCCurrencyAmount = IPCPaymentCurrencyAmount(aAmount.mCurrency, aAmount.mValue);
}
void
ConvertItem(const PaymentItem& aItem, IPCPaymentItem& aIPCItem)
{
+ uint8_t typeIndex = UINT8_MAX;
+ if (aItem.mType.WasPassed()) {
+ typeIndex = static_cast<uint8_t>(aItem.mType.Value());
+ }
+ nsString type;
+ if (typeIndex < ArrayLength(PaymentItemTypeValues::strings)) {
+ type.AssignASCII(
+ PaymentItemTypeValues::strings[typeIndex].value);
+ }
IPCPaymentCurrencyAmount amount;
ConvertCurrencyAmount(aItem.mAmount, amount);
- aIPCItem = IPCPaymentItem(aItem.mLabel, amount, aItem.mPending);
+ aIPCItem = IPCPaymentItem(aItem.mLabel, amount, aItem.mPending, type);
}
nsresult
ConvertModifier(JSContext* aCx,
const PaymentDetailsModifier& aModifier,
IPCPaymentDetailsModifier& aIPCModifier)
{
NS_ENSURE_ARG_POINTER(aCx);
--- a/dom/payments/ipc/PPaymentRequest.ipdl
+++ b/dom/payments/ipc/PPaymentRequest.ipdl
@@ -22,16 +22,17 @@ struct IPCPaymentCurrencyAmount
nsString value;
};
struct IPCPaymentItem
{
nsString label;
IPCPaymentCurrencyAmount amount;
bool pending;
+ nsString type;
};
struct IPCPaymentDetailsModifier
{
nsString supportedMethods;
IPCPaymentItem total;
IPCPaymentItem[] additionalDisplayItems;
nsString data;
--- a/dom/payments/test/ConstructorChromeScript.js
+++ b/dom/payments/test/ConstructorChromeScript.js
@@ -136,39 +136,58 @@ function checkComplexRequest(payRequest)
if (details.totalItem.amount.value != "100.00") {
emitTestFail("total item's value should be '100.00'.");
}
const displayItems = details.displayItems;
if (!details.displayItems) {
emitTestFail("details.displayItems should not be undefined.");
}
- if (displayItems.length != 2) {
- emitTestFail("displayItems' length should be 2.")
+ if (displayItems.length != 3) {
+ emitTestFail("displayItems' length should be 3.")
}
let item = displayItems.queryElementAt(0, Ci.nsIPaymentItem);
if (item.label != "First item") {
emitTestFail("1st display item's label should be 'First item'.");
}
if (item.amount.currency != "USD") {
emitTestFail("1st display item's currency should be 'USD'.");
}
if (item.amount.value != "60.00") {
emitTestFail("1st display item's value should be '60.00'.");
}
+ if (item.type != "") {
+ emitTestFail("1st display item's type should be ''.");
+ }
item = displayItems.queryElementAt(1, Ci.nsIPaymentItem);
if (item.label != "Second item") {
emitTestFail("2nd display item's label should be 'Second item'.");
}
if (item.amount.currency != "USD") {
emitTestFail("2nd display item's currency should be 'USD'.");
}
if (item.amount.value != "40.00") {
emitTestFail("2nd display item's value should be '40.00'.");
}
+ if (item.type != "") {
+ emitTestFail("2nd display item's type should be ''.");
+ }
+ item = displayItems.queryElementAt(2, Ci.nsIPaymentItem);
+ if (item.label != "Tax") {
+ emitTestFail("3rd display item's label should be 'Tax'.");
+ }
+ if (item.amount.currency != "USD") {
+ emitTestFail("3rd display item's currency should be 'USD'.");
+ }
+ if (item.amount.value != "5.00") {
+ emitTestFail("3rd display item's value should be '5.00'.");
+ }
+ if (item.type != "tax") {
+ emitTestFail("3rd display item's type should be 'tax'.");
+ }
const modifiers = details.modifiers;
if (!modifiers) {
emitTestFail("details.displayItems should not be undefined.");
}
if (modifiers.length != 1) {
emitTestFail("modifiers' length should be 1.");
}
--- a/dom/payments/test/test_constructor.html
+++ b/dom/payments/test/test_constructor.html
@@ -70,16 +70,24 @@ https://bugzilla.mozilla.org/show_bug.cg
}
},
{
label: "Second item",
amount: {
currency: "USD",
value: "40.00"
}
+ },
+ {
+ label: "Tax",
+ amount: {
+ currency: "USD",
+ value: "5.00"
+ },
+ type: "tax"
}
],
modifiers: [
{
supportedMethods: "basic-card",
total: {
label: "Discounted Total",
amount: {
--- a/dom/webidl/PaymentRequest.webidl
+++ b/dom/webidl/PaymentRequest.webidl
@@ -13,20 +13,25 @@ dictionary PaymentMethodData {
};
dictionary PaymentCurrencyAmount {
required DOMString currency;
required DOMString value;
DOMString currencySystem = "urn:iso:std:iso:4217";
};
+enum PaymentItemType {
+ "tax"
+};
+
dictionary PaymentItem {
required DOMString label;
required PaymentCurrencyAmount amount;
boolean pending = false;
+ PaymentItemType type;
};
dictionary PaymentShippingOption {
required DOMString id;
required DOMString label;
required PaymentCurrencyAmount amount;
boolean selected = false;
};