diff --git a/browser/components/payments/test/unit/test_response_creation.js b/browser/components/payments/test/unit/test_response_creation.js index 3db2a63c80db..b903bb4e7caf 100644 --- a/browser/components/payments/test/unit/test_response_creation.js +++ b/browser/components/payments/test/unit/test_response_creation.js @@ -10,16 +10,6 @@ const DIALOG_WRAPPER_URI = "chrome://payments/content/paymentDialogWrapper.js"; let dialogGlobal = {}; Services.scriptloader.loadSubScript(DIALOG_WRAPPER_URI, dialogGlobal); -/** - * @param {Object} responseData with properties in the order matching `nsIBasicCardResponseData` - * init method args. - * @returns {string} serialized card data - */ -function serializeBasicCardResponseData(responseData) { - return [...Object.entries(responseData)].map(array => array.join(":")).join(";") + ";"; -} - - add_task(async function test_createBasicCardResponseData_basic() { let expected = { cardholderName: "John Smith", @@ -29,8 +19,11 @@ add_task(async function test_createBasicCardResponseData_basic() { cardSecurityCode: "0123", }; let actual = dialogGlobal.paymentDialogWrapper.createBasicCardResponseData(expected); - let expectedSerialized = serializeBasicCardResponseData(expected); - Assert.equal(actual.data, expectedSerialized, "Check data"); + Assert.equal(actual.cardholderName, expected.cardholderName, "Check cardholderName"); + Assert.equal(actual.cardNumber, expected.cardNumber, "Check cardNumber"); + Assert.equal(actual.expiryMonth, expected.expiryMonth, "Check expiryMonth"); + Assert.equal(actual.expiryYear, expected.expiryYear, "Check expiryYear"); + Assert.equal(actual.cardSecurityCode, expected.cardSecurityCode, "Check cardSecurityCode"); }); add_task(async function test_createBasicCardResponseData_minimal() { @@ -38,9 +31,8 @@ add_task(async function test_createBasicCardResponseData_minimal() { cardNumber: "1234567890", }; let actual = dialogGlobal.paymentDialogWrapper.createBasicCardResponseData(expected); - let expectedSerialized = serializeBasicCardResponseData(expected); - info(actual.data); - Assert.equal(actual.data, expectedSerialized, "Check data"); + info(actual.cardNumber); + Assert.equal(actual.cardNumber, expected.cardNumber, "Check cardNumber"); }); add_task(async function test_createBasicCardResponseData_withoutNumber() { @@ -130,11 +122,6 @@ add_task(async function test_createShowResponse_basic() { Assert.equal(propVal, requestId, `Check ${propName}`); continue; } - if (propName == "data") { - Assert.equal(propVal, serializeBasicCardResponseData(cardData), `Check ${propName}`); - continue; - } - Assert.equal(propVal, responseData[propName], `Check ${propName}`); } }); diff --git a/dom/interfaces/payments/nsIPaymentActionResponse.idl b/dom/interfaces/payments/nsIPaymentActionResponse.idl index 08a5e715fd67..9746d91f306d 100644 --- a/dom/interfaces/payments/nsIPaymentActionResponse.idl +++ b/dom/interfaces/payments/nsIPaymentActionResponse.idl @@ -69,9 +69,34 @@ interface nsIGeneralResponseData : nsIPaymentResponseData interface nsIBasicCardResponseData : nsIPaymentResponseData { /** - * The stringified response data. + * The cardholder name. */ - readonly attribute AString data; + readonly attribute AString cardholderName; + + /** + * The card number. + */ + readonly attribute AString cardNumber; + + /** + * The expiry month. + */ + readonly attribute AString expiryMonth; + + /** + * The expiry year. + */ + readonly attribute AString expiryYear; + + /** + * The card security number. + */ + readonly attribute AString cardSecurityCode; + + /** + * The billing address. + */ + readonly attribute nsIPaymentAddress billingAddress; /** * The initial method for nsIBasicCardResponseData. @@ -183,7 +208,7 @@ interface nsIPaymentShowActionResponse : nsIPaymentActionResponse /** * The data needed by the payment method. (it must be serializable) */ - readonly attribute AString data; + readonly attribute nsIPaymentResponseData data; /** * The payer name information. diff --git a/dom/payments/BasicCardPayment.cpp b/dom/payments/BasicCardPayment.cpp index c22ecac62c97..be87cb3f159d 100644 --- a/dom/payments/BasicCardPayment.cpp +++ b/dom/payments/BasicCardPayment.cpp @@ -14,117 +14,19 @@ namespace mozilla { namespace dom { -#ifndef PaymentBasicCardMacros -#define PaymentBasicCardMacros - -#define AMEX NS_LITERAL_STRING("amex") -#define CARTEBANCAIRE NS_LITERAL_STRING("cartebancaire") -#define DINERS NS_LITERAL_STRING("diners") -#define DISCOVER NS_LITERAL_STRING("discover") -#define JCB NS_LITERAL_STRING("jcb") -#define MASTERCARD NS_LITERAL_STRING("mastercard") -#define MIR NS_LITERAL_STRING("mir") -#define UNIONPAY NS_LITERAL_STRING("unionpay") -#define VISA NS_LITERAL_STRING("visa") - -#define CardholderName NS_LITERAL_STRING("cardholderName") -#define CardNumber NS_LITERAL_STRING("cardNumber") -#define ExpiryMonth NS_LITERAL_STRING("expiryMonth") -#define ExpiryYear NS_LITERAL_STRING("expiryYear") -#define CardSecurityCode NS_LITERAL_STRING("cardSecurityCode") - -#define Country NS_LITERAL_STRING("country") -#define AddressLine NS_LITERAL_STRING("addressLine") -#define Region NS_LITERAL_STRING("region") -#define RegionCode NS_LITERAL_STRING("regionCode") -#define City NS_LITERAL_STRING("city") -#define DependentLocality NS_LITERAL_STRING("dependentLocality") -#define PostalCode NS_LITERAL_STRING("postalCode") -#define SortingCode NS_LITERAL_STRING("sortingCode") -#define Organization NS_LITERAL_STRING("organization") -#define Recipient NS_LITERAL_STRING("recipient") -#define Phone NS_LITERAL_STRING("phone") - -#define PropertySpliter NS_LITERAL_STRING(";") -#define KeyValueSpliter NS_LITERAL_STRING(":") -#define AddressLineSpliter NS_LITERAL_STRING("%") - -#define EncodeBasicCardProperty(aPropertyName, aPropertyValue, aResult) \ - do { \ - if (!(aPropertyValue).IsEmpty()) { \ - (aResult) += (aPropertyName) \ - + KeyValueSpliter \ - + (aPropertyValue) \ - + PropertySpliter; \ - } \ - } while(0) - -#define EncodeAddressProperty(aAddress, aPropertyName, aResult) \ - do { \ - nsAutoString propertyValue; \ - NS_ENSURE_SUCCESS((aAddress)->Get##aPropertyName(propertyValue), \ - NS_ERROR_FAILURE); \ - EncodeBasicCardProperty((aPropertyName) ,propertyValue , (aResult)); \ - } while(0) - -#define DecodeBasicCardProperty(aPropertyName, aPropertyValue, \ - aMatchPropertyName, aResponse) \ - do { \ - if ((aPropertyName).Equals((aMatchPropertyName))) { \ - (aResponse).m##aMatchPropertyName.Construct(); \ - (aResponse).m##aMatchPropertyName.Value() = (aPropertyValue); \ - } \ - } while(0) - -#define DecodeAddressProperty(aPropertyName, aPropertyValue, \ - aMatchPropertyName, aMatchPropertyValue) \ - do { \ - if ((aPropertyName).Equals((aMatchPropertyName))) { \ - (aMatchPropertyValue) = (aPropertyValue); \ - } \ - } while(0) - -#endif - namespace { - bool IsValidNetwork(const nsAString& aNetwork) { - return AMEX.Equals(aNetwork) || - CARTEBANCAIRE.Equals(aNetwork) || - DINERS.Equals(aNetwork) || - DISCOVER.Equals(aNetwork) || - JCB.Equals(aNetwork) || - MASTERCARD.Equals(aNetwork) || - MIR.Equals(aNetwork) || - UNIONPAY.Equals(aNetwork) || - VISA.Equals(aNetwork); + return aNetwork.Equals(NS_LITERAL_STRING("amex")) || + aNetwork.Equals(NS_LITERAL_STRING("cartebancaire")) || + aNetwork.Equals(NS_LITERAL_STRING("diners")) || + aNetwork.Equals(NS_LITERAL_STRING("discover")) || + aNetwork.Equals(NS_LITERAL_STRING("jcb")) || + aNetwork.Equals(NS_LITERAL_STRING("mastercard")) || + aNetwork.Equals(NS_LITERAL_STRING("mir")) || + aNetwork.Equals(NS_LITERAL_STRING("unionpay")) || + aNetwork.Equals(NS_LITERAL_STRING("visa")); } - -bool IsBasicCardKey(const nsAString& aKey) -{ - return CardholderName.Equals(aKey) || - CardNumber.Equals(aKey) || - ExpiryMonth.Equals(aKey) || - ExpiryYear.Equals(aKey) || - CardSecurityCode.Equals(aKey); -} - -bool IsAddressKey(const nsAString& aKey) -{ - return Country.Equals(aKey) || - AddressLine.Equals(aKey) || - Region.Equals(aKey) || - RegionCode.Equals(aKey) || - City.Equals(aKey) || - DependentLocality.Equals(aKey) || - PostalCode.Equals(aKey) || - SortingCode.Equals(aKey) || - Organization.Equals(aKey) || - Recipient.Equals(aKey) || - Phone.Equals(aKey); -} - } // end of namespace @@ -223,132 +125,6 @@ BasicCardService::IsValidExpiryYear(const nsAString& aExpiryYear) return true; } -nsresult -BasicCardService::EncodeBasicCardData(const nsAString& aCardholderName, - const nsAString& aCardNumber, - const nsAString& aExpiryMonth, - const nsAString& aExpiryYear, - const nsAString& aCardSecurityCode, - nsIPaymentAddress* aBillingAddress, - nsAString& aResult) -{ - // aBillingAddress can be nullptr - if (aCardNumber.IsEmpty()) { - return NS_ERROR_FAILURE; - } - EncodeBasicCardProperty(CardholderName, aCardholderName, aResult); - EncodeBasicCardProperty(CardNumber, aCardNumber, aResult); - EncodeBasicCardProperty(ExpiryMonth, aExpiryMonth, aResult); - EncodeBasicCardProperty(ExpiryYear, aExpiryYear, aResult); - EncodeBasicCardProperty(CardSecurityCode, aCardSecurityCode, aResult); - if (!aBillingAddress) { - return NS_OK; - } - EncodeAddressProperty(aBillingAddress, Country, aResult); - nsCOMPtr addressLine; - NS_ENSURE_SUCCESS(aBillingAddress->GetAddressLine(getter_AddRefs(addressLine)), - NS_ERROR_FAILURE); - uint32_t length; - nsAutoString addressLineString; - NS_ENSURE_SUCCESS(addressLine->GetLength(&length), NS_ERROR_FAILURE); - for (uint32_t index = 0; index < length; ++index) { - nsCOMPtr address = do_QueryElementAt(addressLine, index); - MOZ_ASSERT(address); - nsAutoString addressString; - NS_ENSURE_SUCCESS(address->GetData(addressString), NS_ERROR_FAILURE); - addressLineString += addressString + AddressLineSpliter; - } - EncodeBasicCardProperty(AddressLine ,addressLineString , aResult); - EncodeAddressProperty(aBillingAddress, Region, aResult); - EncodeAddressProperty(aBillingAddress, RegionCode, aResult); - EncodeAddressProperty(aBillingAddress, City, aResult); - EncodeAddressProperty(aBillingAddress, DependentLocality, aResult); - EncodeAddressProperty(aBillingAddress, PostalCode, aResult); - EncodeAddressProperty(aBillingAddress, SortingCode, aResult); - EncodeAddressProperty(aBillingAddress, Organization, aResult); - EncodeAddressProperty(aBillingAddress, Recipient, aResult); - EncodeAddressProperty(aBillingAddress, Phone, aResult); - return NS_OK; -} - -nsresult -BasicCardService::DecodeBasicCardData(const nsAString& aData, - nsPIDOMWindowInner* aWindow, - BasicCardResponse& aResponse) -{ - // aWindow can be nullptr - bool isBillingAddressPassed = false; - nsTArray addressLine; - nsAutoString country; - nsAutoString region; - nsAutoString regionCode; - nsAutoString city; - nsAutoString dependentLocality; - nsAutoString postalCode; - nsAutoString sortingCode; - nsAutoString organization; - nsAutoString recipient; - nsAutoString phone; - - nsCharSeparatedTokenizer propertyTokenizer(aData, PropertySpliter.CharAt(0)); - while (propertyTokenizer.hasMoreTokens()) { - nsDependentSubstring property = propertyTokenizer.nextToken(); - nsCharSeparatedTokenizer keyValueTokenizer(property, KeyValueSpliter.CharAt(0)); - MOZ_ASSERT(keyValueTokenizer.hasMoreTokens()); - nsDependentSubstring key = keyValueTokenizer.nextToken(); - nsDependentSubstring value = keyValueTokenizer.nextToken(); - if (IsAddressKey(key) && !isBillingAddressPassed) { - isBillingAddressPassed = true; - } - if (!IsAddressKey(key) && !IsBasicCardKey(key)) { - return NS_ERROR_FAILURE; - } - - if (key.Equals(CardNumber)) { - aResponse.mCardNumber = (value); - } - - DecodeBasicCardProperty(key, value, CardholderName, aResponse); - DecodeBasicCardProperty(key, value, ExpiryMonth, aResponse); - DecodeBasicCardProperty(key, value, ExpiryYear, aResponse); - DecodeBasicCardProperty(key, value, CardSecurityCode, aResponse); - - DecodeAddressProperty(key, value, Country, country); - DecodeAddressProperty(key, value, Region, region); - DecodeAddressProperty(key, value, RegionCode, regionCode); - DecodeAddressProperty(key, value, City, city); - DecodeAddressProperty(key, value, DependentLocality, dependentLocality); - DecodeAddressProperty(key, value, PostalCode, postalCode); - DecodeAddressProperty(key, value, SortingCode, sortingCode); - DecodeAddressProperty(key, value, Organization, organization); - DecodeAddressProperty(key, value, Recipient, recipient); - DecodeAddressProperty(key, value, Phone, phone); - - if ((key).Equals(AddressLine)) { - nsCharSeparatedTokenizer addressTokenizer(value, AddressLineSpliter.CharAt(0)); - while (addressTokenizer.hasMoreTokens()) { - addressLine.AppendElement(addressTokenizer.nextToken()); - } - } - } - if (isBillingAddressPassed) { - aResponse.mBillingAddress.Construct(); - aResponse.mBillingAddress.Value() = new PaymentAddress(aWindow, - country, - addressLine, - region, - regionCode, - city, - dependentLocality, - postalCode, - sortingCode, - organization, - recipient, - phone); - } - return NS_OK; -} - bool BasicCardService::IsValidBasicCardErrors(JSContext* aCx, JSObject* aData) @@ -361,42 +137,5 @@ BasicCardService::IsValidBasicCardErrors(JSContext* aCx, BasicCardErrors bcError; return !bcError.Init(aCx, data); } - -#ifdef PaymentBasicCardMacros -#undef PaymentBasicCardMacros -#undef EncodeBasicCardProperty -#undef EncodeAddressProperty -#undef DecodeBasicCardProperty -#undef DecodeAddressProperty -#undef AMEX -#undef CARTEBANCAIRE -#undef DINERS -#undef DISCOVER -#undef JCB -#undef MASTERCARD -#undef MIR -#undef UNIONPAY -#undef VISA -#undef CardholderName -#undef CardNumber -#undef ExpiryMonth -#undef ExpiryYear -#undef CardSecurityCode -#undef Country -#undef AddressLine -#undef Region -#undef RegionCode -#undef City -#undef DependentLocality -#undef PostalCode -#undef SortingCode -#undef Organization -#undef Recipient -#undef Phone -#undef PropertySpliter -#undef KeyValueSpliter -#undef AddressLineSpliter -#endif - } // end of namespace dom } // end of namespace mozilla diff --git a/dom/payments/BasicCardPayment.h b/dom/payments/BasicCardPayment.h index af8f9ea7c93a..5bb18a70b50c 100644 --- a/dom/payments/BasicCardPayment.h +++ b/dom/payments/BasicCardPayment.h @@ -27,22 +27,6 @@ public: bool IsValidBasicCardErrors(JSContext* aCx, JSObject* aData); bool IsValidExpiryMonth(const nsAString& aExpiryMonth); bool IsValidExpiryYear(const nsAString& aExpiryYear); -/* - To let BasicCardResponse using the same data type with non-BasicCard response - in IPC transferring, following two methods is used to Encode/Decode the raw - data of BasicCardResponse. -*/ - nsresult EncodeBasicCardData(const nsAString& aCardholderName, - const nsAString& aCardNumber, - const nsAString& aExpiryMonth, - const nsAString& aExpiryYear, - const nsAString& aCardSecurityCode, - nsIPaymentAddress* aBillingAddress, - nsAString& aResult); - - nsresult DecodeBasicCardData(const nsAString& aData, - nsPIDOMWindowInner* aWindow, - BasicCardResponse& aResponse); private: BasicCardService() = default; ~BasicCardService() = default; diff --git a/dom/payments/PaymentActionResponse.cpp b/dom/payments/PaymentActionResponse.cpp index 7056df2c2b9a..5116cec5481a 100644 --- a/dom/payments/PaymentActionResponse.cpp +++ b/dom/payments/PaymentActionResponse.cpp @@ -6,7 +6,6 @@ #include "PaymentActionResponse.h" #include "PaymentRequestUtils.h" -#include "BasicCardPayment.h" namespace mozilla { namespace dom { @@ -78,9 +77,47 @@ BasicCardResponseData::BasicCardResponseData() } NS_IMETHODIMP -BasicCardResponseData::GetData(nsAString& aData) +BasicCardResponseData::GetCardholderName(nsAString& aCardholderName) { - aData = mData; + aCardholderName = mCardholderName; + return NS_OK; +} + +NS_IMETHODIMP +BasicCardResponseData::GetCardNumber(nsAString& aCardNumber) +{ + aCardNumber = mCardNumber; + return NS_OK; +} + +NS_IMETHODIMP +BasicCardResponseData::GetExpiryMonth(nsAString& aExpiryMonth) +{ + aExpiryMonth = mExpiryMonth; + return NS_OK; +} + +NS_IMETHODIMP +BasicCardResponseData::GetExpiryYear(nsAString& aExpiryYear) +{ + aExpiryYear = mExpiryYear; + return NS_OK; +} + +NS_IMETHODIMP +BasicCardResponseData::GetCardSecurityCode(nsAString& aCardSecurityCode) +{ + aCardSecurityCode = mCardSecurityCode; + return NS_OK; +} + +NS_IMETHODIMP +BasicCardResponseData::GetBillingAddress(nsIPaymentAddress** aBillingAddress) +{ + NS_ENSURE_ARG_POINTER(aBillingAddress); + nsCOMPtr address; + address = mBillingAddress; + address.forget(aBillingAddress); return NS_OK; } @@ -107,16 +144,14 @@ BasicCardResponseData::InitData(const nsAString& aCardholderName, if (!service->IsValidExpiryYear(aExpiryYear)) { return NS_ERROR_FAILURE; } - nsresult rv = service->EncodeBasicCardData(aCardholderName, - aCardNumber, - aExpiryMonth, - aExpiryYear, - aCardSecurityCode, - aBillingAddress, - mData); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } + + mCardholderName = aCardholderName; + mCardNumber = aCardNumber; + mExpiryMonth = aExpiryMonth; + mExpiryYear = aExpiryYear; + mCardSecurityCode = aCardSecurityCode; + mBillingAddress = aBillingAddress; + return NS_OK; } @@ -202,9 +237,11 @@ PaymentShowActionResponse::GetMethodName(nsAString& aMethodName) } NS_IMETHODIMP -PaymentShowActionResponse::GetData(nsAString& aData) +PaymentShowActionResponse::GetData(nsIPaymentResponseData** aData) { - aData = mData; + NS_ENSURE_ARG_POINTER(aData); + nsCOMPtr data = mData; + data.forget(aData); return NS_OK; } @@ -258,28 +295,20 @@ PaymentShowActionResponse::Init(const nsAString& aRequestId, if (isBasicCardPayment) { return NS_ERROR_FAILURE; } - nsCOMPtr data = do_QueryInterface(aData); - MOZ_ASSERT(data); - NS_ENSURE_SUCCESS(data->GetData(mData), NS_ERROR_FAILURE); break; } case nsIPaymentResponseData::BASICCARD_RESPONSE: { if (!isBasicCardPayment) { return NS_ERROR_FAILURE; } - nsCOMPtr data = do_QueryInterface(aData); - MOZ_ASSERT(data); - NS_ENSURE_SUCCESS(data->GetData(mData), NS_ERROR_FAILURE); break; } default: { return NS_ERROR_FAILURE; } } - if (mData.IsEmpty()) { - return NS_ERROR_FAILURE; - } } + mData = aData; mPayerName = aPayerName; mPayerEmail = aPayerEmail; mPayerPhone = aPayerPhone; diff --git a/dom/payments/PaymentActionResponse.h b/dom/payments/PaymentActionResponse.h index 1985f65fab28..9e276234f6ff 100644 --- a/dom/payments/PaymentActionResponse.h +++ b/dom/payments/PaymentActionResponse.h @@ -57,7 +57,11 @@ public: private: ~BasicCardResponseData() = default; - nsString mData; + nsString mCardholderName; + nsString mCardNumber; + nsString mExpiryMonth; + nsString mExpiryYear; + nsString mCardSecurityCode; nsCOMPtr mBillingAddress; }; @@ -107,7 +111,7 @@ private: uint32_t mAcceptStatus; nsString mMethodName; - nsString mData; + nsCOMPtr mData; nsString mPayerName; nsString mPayerEmail; nsString mPayerPhone; diff --git a/dom/payments/PaymentRequest.cpp b/dom/payments/PaymentRequest.cpp index dbcf05f58d46..b5277b14bbe2 100644 --- a/dom/payments/PaymentRequest.cpp +++ b/dom/payments/PaymentRequest.cpp @@ -9,7 +9,7 @@ #include "mozilla/dom/FeaturePolicyUtils.h" #include "mozilla/dom/PaymentRequest.h" #include "mozilla/dom/PaymentRequestChild.h" -#include "mozilla/dom/PaymentResponse.h" +#include "mozilla/dom/PaymentRequestManager.h" #include "mozilla/intl/LocaleService.h" #include "mozilla/intl/MozLocale.h" #include "mozilla/EventStateManager.h" @@ -18,8 +18,8 @@ #include "nsIScriptError.h" #include "nsIURLParser.h" #include "nsNetCID.h" -#include "PaymentRequestManager.h" #include "mozilla/dom/MerchantValidationEvent.h" +#include "PaymentResponse.h" using mozilla::intl::LocaleService; @@ -797,7 +797,7 @@ PaymentRequest::RejectShowPayment(nsresult aRejectReason) void PaymentRequest::RespondShowPayment(const nsAString& aMethodName, - const nsAString& aDetails, + const ResponseData& aDetails, const nsAString& aPayerName, const nsAString& aPayerEmail, const nsAString& aPayerPhone, @@ -888,7 +888,7 @@ PaymentRequest::RespondAbortPayment(bool aSuccess) if (NS_FAILED(mUpdateError)) { // Respond show with mUpdateError, set mUpdating to false. mUpdating = false; - RespondShowPayment(EmptyString(), EmptyString(), EmptyString(), + RespondShowPayment(EmptyString(), ResponseData(), EmptyString(), EmptyString(), EmptyString(), mUpdateError); mUpdateError = NS_OK; return; diff --git a/dom/payments/PaymentRequest.h b/dom/payments/PaymentRequest.h index 4c8f2e0e31ee..085602ec1905 100644 --- a/dom/payments/PaymentRequest.h +++ b/dom/payments/PaymentRequest.h @@ -23,6 +23,7 @@ class EventHandlerNonNull; class PaymentAddress; class PaymentRequestChild; class PaymentResponse; +class ResponseData; class PaymentRequest final : public DOMEventTargetHelper @@ -96,7 +97,7 @@ public: const Optional>& detailsPromise, ErrorResult& aRv); void RespondShowPayment(const nsAString& aMethodName, - const nsAString& aDetails, + const ResponseData& aDetails, const nsAString& aPayerName, const nsAString& aPayerEmail, const nsAString& aPayerPhone, diff --git a/dom/payments/PaymentRequestManager.cpp b/dom/payments/PaymentRequestManager.cpp index 75f0767a75a4..91ab08164651 100644 --- a/dom/payments/PaymentRequestManager.cpp +++ b/dom/payments/PaymentRequestManager.cpp @@ -4,15 +4,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "PaymentRequestManager.h" -#include "PaymentRequestUtils.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/dom/ContentChild.h" -#include "mozilla/dom/TabChild.h" #include "mozilla/dom/PaymentRequestChild.h" +#include "mozilla/dom/TabChild.h" #include "nsContentUtils.h" #include "nsString.h" #include "nsIPrincipal.h" +#include "PaymentRequestManager.h" +#include "PaymentRequestUtils.h" +#include "PaymentResponse.h" namespace mozilla { namespace dom { @@ -249,6 +250,47 @@ ConvertOptions(const PaymentOptions& aOptions, aOptions.mRequestShipping, shippingType); } + +void +ConvertResponseData(const IPCPaymentResponseData& aIPCData, + ResponseData& aData) +{ + switch (aIPCData.type()) { + case IPCPaymentResponseData::TIPCGeneralResponse : { + const IPCGeneralResponse& data = aIPCData; + GeneralData gData; + gData.data = data.data(); + aData = gData; + break; + } + case IPCPaymentResponseData::TIPCBasicCardResponse: { + const IPCBasicCardResponse& data = aIPCData; + BasicCardData bData; + bData.cardholderName = data.cardholderName(); + bData.cardNumber = data.cardNumber(); + bData.expiryMonth = data.expiryMonth(); + bData.expiryYear = data.expiryYear(); + bData.cardSecurityCode = data.cardSecurityCode(); + bData.billingAddress.country = data.billingAddress().country(); + bData.billingAddress.addressLine = data.billingAddress().addressLine(); + bData.billingAddress.region = data.billingAddress().region(); + bData.billingAddress.regionCode = data.billingAddress().regionCode(); + bData.billingAddress.city = data.billingAddress().city(); + bData.billingAddress.dependentLocality = + data.billingAddress().dependentLocality(); + bData.billingAddress.postalCode = data.billingAddress().postalCode(); + bData.billingAddress.sortingCode = data.billingAddress().sortingCode(); + bData.billingAddress.organization = data.billingAddress().organization(); + bData.billingAddress.recipient = data.billingAddress().recipient(); + bData.billingAddress.phone = data.billingAddress().phone(); + aData = bData; + break; + } + default: { + break; + } + } +} } // end of namespace /* PaymentRequestManager */ @@ -589,6 +631,8 @@ PaymentRequestManager::RespondPayment(PaymentRequest* aRequest, case IPCPaymentActionResponse::TIPCPaymentShowActionResponse: { const IPCPaymentShowActionResponse& response = aResponse; nsresult rejectedReason = NS_ERROR_DOM_ABORT_ERR; + ResponseData responseData; + ConvertResponseData(response.data(), responseData); switch (response.status()) { case nsIPaymentActionResponse::PAYMENT_ACCEPTED: { rejectedReason = NS_OK; @@ -608,7 +652,7 @@ PaymentRequestManager::RespondPayment(PaymentRequest* aRequest, } } aRequest->RespondShowPayment(response.methodName(), - response.data(), + responseData, response.payerName(), response.payerEmail(), response.payerPhone(), diff --git a/dom/payments/PaymentResponse.cpp b/dom/payments/PaymentResponse.cpp index 58d394a68d6e..bc5967ebfa6d 100644 --- a/dom/payments/PaymentResponse.cpp +++ b/dom/payments/PaymentResponse.cpp @@ -51,7 +51,7 @@ PaymentResponse::PaymentResponse(nsPIDOMWindowInner* aWindow, const nsAString& aMethodName, const nsAString& aShippingOption, PaymentAddress* aShippingAddress, - const nsAString& aDetails, + const ResponseData& aDetails, const nsAString& aPayerName, const nsAString& aPayerEmail, const nsAString& aPayerPhone) @@ -101,23 +101,70 @@ void PaymentResponse::GetDetails(JSContext* aCx, JS::MutableHandle aRetVal) const { - RefPtr service = BasicCardService::GetService(); - MOZ_ASSERT(service); - if (!service->IsBasicCardPayment(mMethodName)) { - DeserializeToJSObject(mDetails, aCx, aRetVal); - } else { - BasicCardResponse response; - nsresult rv = service->DecodeBasicCardData(mDetails, GetOwner(), response); - if (NS_WARN_IF(NS_FAILED(rv))) { - return; + switch(mDetails.type()) { + case ResponseData::GeneralResponse: { + const GeneralData& rawData = mDetails.generalData(); + DeserializeToJSObject(rawData.data, aCx, aRetVal); + break; } - - MOZ_ASSERT(aCx); - JS::RootedValue value(aCx); - if (NS_WARN_IF(!response.ToObjectInternal(aCx, &value))) { - return; + case ResponseData::BasicCardResponse: { + const BasicCardData& rawData = mDetails.basicCardData(); + BasicCardResponse basicCardResponse; + if (!rawData.cardholderName.IsEmpty()) { + basicCardResponse.mCardholderName.Construct(); + basicCardResponse.mCardholderName.Value() = rawData.cardholderName; + } + basicCardResponse.mCardNumber = rawData.cardNumber; + if (!rawData.expiryMonth.IsEmpty()) { + basicCardResponse.mExpiryMonth.Construct(); + basicCardResponse.mExpiryMonth.Value() = rawData.expiryMonth; + } + if (!rawData.expiryYear.IsEmpty()) { + basicCardResponse.mExpiryYear.Construct(); + basicCardResponse.mExpiryYear.Value() = rawData.expiryYear; + } + if (!rawData.cardSecurityCode.IsEmpty()) { + basicCardResponse.mCardSecurityCode.Construct(); + basicCardResponse.mCardSecurityCode.Value() = rawData.cardSecurityCode; + } + if (!rawData.billingAddress.country.IsEmpty() || + !rawData.billingAddress.addressLine.IsEmpty() || + !rawData.billingAddress.region.IsEmpty() || + !rawData.billingAddress.regionCode.IsEmpty() || + !rawData.billingAddress.city.IsEmpty() || + !rawData.billingAddress.dependentLocality.IsEmpty() || + !rawData.billingAddress.postalCode.IsEmpty() || + !rawData.billingAddress.sortingCode.IsEmpty() || + !rawData.billingAddress.organization.IsEmpty() || + !rawData.billingAddress.recipient.IsEmpty() || + !rawData.billingAddress.phone.IsEmpty()) { + basicCardResponse.mBillingAddress.Construct(); + basicCardResponse.mBillingAddress.Value() = + new PaymentAddress(GetOwner(), + rawData.billingAddress.country, + rawData.billingAddress.addressLine, + rawData.billingAddress.region, + rawData.billingAddress.regionCode, + rawData.billingAddress.city, + rawData.billingAddress.dependentLocality, + rawData.billingAddress.postalCode, + rawData.billingAddress.sortingCode, + rawData.billingAddress.organization, + rawData.billingAddress.recipient, + rawData.billingAddress.phone); + } + MOZ_ASSERT(aCx); + JS::RootedValue value(aCx); + if (NS_WARN_IF(!basicCardResponse.ToObjectInternal(aCx, &value))) { + return; + } + aRetVal.set(&value.toObject()); + break; + } + default: { + MOZ_ASSERT(false); + break; } - aRetVal.set(&value.toObject()); } } @@ -275,7 +322,7 @@ void PaymentResponse::RespondRetry(const nsAString& aMethodName, const nsAString& aShippingOption, PaymentAddress* aShippingAddress, - const nsAString& aDetails, + const ResponseData& aDetails, const nsAString& aPayerName, const nsAString& aPayerEmail, const nsAString& aPayerPhone) diff --git a/dom/payments/PaymentResponse.h b/dom/payments/PaymentResponse.h index 861c48364f71..0186a162792e 100644 --- a/dom/payments/PaymentResponse.h +++ b/dom/payments/PaymentResponse.h @@ -19,6 +19,83 @@ class PaymentAddress; class PaymentRequest; class Promise; +class GeneralData final +{ +public: + GeneralData() = default; + ~GeneralData() = default; + nsString data; +}; + +class BasicCardData final +{ +public: + struct Address { + nsString country; + nsTArray addressLine; + nsString region; + nsString regionCode; + nsString city; + nsString dependentLocality; + nsString postalCode; + nsString sortingCode; + nsString organization; + nsString recipient; + nsString phone; + }; + BasicCardData() = default; + ~BasicCardData() = default; + + nsString cardholderName; + nsString cardNumber; + nsString expiryMonth; + nsString expiryYear; + nsString cardSecurityCode; + Address billingAddress; +}; + +class ResponseData final +{ +public: + enum Type { + Unknown = 0, + GeneralResponse = 1, + BasicCardResponse + }; + ResponseData() + : mType(ResponseData::Unknown) + {} + explicit ResponseData(const GeneralData& aGeneralData) + : mType(GeneralResponse) + , mGeneralData(aGeneralData) + {} + explicit ResponseData(const BasicCardData& aBasicCardData) + : mType(BasicCardResponse) + , mBasicCardData(aBasicCardData) + {} + ResponseData& operator = (const GeneralData& aGeneralData) { + mType = GeneralResponse; + mGeneralData = aGeneralData; + mBasicCardData = BasicCardData(); + return *this; + } + ResponseData& operator = (const BasicCardData& aBasicCardData) { + mType = BasicCardResponse; + mGeneralData = GeneralData(); + mBasicCardData = aBasicCardData; + return *this; + } + virtual ~ResponseData() = default; + + const Type& type() const { return mType; } + const GeneralData& generalData() const { return mGeneralData; } + const BasicCardData& basicCardData() const { return mBasicCardData;} +private: + Type mType; + GeneralData mGeneralData; + BasicCardData mBasicCardData; +}; + class PaymentResponse final : public DOMEventTargetHelper , public nsITimerCallback @@ -37,7 +114,7 @@ public: const nsAString& aMethodName, const nsAString& aShippingOption, PaymentAddress* aShippingAddress, - const nsAString& aDetails, + const ResponseData& aDetails, const nsAString& aPayerName, const nsAString& aPayerEmail, const nsAString& aPayerPhone); @@ -80,7 +157,7 @@ public: void RespondRetry(const nsAString& aMethodName, const nsAString& aShippingOption, PaymentAddress* aShippingAddress, - const nsAString& aDetails, + const ResponseData& aDetails, const nsAString& aPayerName, const nsAString& aPayerEmail, const nsAString& aPayerPhone); @@ -103,7 +180,7 @@ private: PaymentRequest* mRequest; nsString mRequestId; nsString mMethodName; - nsString mDetails; + ResponseData mDetails; nsString mShippingOption; nsString mPayerName; nsString mPayerEmail; diff --git a/dom/payments/ipc/PPaymentRequest.ipdl b/dom/payments/ipc/PPaymentRequest.ipdl index 7c634e4fc037..0e12dfea145c 100644 --- a/dom/payments/ipc/PPaymentRequest.ipdl +++ b/dom/payments/ipc/PPaymentRequest.ipdl @@ -138,12 +138,48 @@ struct IPCPaymentCanMakeActionResponse bool result; }; +struct IPCPaymentAddress +{ + nsString country; + nsString[] addressLine; + nsString region; + nsString regionCode; + nsString city; + nsString dependentLocality; + nsString postalCode; + nsString sortingCode; + nsString organization; + nsString recipient; + nsString phone; +}; + +struct IPCGeneralResponse +{ + nsString data; +}; + +struct IPCBasicCardResponse +{ + nsString cardholderName; + nsString cardNumber; + nsString expiryMonth; + nsString expiryYear; + nsString cardSecurityCode; + IPCPaymentAddress billingAddress; +}; + +union IPCPaymentResponseData +{ + IPCGeneralResponse; + IPCBasicCardResponse; +}; + struct IPCPaymentShowActionResponse { nsString requestId; uint32_t status; nsString methodName; - nsString data; + IPCPaymentResponseData data; nsString payerName; nsString payerEmail; nsString payerPhone; @@ -169,21 +205,6 @@ union IPCPaymentActionResponse IPCPaymentCompleteActionResponse; }; -struct IPCPaymentAddress -{ - nsString country; - nsString[] addressLine; - nsString region; - nsString regionCode; - nsString city; - nsString dependentLocality; - nsString postalCode; - nsString sortingCode; - nsString organization; - nsString recipient; - nsString phone; -}; - sync protocol PPaymentRequest { manager PBrowser; diff --git a/dom/payments/ipc/PaymentRequestParent.cpp b/dom/payments/ipc/PaymentRequestParent.cpp index 6a036fe41b2a..a4feb0e7bbcb 100644 --- a/dom/payments/ipc/PaymentRequestParent.cpp +++ b/dom/payments/ipc/PaymentRequestParent.cpp @@ -138,8 +138,17 @@ PaymentRequestParent::RespondPayment(nsIPaymentActionResponse* aResponse) NS_ENSURE_SUCCESS(response->GetAcceptStatus(&acceptStatus), NS_ERROR_FAILURE); nsAutoString methodName; NS_ENSURE_SUCCESS(response->GetMethodName(methodName), NS_ERROR_FAILURE); - nsAutoString data; - NS_ENSURE_SUCCESS(response->GetData(data), NS_ERROR_FAILURE); + IPCPaymentResponseData ipcData; + if (acceptStatus == nsIPaymentActionResponse::PAYMENT_ACCEPTED) { + nsCOMPtr data; + NS_ENSURE_SUCCESS(response->GetData(getter_AddRefs(data)), + NS_ERROR_FAILURE); + MOZ_ASSERT(data); + NS_ENSURE_SUCCESS(SerializeResponseData(ipcData, data), NS_ERROR_FAILURE); + } else { + ipcData = IPCGeneralResponse(); + } + nsAutoString payerName; NS_ENSURE_SUCCESS(response->GetPayerName(payerName), NS_ERROR_FAILURE); nsAutoString payerEmail; @@ -149,7 +158,7 @@ PaymentRequestParent::RespondPayment(nsIPaymentActionResponse* aResponse) IPCPaymentShowActionResponse actionResponse(requestId, acceptStatus, methodName, - data, + ipcData, payerName, payerEmail, payerPhone); @@ -209,67 +218,11 @@ PaymentRequestParent::ChangeShippingAddress(const nsAString& aRequestId, if (!mActorAlive) { return NS_ERROR_FAILURE; } - nsAutoString country; - nsresult rv = aAddress->GetCountry(country); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr iaddressLine; - rv = aAddress->GetAddressLine(getter_AddRefs(iaddressLine)); + IPCPaymentAddress ipcAddress; + nsresult rv = SerializeAddress(ipcAddress, aAddress); NS_ENSURE_SUCCESS(rv, rv); - nsAutoString region; - rv = aAddress->GetRegion(region); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString regionCode; - rv = aAddress->GetRegionCode(regionCode); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString city; - rv = aAddress->GetCity(city); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString dependentLocality; - rv = aAddress->GetDependentLocality(dependentLocality); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString postalCode; - rv = aAddress->GetPostalCode(postalCode); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString sortingCode; - rv = aAddress->GetSortingCode(sortingCode); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString organization; - rv = aAddress->GetOrganization(organization); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString recipient; - rv = aAddress->GetRecipient(recipient); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoString phone; - rv = aAddress->GetPhone(phone); - NS_ENSURE_SUCCESS(rv, rv); - - nsTArray addressLine; - uint32_t length; - rv = iaddressLine->GetLength(&length); - NS_ENSURE_SUCCESS(rv, rv); - for (uint32_t index = 0; index < length; ++index) { - nsCOMPtr iaddress = do_QueryElementAt(iaddressLine, index); - MOZ_ASSERT(iaddress); - nsAutoString address; - rv = iaddress->GetData(address); - NS_ENSURE_SUCCESS(rv, rv); - addressLine.AppendElement(address); - } - - IPCPaymentAddress ipcAddress(country, addressLine, region, regionCode, city, - dependentLocality, postalCode, sortingCode, - organization, recipient, phone); - nsAutoString requestId(aRequestId); if (!SendChangeShippingAddress(requestId, ipcAddress)) { return NS_ERROR_FAILURE; @@ -360,5 +313,122 @@ PaymentRequestParent::ActorDestroy(ActorDestroyReason aWhy) rowRequest->SetIPC(nullptr); } } + +nsresult +PaymentRequestParent::SerializeAddress(IPCPaymentAddress& aIPCAddress, + nsIPaymentAddress* aAddress) +{ + // address can be nullptr + if (!aAddress) { + return NS_OK; + } + nsAutoString country; + nsresult rv = aAddress->GetCountry(country); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr iaddressLine; + rv = aAddress->GetAddressLine(getter_AddRefs(iaddressLine)); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString region; + rv = aAddress->GetRegion(region); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString regionCode; + rv = aAddress->GetRegionCode(regionCode); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString city; + rv = aAddress->GetCity(city); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString dependentLocality; + rv = aAddress->GetDependentLocality(dependentLocality); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString postalCode; + rv = aAddress->GetPostalCode(postalCode); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString sortingCode; + rv = aAddress->GetSortingCode(sortingCode); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString organization; + rv = aAddress->GetOrganization(organization); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString recipient; + rv = aAddress->GetRecipient(recipient); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString phone; + rv = aAddress->GetPhone(phone); + NS_ENSURE_SUCCESS(rv, rv); + + nsTArray addressLine; + uint32_t length; + rv = iaddressLine->GetLength(&length); + NS_ENSURE_SUCCESS(rv, rv); + for (uint32_t index = 0; index < length; ++index) { + nsCOMPtr iaddress = do_QueryElementAt(iaddressLine, index); + MOZ_ASSERT(iaddress); + nsAutoString address; + rv = iaddress->GetData(address); + NS_ENSURE_SUCCESS(rv, rv); + addressLine.AppendElement(address); + } + + aIPCAddress = IPCPaymentAddress(country, addressLine, region, regionCode, city, + dependentLocality, postalCode, sortingCode, + organization, recipient, phone); + return NS_OK; +} + +nsresult +PaymentRequestParent::SerializeResponseData(IPCPaymentResponseData& aIPCData, + nsIPaymentResponseData* aData) +{ + NS_ENSURE_ARG_POINTER(aData); + uint32_t dataType; + NS_ENSURE_SUCCESS(aData->GetType(&dataType), NS_ERROR_FAILURE); + switch(dataType) { + case nsIPaymentResponseData::GENERAL_RESPONSE: { + nsCOMPtr response = do_QueryInterface(aData); + MOZ_ASSERT(response); + IPCGeneralResponse data; + NS_ENSURE_SUCCESS(response->GetData(data.data()), NS_ERROR_FAILURE); + aIPCData = data; + break; + } + case nsIPaymentResponseData::BASICCARD_RESPONSE: { + nsCOMPtr response = do_QueryInterface(aData); + MOZ_ASSERT(response); + IPCBasicCardResponse data; + NS_ENSURE_SUCCESS(response->GetCardholderName(data.cardholderName()), + NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(response->GetCardNumber(data.cardNumber()), + NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(response->GetExpiryMonth(data.expiryMonth()), + NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(response->GetExpiryYear(data.expiryYear()), + NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(response->GetCardSecurityCode(data.cardSecurityCode()), + NS_ERROR_FAILURE); + nsCOMPtr address; + NS_ENSURE_SUCCESS(response->GetBillingAddress(getter_AddRefs(address)), + NS_ERROR_FAILURE); + IPCPaymentAddress ipcAddress; + NS_ENSURE_SUCCESS(SerializeAddress(ipcAddress, address), NS_ERROR_FAILURE); + data.billingAddress() = ipcAddress; + aIPCData = data; + break; + } + default: { + return NS_ERROR_FAILURE; + } + } + return NS_OK; +} } // end of namespace dom } // end of namespace mozilla diff --git a/dom/payments/ipc/PaymentRequestParent.h b/dom/payments/ipc/PaymentRequestParent.h index 8eba85c5f4e4..fcebd6b9c1cb 100644 --- a/dom/payments/ipc/PaymentRequestParent.h +++ b/dom/payments/ipc/PaymentRequestParent.h @@ -41,6 +41,11 @@ protected: private: ~PaymentRequestParent() = default; + nsresult SerializeAddress(IPCPaymentAddress& ipcAddress, + nsIPaymentAddress* aAddress); + nsresult SerializeResponseData(IPCPaymentResponseData& ipcData, + nsIPaymentResponseData* aData); + bool mActorAlive; uint64_t mTabId; nsString mRequestId; diff --git a/dom/payments/test/BasiccardChromeScript.js b/dom/payments/test/BasiccardChromeScript.js index 81a38a4142e6..ee246642ce8d 100644 --- a/dom/payments/test/BasiccardChromeScript.js +++ b/dom/payments/test/BasiccardChromeScript.js @@ -29,6 +29,24 @@ billingAddress.init("USA", // country "Bill A. Pacheco", // recipient "+14344413879"); // phone +const specialAddress = Cc["@mozilla.org/dom/payments/payment-address;1"]. + createInstance(Ci.nsIPaymentAddress); +const specialAddressLine = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray); +const specialData = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString); +specialData.data = ":$%@&*"; +specialAddressLine.appendElement(specialData); +specialAddress.init("USA", // country + specialAddressLine, // address line + "CA", // region + "CA", // region code + "San Bruno", // city + "", // dependent locality + "94066", // postal code + "123456", // sorting code + "", // organization + "Bill A. Pacheco", // recipient + "+14344413879"); // phone + const basiccardResponseData = Cc["@mozilla.org/dom/payments/basiccard-response-data;1"]. createInstance(Ci.nsIBasicCardResponseData); @@ -109,6 +127,36 @@ const simpleResponseUI = { QueryInterface: ChromeUtils.generateQI([Ci.nsIPaymentUIService]), }; +const specialAddressUI = { + showPayment: function(requestId) { + try { + basiccardResponseData.initData("Bill A. Pacheco", // cardholderName + "4916855166538720", // cardNumber + "01", // expiryMonth + "2024", // expiryYear + "180", // cardSecurityCode + specialAddress); // billingAddress + } catch (e) { + emitTestFail("Fail to initialize basic card response data."); + } + showResponse.init(requestId, + Ci.nsIPaymentActionResponse.PAYMENT_ACCEPTED, + "basic-card", // payment method + basiccardResponseData,// payment method data + "Bill A. Pacheco", // payer name + "", // payer email + ""); // payer phone + paymentSrv.respondPayment(showResponse.QueryInterface(Ci.nsIPaymentActionResponse)); + }, + abortPayment: abortPaymentResponse, + completePayment: completePaymentResponse, + updatePayment: function(requestId) { + }, + closePayment: function (requestId) { + }, + QueryInterface: ChromeUtils.generateQI([Ci.nsIPaymentUIService]), +}; + addMessageListener("set-detailed-ui-service", function() { paymentSrv.setTestingUIService(detailedResponseUI.QueryInterface(Ci.nsIPaymentUIService)); }); @@ -117,6 +165,10 @@ addMessageListener("set-simple-ui-service", function() { paymentSrv.setTestingUIService(simpleResponseUI.QueryInterface(Ci.nsIPaymentUIService)); }); +addMessageListener("set-special-address-ui-service", function() { + paymentSrv.setTestingUIService(specialAddressUI.QueryInterface(Ci.nsIPaymentUIService)); +}); + addMessageListener("error-response-test", function() { // test empty cardNumber try { diff --git a/dom/payments/test/test_basiccard.html b/dom/payments/test/test_basiccard.html index 2df66c8e543a..c643f655db82 100644 --- a/dom/payments/test/test_basiccard.html +++ b/dom/payments/test/test_basiccard.html @@ -241,6 +241,24 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345 }); } + function testSpecialAddressResponse() { + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true); + gScript.sendAsyncMessage("set-special-address-ui-service"); + return new Promise((resolve, reject) => { + const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions); + payRequest.show().then(response => { + ok(response.details, "BasiccardResponse should exist."); + ok(response.details.billingAddress, + "BasiccardResponse.billingAddress should exist."); + is(response.details.billingAddress.addressLine[0], ":$%@&*", + "AddressLine should be ':$%@&*'"); + response.complete("success").then(()=>{ + resolve(); + }); + }).finally(handler.destruct); + }); + } + function testBasicCardErrorResponse() { return new Promise((resolve, reject) => { gScript.addMessageListener("error-response-complete", @@ -272,6 +290,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345 .then(testCanMakePaymentWithBasicCardRequest) .then(testBasicCardSimpleResponse) .then(testBasicCardDetailedResponse) + .then(testSpecialAddressResponse) .then(testBasicCardErrorResponse) .then(teardown) .catch( e => {