Backed out 4 changesets (bug 1477117) for causing hazard build bustage on payments/PaymentRequest.cpp:1066 CLOSED TREE

Backed out changeset 3b473ca68a57 (bug 1477117)
Backed out changeset 8ffc94b44c3e (bug 1477117)
Backed out changeset ddaac3335514 (bug 1477117)
Backed out changeset 1809212f5f29 (bug 1477117)
This commit is contained in:
arthur.iakab 2018-11-28 02:28:36 +02:00
Родитель 1690a0092c
Коммит e36b9a7f34
27 изменённых файлов: 255 добавлений и 1029 удалений

Просмотреть файл

@ -292,77 +292,6 @@ interface nsIPaymentCompleteActionResponse : nsIPaymentActionResponse
bool isCompleted();
};
[builtinclass, scriptable, uuid(2035e0a9-c9ab-4c9f-b8e9-28b2ed61548c)]
interface nsIMethodChangeDetails : nsISupports
{
/**
* The consts for representing the method change details data type.
* GENERAL_DETAILS is the general purpose details data type. Except basic
* card details, all details should belong to this type.
* BASICCARD_DETAILS is a special details data type for basic card change
* details.
*/
const uint32_t GENERAL_DETAILS = 0;
const uint32_t BASICCARD_DETAILS = 1;
/**
* The method change details data type.
* Using the above defined consts(GENERAL_DETAILS or BASICCARD_DETAILS).
*/
readonly attribute uint32_t type;
/**
* The initial method.
* @param aType - the method change details data type.
*/
void init(in uint32_t aType);
};
/**
* The general purpose method change details.
*/
[builtinclass, scriptable, uuid(e031267e-bec8-4f3c-b0b1-396b77ca260c)]
interface nsIGeneralChangeDetails : nsIMethodChangeDetails
{
/**
* The stringified change details.
*/
readonly attribute AString details;
/**
* The initial method for nsIGeneralChangeDetails.
* @param aData - the javascript object of the content.
*/
[implicit_jscontext]
void initData(in jsval aDetails);
};
/**
* The basic card change details.
* Since PaymentAddress is an no constructor interface type, UI code can not
* easy create PaymentAddress by calling new PaymentAddress().
* Unfortunately, BasicCardResponse has a PaymentAddress attribute, billingAddress
* , it means UI can not create BsaicCardChangeDetails by calling the init() with a
* given JSObject directly, because PaymentAddress creation in JS code is hard.
* To let UI code can create BasicCardResponse easier, nsIBasicCardResponse is
* provided for UI by passing the raw data of BasicCardResponse,
*/
[builtinclass, scriptable, uuid(5296f79e-15ea-40c3-8196-19cfa64d328c)]
interface nsIBasicCardChangeDetails : nsIMethodChangeDetails
{
/**
* The billing address.
*/
readonly attribute nsIPaymentAddress billingAddress;
/**
* The initial method for nsIBasicCardChangeDetails.
* @param aBillingAddreess - the billing address.
*/
void initData(in nsIPaymentAddress billingAddress);
};
%{C++
#define NS_GENERAL_RESPONSE_DATA_CID \
{ 0xb986773e, 0x2b30, 0x4ed2, { 0xb8, 0xfe, 0x6a, 0x96, 0x63, 0x1c, 0x80, 0x00 } }
@ -393,14 +322,4 @@ interface nsIBasicCardChangeDetails : nsIMethodChangeDetails
{ 0x62c01e69, 0x9ca4, 0x4060, { 0x99, 0xe4, 0xb9, 0x5f, 0x62, 0x8c, 0x8e, 0x6d } }
#define NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CONTRACT_ID \
"@mozilla.org/dom/payments/payment-complete-action-response;1"
#define NS_GENERAL_CHANGE_DETAILS_CID \
{ 0xe031267e, 0xbec8, 0x4f3c, { 0xb0, 0xb1, 0x39, 0x6b, 0x77, 0xca, 0x26, 0x0c } }
#define NS_GENERAL_CHANGE_DETAILS_CONTRACT_ID \
"@mozilla.org/dom/payments/general-change-details;1"
#define NS_BASICCARD_CHANGE_DETAILS_CID \
{ 0x5296f79e, 0x15ea, 0x40c3, { 0x81, 0x96, 0x19, 0xcf, 0xa6, 0x4d, 0x32, 0x8c } }
#define NS_BASICCARD_CHANGE_DETAILS_CONTRACT_ID \
"@mozilla.org/dom/payments/basiccard-change-details;1"
%}

Просмотреть файл

@ -75,7 +75,6 @@ interface nsIPaymentOptions : nsISupports
readonly attribute boolean requestPayerEmail;
readonly attribute boolean requestPayerPhone;
readonly attribute boolean requestShipping;
readonly attribute boolean requestBillingAddress;
readonly attribute AString shippingType;
};

Просмотреть файл

@ -66,17 +66,6 @@ interface nsIPaymentRequestService : nsISupports
in AString aPayerEmail,
in AString aPayerPhone);
/**
* Inform the merchant the payment method has changed.
* @param requestId - the request identifier of the payment request.
* @param aMethodName - the changed payment method's name.
* @param aMethodDetails - the changed payment method's details.
*/
void changePaymentMethod(in AString requestId,
in AString aMethodName,
in nsIMethodChangeDetails aMethodDetails);
/**
* Following APIs are for testing or platform code only. UI implementation
* should not use them.

Просмотреть файл

@ -389,88 +389,5 @@ PaymentCompleteActionResponse::IsCompleted(bool* aIsCompleted)
return NS_OK;
}
/* PaymentChangeDetails */
NS_IMPL_ISUPPORTS(MethodChangeDetails, nsIMethodChangeDetails)
NS_IMETHODIMP
MethodChangeDetails::GetType(uint32_t* aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = mType;
return NS_OK;
}
NS_IMETHODIMP
MethodChangeDetails::Init(const uint32_t aType)
{
if (aType != nsIMethodChangeDetails::GENERAL_DETAILS &&
aType != nsIMethodChangeDetails::BASICCARD_DETAILS) {
return NS_ERROR_FAILURE;
}
mType = aType;
return NS_OK;
}
/* GeneralMethodChangeDetails */
NS_IMPL_ISUPPORTS_INHERITED(GeneralMethodChangeDetails,
MethodChangeDetails,
nsIGeneralChangeDetails)
GeneralMethodChangeDetails::GeneralMethodChangeDetails()
: mDetails(NS_LITERAL_STRING("{}"))
{
Init(nsIMethodChangeDetails::GENERAL_DETAILS);
}
NS_IMETHODIMP
GeneralMethodChangeDetails::GetDetails(nsAString& aDetails)
{
aDetails = mDetails;
return NS_OK;
}
NS_IMETHODIMP
GeneralMethodChangeDetails::InitData(JS::HandleValue aDetails, JSContext* aCx)
{
if (aDetails.isNullOrUndefined()) {
return NS_ERROR_FAILURE;
}
nsresult rv = SerializeFromJSVal(aCx, aDetails, mDetails);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
/* BasicCardMethodChangeDetails */
NS_IMPL_ISUPPORTS_INHERITED(BasicCardMethodChangeDetails,
MethodChangeDetails,
nsIBasicCardChangeDetails)
BasicCardMethodChangeDetails::BasicCardMethodChangeDetails()
{
Init(nsIMethodChangeDetails::BASICCARD_DETAILS);
}
NS_IMETHODIMP
BasicCardMethodChangeDetails::GetBillingAddress(nsIPaymentAddress** aBillingAddress)
{
NS_ENSURE_ARG_POINTER(aBillingAddress);
nsCOMPtr<nsIPaymentAddress> address;
address = mBillingAddress;
address.forget(aBillingAddress);
return NS_OK;
}
NS_IMETHODIMP
BasicCardMethodChangeDetails::InitData(nsIPaymentAddress* aBillingAddress)
{
mBillingAddress = aBillingAddress;
return NS_OK;
}
} // end of namespace dom
} // end of namespace mozilla

Просмотреть файл

@ -149,52 +149,6 @@ private:
uint32_t mCompleteStatus;
};
class MethodChangeDetails : public nsIMethodChangeDetails
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMETHODCHANGEDETAILS
MethodChangeDetails() = default;
protected:
virtual ~MethodChangeDetails() = default;
uint32_t mType;
};
class GeneralMethodChangeDetails final : public MethodChangeDetails
, public nsIGeneralChangeDetails
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_NSIMETHODCHANGEDETAILS(MethodChangeDetails::)
NS_DECL_NSIGENERALCHANGEDETAILS
GeneralMethodChangeDetails();
private:
~GeneralMethodChangeDetails() = default;
nsString mDetails;
};
class BasicCardMethodChangeDetails final : public MethodChangeDetails
, public nsIBasicCardChangeDetails
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_NSIMETHODCHANGEDETAILS(MethodChangeDetails::)
NS_DECL_NSIBASICCARDCHANGEDETAILS
BasicCardMethodChangeDetails();
private:
~BasicCardMethodChangeDetails() = default;
nsCOMPtr<nsIPaymentAddress> mBillingAddress;
};
} // end of dom
} // end of namespace mozilla

Просмотреть файл

@ -4,10 +4,9 @@
* 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 "BasicCardPayment.h"
#include "mozilla/dom/PaymentMethodChangeEvent.h"
#include "mozilla/dom/PaymentRequestUpdateEvent.h"
#include "PaymentRequestUtils.h"
#include "mozilla/HoldDropJSObjects.h"
namespace mozilla {
namespace dom {
@ -15,6 +14,8 @@ namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(PaymentMethodChangeEvent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PaymentMethodChangeEvent,
PaymentRequestUpdateEvent)
tmp->mMethodDetails = nullptr;
mozilla::DropJSObjects(this);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PaymentMethodChangeEvent,
@ -23,6 +24,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(PaymentMethodChangeEvent,
PaymentRequestUpdateEvent)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mMethodDetails)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_ADDREF_INHERITED(PaymentMethodChangeEvent, PaymentRequestUpdateEvent)
@ -55,64 +57,22 @@ PaymentMethodChangeEvent::Constructor(
{
nsCOMPtr<mozilla::dom::EventTarget> owner =
do_QueryInterface(aGlobal.GetAsSupports());
RefPtr<PaymentMethodChangeEvent> event = Constructor(owner, aType, aEventInitDict);
if (!aEventInitDict.mMethodDetails) {
return event.forget();
}
ChangeDetails details;
RefPtr<BasicCardService> service = BasicCardService::GetService();
MOZ_ASSERT(service);
if (service->IsBasicCardPayment(aEventInitDict.mMethodName)) {
BasicCardChangeDetails methodDetails;
BasicCardDetails bcDetails;
JS::RootedValue value(aGlobal.Context(), JS::ObjectValue(*(aEventInitDict.mMethodDetails)));
if (!methodDetails.Init(aGlobal.Context(), value)) {
return event.forget();
} else {
if(methodDetails.mBillingAddress.WasPassed()) {
RefPtr<PaymentAddress> address = methodDetails.mBillingAddress.Value();
address->GetCountry(bcDetails.billingAddress.country);
address->GetAddressLine(bcDetails.billingAddress.addressLine);
address->GetCity(bcDetails.billingAddress.city);
address->GetRegion(bcDetails.billingAddress.region);
address->GetRegionCode(bcDetails.billingAddress.regionCode);
address->GetDependentLocality(bcDetails.billingAddress.dependentLocality);
address->GetPostalCode(bcDetails.billingAddress.postalCode);
address->GetSortingCode(bcDetails.billingAddress.sortingCode);
address->GetOrganization(bcDetails.billingAddress.organization);
address->GetRecipient(bcDetails.billingAddress.recipient);
address->GetPhone(bcDetails.billingAddress.phone);
}
details = bcDetails;
}
} else {
JS::RootedObject object(aGlobal.Context(), aEventInitDict.mMethodDetails);
nsAutoString serializedDetails;
nsresult rv = SerializeFromJSObject(aGlobal.Context(), object, serializedDetails);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
GeneralDetails gDetails;
gDetails.details = serializedDetails;
details = gDetails;
}
event->SetMethodDetails(details);
return event.forget();
return Constructor(owner, aType, aEventInitDict);
}
PaymentMethodChangeEvent::PaymentMethodChangeEvent(EventTarget* aOwner)
: PaymentRequestUpdateEvent(aOwner)
{
MOZ_ASSERT(aOwner);
mozilla::HoldJSObjects(this);
}
void
PaymentMethodChangeEvent::init(const PaymentMethodChangeEventInit& aEventInitDict)
PaymentMethodChangeEvent::init(
const PaymentMethodChangeEventInit& aEventInitDict)
{
mMethodName.Assign(aEventInitDict.mMethodName);
mMethodDetails = aEventInitDict.mMethodDetails;
}
void
@ -122,82 +82,15 @@ PaymentMethodChangeEvent::GetMethodName(nsAString& aMethodName)
}
void
PaymentMethodChangeEvent::SetMethodName(const nsAString& aMethodName)
PaymentMethodChangeEvent::GetMethodDetails(JSContext* cx,
JS::MutableHandle<JSObject*> retval)
{
mMethodName = aMethodName;
}
void
PaymentMethodChangeEvent::GetMethodDetails(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetVal)
{
MOZ_ASSERT(aCx);
RefPtr<BasicCardService> service = BasicCardService::GetService();
MOZ_ASSERT(service);
aRetVal.set(nullptr);
switch(mMethodDetails.type()) {
case ChangeDetails::GeneralMethodDetails: {
const GeneralDetails& rawDetails = mMethodDetails.generalDetails();
DeserializeToJSObject(rawDetails.details, aCx, aRetVal);
break;
}
case ChangeDetails::BasicCardMethodDetails: {
const BasicCardDetails& rawDetails = mMethodDetails.basicCardDetails();
BasicCardChangeDetails basicCardDetails;
PaymentOptions options;
mRequest->GetOptions(options);
if (options.mRequestBillingAddress) {
if (!rawDetails.billingAddress.country.IsEmpty() ||
!rawDetails.billingAddress.addressLine.IsEmpty() ||
!rawDetails.billingAddress.region.IsEmpty() ||
!rawDetails.billingAddress.regionCode.IsEmpty() ||
!rawDetails.billingAddress.city.IsEmpty() ||
!rawDetails.billingAddress.dependentLocality.IsEmpty() ||
!rawDetails.billingAddress.postalCode.IsEmpty() ||
!rawDetails.billingAddress.sortingCode.IsEmpty() ||
!rawDetails.billingAddress.organization.IsEmpty() ||
!rawDetails.billingAddress.recipient.IsEmpty() ||
!rawDetails.billingAddress.phone.IsEmpty()) {
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetParentObject());
basicCardDetails.mBillingAddress.Construct();
basicCardDetails.mBillingAddress.Value() =
new PaymentAddress(window,
rawDetails.billingAddress.country,
rawDetails.billingAddress.addressLine,
rawDetails.billingAddress.region,
rawDetails.billingAddress.regionCode,
rawDetails.billingAddress.city,
rawDetails.billingAddress.dependentLocality,
rawDetails.billingAddress.postalCode,
rawDetails.billingAddress.sortingCode,
rawDetails.billingAddress.organization,
rawDetails.billingAddress.recipient,
rawDetails.billingAddress.phone);
}
}
MOZ_ASSERT(aCx);
JS::RootedValue value(aCx);
if (NS_WARN_IF(!basicCardDetails.ToObjectInternal(aCx, &value))) {
return;
}
aRetVal.set(&value.toObject());
break;
}
default: {
break;
}
}
}
void
PaymentMethodChangeEvent::SetMethodDetails(const ChangeDetails& aMethodDetails)
{
mMethodDetails = aMethodDetails;
retval.set(mMethodDetails.get());
}
PaymentMethodChangeEvent::~PaymentMethodChangeEvent()
{
mozilla::DropJSObjects(this);
}
JSObject*

Просмотреть файл

@ -42,17 +42,15 @@ public:
ErrorResult& aRv);
void GetMethodName(nsAString& aMethodName);
void SetMethodName(const nsAString& aMethodName);
void GetMethodDetails(JSContext* cx, JS::MutableHandle<JSObject*> retval);
void SetMethodDetails(const ChangeDetails& aMethodDetails);
protected:
void init(const PaymentMethodChangeEventInit& aEventInitDict);
~PaymentMethodChangeEvent();
private:
ChangeDetails mMethodDetails;
JS::Heap<JSObject*> mMethodDetails;
nsString mMethodName;
};

Просмотреть файл

@ -1042,30 +1042,6 @@ PaymentRequest::DispatchMerchantValidationEvent(const nsAString& aType)
return rv.StealNSResult();
}
nsresult
PaymentRequest::DispatchPaymentMethodChangeEvent(const nsAString& aMethodName,
const ChangeDetails& aMethodDetails)
{
MOZ_ASSERT(ReadyForUpdate());
PaymentMethodChangeEventInit init;
init.mBubbles = false;
init.mCancelable = false;
RefPtr<PaymentMethodChangeEvent> event =
PaymentMethodChangeEvent::Constructor(this,
NS_LITERAL_STRING("paymentmethodchange"),
init);
event->SetTrusted(true);
event->SetMethodName(aMethodName);
event->SetMethodDetails(aMethodDetails);
event->SetRequest(this);
ErrorResult rv;
DispatchEvent(*event, rv);
return rv.StealNSResult();
}
already_AddRefed<PaymentAddress>
PaymentRequest::GetShippingAddress() const
{
@ -1122,13 +1098,6 @@ PaymentRequest::UpdateShippingOption(const nsAString& aShippingOption)
return DispatchUpdateEvent(NS_LITERAL_STRING("shippingoptionchange"));
}
nsresult
PaymentRequest::UpdatePaymentMethod(const nsAString& aMethodName,
const ChangeDetails& aMethodDetails)
{
return DispatchPaymentMethodChangeEvent(aMethodName, aMethodDetails);
}
void
PaymentRequest::SetShippingType(const Nullable<PaymentShippingType>& aShippingType)
{

Просмотреть файл

@ -19,83 +19,12 @@
namespace mozilla {
namespace dom {
class EventHandlerNonNull;
class PaymentAddress;
class PaymentRequestChild;
class PaymentResponse;
class ResponseData;
class GeneralDetails final
{
public:
GeneralDetails() = default;
~GeneralDetails() = default;
nsString details;
};
class BasicCardDetails final
{
public:
struct Address {
nsString country;
nsTArray<nsString> addressLine;
nsString region;
nsString regionCode;
nsString city;
nsString dependentLocality;
nsString postalCode;
nsString sortingCode;
nsString organization;
nsString recipient;
nsString phone;
};
BasicCardDetails() = default;
~BasicCardDetails() = default;
Address billingAddress;
};
class ChangeDetails final
{
public:
enum Type {
Unknown = 0,
GeneralMethodDetails = 1,
BasicCardMethodDetails
};
ChangeDetails()
: mType(ChangeDetails::Unknown)
{}
explicit ChangeDetails(const GeneralDetails& aGeneralDetails)
: mType(GeneralMethodDetails)
, mGeneralDetails(aGeneralDetails)
{}
explicit ChangeDetails(const BasicCardDetails& aBasicCardDetails)
: mType(BasicCardMethodDetails)
, mBasicCardDetails(aBasicCardDetails)
{}
ChangeDetails& operator = (const GeneralDetails& aGeneralDetails) {
mType = GeneralMethodDetails;
mGeneralDetails = aGeneralDetails;
mBasicCardDetails = BasicCardDetails();
return *this;
}
ChangeDetails& operator = (const BasicCardDetails& aBasicCardDetails) {
mType = BasicCardMethodDetails;
mGeneralDetails = GeneralDetails();
mBasicCardDetails = aBasicCardDetails;
return *this;
}
~ChangeDetails() = default;
const Type& type() const { return mType; }
const GeneralDetails& generalDetails() const { return mGeneralDetails; }
const BasicCardDetails& basicCardDetails() const { return mBasicCardDetails;}
private:
Type mType;
GeneralDetails mGeneralDetails;
BasicCardDetails mBasicCardDetails;
};
class PaymentRequest final
: public DOMEventTargetHelper
, public PromiseNativeHandler
@ -168,7 +97,7 @@ public:
const Optional<OwningNonNull<Promise>>& detailsPromise,
ErrorResult& aRv);
void RespondShowPayment(const nsAString& aMethodName,
const ResponseData& aData,
const ResponseData& aDetails,
const nsAString& aPayerName,
const nsAString& aPayerEmail,
const nsAString& aPayerPhone,
@ -222,9 +151,6 @@ public:
inline void ShippingWasRequested() { mRequestShipping = true; }
nsresult UpdatePaymentMethod(const nsAString& aMethodName,
const ChangeDetails& aMethodDetails);
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
@ -250,9 +176,6 @@ protected:
nsresult DispatchMerchantValidationEvent(const nsAString& aType);
nsresult DispatchPaymentMethodChangeEvent(const nsAString& aMethodName,
const ChangeDetails& aMethodDatils);
PaymentRequest(nsPIDOMWindowInner* aWindow, const nsAString& aInternalId);
// Id for internal identification

Просмотреть файл

@ -605,13 +605,11 @@ PaymentOptions::PaymentOptions(const bool aRequestPayerName,
const bool aRequestPayerEmail,
const bool aRequestPayerPhone,
const bool aRequestShipping,
const bool aRequestBillingAddress,
const nsAString& aShippingType)
: mRequestPayerName(aRequestPayerName)
, mRequestPayerEmail(aRequestPayerEmail)
, mRequestPayerPhone(aRequestPayerPhone)
, mRequestShipping(aRequestShipping)
, mRequestBillingAddress(aRequestBillingAddress)
, mShippingType(aShippingType)
{
}
@ -627,7 +625,6 @@ PaymentOptions::Create(const IPCPaymentOptions& aIPCOptions,
aIPCOptions.requestPayerEmail(),
aIPCOptions.requestPayerPhone(),
aIPCOptions.requestShipping(),
aIPCOptions.requestBillingAddress(),
aIPCOptions.shippingType());
options.forget(aOptions);
return NS_OK;
@ -665,14 +662,6 @@ PaymentOptions::GetRequestShipping(bool* aRequestShipping)
return NS_OK;
}
NS_IMETHODIMP
PaymentOptions::GetRequestBillingAddress(bool* aRequestBillingAddress)
{
NS_ENSURE_ARG_POINTER(aRequestBillingAddress);
*aRequestBillingAddress = mRequestBillingAddress;
return NS_OK;
}
NS_IMETHODIMP
PaymentOptions::GetShippingType(nsAString& aShippingType)
{

Просмотреть файл

@ -176,7 +176,6 @@ private:
const bool aRequestPayerEmail,
const bool aRequestPayerPhone,
const bool aRequestShipping,
const bool aRequestBillingAddress,
const nsAString& aShippintType);
~PaymentOptions() = default;
@ -184,7 +183,6 @@ private:
bool mRequestPayerEmail;
bool mRequestPayerPhone;
bool mRequestShipping;
bool mRequestBillingAddress;
nsString mShippingType;
};

Просмотреть файл

@ -255,7 +255,6 @@ ConvertOptions(const PaymentOptions& aOptions,
aOptions.mRequestPayerEmail,
aOptions.mRequestPayerPhone,
aOptions.mRequestShipping,
aOptions.mRequestBillingAddress,
shippingType);
}
@ -299,43 +298,6 @@ ConvertResponseData(const IPCPaymentResponseData& aIPCData,
}
}
}
void
ConvertMethodChangeDetails(const IPCMethodChangeDetails& aIPCDetails,
ChangeDetails& aDetails)
{
switch (aIPCDetails.type()) {
case IPCMethodChangeDetails::TIPCGeneralChangeDetails : {
const IPCGeneralChangeDetails& details = aIPCDetails;
GeneralDetails gDetails;
gDetails.details = details.details();
aDetails = gDetails;
break;
}
case IPCMethodChangeDetails::TIPCBasicCardChangeDetails: {
const IPCBasicCardChangeDetails& details = aIPCDetails;
BasicCardDetails bDetails;
bDetails.billingAddress.country = details.billingAddress().country();
bDetails.billingAddress.addressLine = details.billingAddress().addressLine();
bDetails.billingAddress.region = details.billingAddress().region();
bDetails.billingAddress.regionCode = details.billingAddress().regionCode();
bDetails.billingAddress.city = details.billingAddress().city();
bDetails.billingAddress.dependentLocality =
details.billingAddress().dependentLocality();
bDetails.billingAddress.postalCode = details.billingAddress().postalCode();
bDetails.billingAddress.sortingCode = details.billingAddress().sortingCode();
bDetails.billingAddress.organization = details.billingAddress().organization();
bDetails.billingAddress.recipient = details.billingAddress().recipient();
bDetails.billingAddress.phone = details.billingAddress().phone();
aDetails = bDetails;
break;
}
default: {
break;
}
}
}
} // end of namespace
/* PaymentRequestManager */
@ -804,16 +766,5 @@ PaymentRequestManager::ChangePayerDetail(PaymentRequest* aRequest,
return response->UpdatePayerDetail(aPayerName, aPayerEmail, aPayerPhone);
}
nsresult
PaymentRequestManager::ChangePaymentMethod(PaymentRequest* aRequest,
const nsAString& aMethodName,
const IPCMethodChangeDetails& aMethodDetails)
{
NS_ENSURE_ARG_POINTER(aRequest);
ChangeDetails methodDetails;
ConvertMethodChangeDetails(aMethodDetails, methodDetails);
return aRequest->UpdatePaymentMethod(aMethodName, methodDetails);
}
} // end of namespace dom
} // end of namespace mozilla

Просмотреть файл

@ -67,13 +67,11 @@ public:
const IPCPaymentAddress& aAddress);
nsresult ChangeShippingOption(PaymentRequest* aRequest,
const nsAString& aOption);
nsresult ChangePayerDetail(PaymentRequest* aRequest,
const nsAString& aPayerName,
const nsAString& aPayerEmail,
const nsAString& aPayerPhone);
nsresult ChangePaymentMethod(PaymentRequest* aRequest,
const nsAString& aMethodName,
const IPCMethodChangeDetails& aMethodDetails);
bool IsRegionSupported(const nsAString& region) const;

Просмотреть файл

@ -15,8 +15,6 @@ using mozilla::dom::PaymentCanMakeActionResponse;
using mozilla::dom::PaymentAbortActionResponse;
using mozilla::dom::PaymentShowActionResponse;
using mozilla::dom::PaymentCompleteActionResponse;
using mozilla::dom::GeneralMethodChangeDetails;
using mozilla::dom::BasicCardMethodChangeDetails;
using mozilla::dom::payments::PaymentAddress;
using mozilla::dom::PaymentRequestService;
@ -26,8 +24,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentCanMakeActionResponse)
NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentAbortActionResponse)
NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentShowActionResponse)
NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentCompleteActionResponse)
NS_GENERIC_FACTORY_CONSTRUCTOR(GeneralMethodChangeDetails)
NS_GENERIC_FACTORY_CONSTRUCTOR(BasicCardMethodChangeDetails)
NS_GENERIC_FACTORY_CONSTRUCTOR(PaymentAddress)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(PaymentRequestService,
PaymentRequestService::GetSingleton)
@ -38,8 +34,6 @@ NS_DEFINE_NAMED_CID(NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CID);
NS_DEFINE_NAMED_CID(NS_PAYMENT_ABORT_ACTION_RESPONSE_CID);
NS_DEFINE_NAMED_CID(NS_PAYMENT_SHOW_ACTION_RESPONSE_CID);
NS_DEFINE_NAMED_CID(NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CID);
NS_DEFINE_NAMED_CID(NS_GENERAL_CHANGE_DETAILS_CID);
NS_DEFINE_NAMED_CID(NS_BASICCARD_CHANGE_DETAILS_CID);
NS_DEFINE_NAMED_CID(NS_PAYMENT_ADDRESS_CID);
NS_DEFINE_NAMED_CID(NS_PAYMENT_REQUEST_SERVICE_CID);
@ -50,8 +44,6 @@ static const mozilla::Module::CIDEntry kPaymentRequestCIDs[] = {
{ &kNS_PAYMENT_ABORT_ACTION_RESPONSE_CID, false, nullptr, PaymentAbortActionResponseConstructor},
{ &kNS_PAYMENT_SHOW_ACTION_RESPONSE_CID, false, nullptr, PaymentShowActionResponseConstructor},
{ &kNS_PAYMENT_COMPLETE_ACTION_RESPONSE_CID, false, nullptr, PaymentCompleteActionResponseConstructor},
{ &kNS_GENERAL_CHANGE_DETAILS_CID, false, nullptr, GeneralMethodChangeDetailsConstructor},
{ &kNS_BASICCARD_CHANGE_DETAILS_CID, false, nullptr, BasicCardMethodChangeDetailsConstructor},
{ &kNS_PAYMENT_ADDRESS_CID, false, nullptr, PaymentAddressConstructor},
{ &kNS_PAYMENT_REQUEST_SERVICE_CID, true, nullptr, PaymentRequestServiceConstructor },
{ nullptr }
@ -64,8 +56,6 @@ static const mozilla::Module::ContractIDEntry kPaymentRequestContracts[] = {
{ NS_PAYMENT_ABORT_ACTION_RESPONSE_CONTRACT_ID, &kNS_PAYMENT_ABORT_ACTION_RESPONSE_CID },
{ NS_PAYMENT_SHOW_ACTION_RESPONSE_CONTRACT_ID, &kNS_PAYMENT_SHOW_ACTION_RESPONSE_CID },
{ NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CONTRACT_ID, &kNS_PAYMENT_COMPLETE_ACTION_RESPONSE_CID },
{ NS_GENERAL_CHANGE_DETAILS_CONTRACT_ID, &kNS_GENERAL_CHANGE_DETAILS_CID },
{ NS_BASICCARD_CHANGE_DETAILS_CONTRACT_ID, &kNS_BASICCARD_CHANGE_DETAILS_CID },
{ NS_PAYMENT_ADDRESS_CONTRACT_ID, &kNS_PAYMENT_ADDRESS_CID },
{ NS_PAYMENT_REQUEST_SERVICE_CONTRACT_ID, &kNS_PAYMENT_REQUEST_SERVICE_CID },
{ nullptr }
@ -78,8 +68,6 @@ static const mozilla::Module::CategoryEntry kPaymentRequestCategories[] = {
{ "payment-request", "PaymentAbortActionResponse", NS_PAYMENT_ABORT_ACTION_RESPONSE_CONTRACT_ID },
{ "payment-request", "PaymentShowActionResponse", NS_PAYMENT_SHOW_ACTION_RESPONSE_CONTRACT_ID },
{ "payment-request", "PaymentCompleteActionResponse", NS_PAYMENT_COMPLETE_ACTION_RESPONSE_CONTRACT_ID },
{ "payment-request", "GeneralMethodChangeDetails", NS_GENERAL_CHANGE_DETAILS_CONTRACT_ID },
{ "payment-request", "BasicCardMethodChangeDetails", NS_BASICCARD_CHANGE_DETAILS_CONTRACT_ID },
{ "payment-request", "PaymentAddress", NS_PAYMENT_ADDRESS_CONTRACT_ID },
{ "payment-request", "PaymentRequestService", NS_PAYMENT_REQUEST_SERVICE_CONTRACT_ID },
{ nullptr }

Просмотреть файл

@ -4,12 +4,11 @@
* 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 "BasicCardPayment.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/BasicCardPaymentBinding.h"
#include "mozilla/dom/PaymentRequestParent.h"
#include "nsSimpleEnumerator.h"
#include "PaymentRequestService.h"
#include "BasicCardPayment.h"
#include "nsSimpleEnumerator.h"
namespace mozilla {
namespace dom {
@ -504,57 +503,6 @@ PaymentRequestService::ChangeShippingOption(const nsAString& aRequestId,
return NS_OK;
}
NS_IMETHODIMP
PaymentRequestService::ChangePayerDetail(const nsAString& aRequestId,
const nsAString& aPayerName,
const nsAString& aPayerEmail,
const nsAString& aPayerPhone)
{
RefPtr<payments::PaymentRequest> request;
nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
MOZ_ASSERT(request);
if (!request->GetIPC()) {
return NS_ERROR_FAILURE;
}
rv = request->GetIPC()->ChangePayerDetail(
aRequestId, aPayerName, aPayerEmail, aPayerPhone);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
PaymentRequestService::ChangePaymentMethod(const nsAString& aRequestId,
const nsAString& aMethodName,
nsIMethodChangeDetails* aMethodDetails)
{
RefPtr<payments::PaymentRequest> request;
nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (!request) {
return NS_ERROR_FAILURE;
}
if (request->GetState() != payments::PaymentRequest::eInteractive) {
return NS_ERROR_FAILURE;
}
if (!request->GetIPC()) {
return NS_ERROR_FAILURE;
}
rv = request->GetIPC()->ChangePaymentMethod(aRequestId,
aMethodName,
aMethodDetails);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
bool
PaymentRequestService::CanMakePayment(const nsAString& aRequestId)
{
@ -639,5 +587,28 @@ PaymentRequestService::IsBasicCardPayment(const nsAString& aRequestId)
return false;
}
NS_IMETHODIMP
PaymentRequestService::ChangePayerDetail(const nsAString& aRequestId,
const nsAString& aPayerName,
const nsAString& aPayerEmail,
const nsAString& aPayerPhone)
{
RefPtr<payments::PaymentRequest> request;
nsresult rv = GetPaymentRequestById(aRequestId, getter_AddRefs(request));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
MOZ_ASSERT(request);
if (!request->GetIPC()) {
return NS_ERROR_FAILURE;
}
rv = request->GetIPC()->ChangePayerDetail(
aRequestId, aPayerName, aPayerEmail, aPayerPhone);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
} // end of namespace dom
} // end of namespace mozilla

Просмотреть файл

@ -54,6 +54,8 @@ public:
protected:
~PaymentRequestUpdateEvent();
private:
// Indicating whether an updateWith()-initiated update is currently in progress.
bool mWaitForUpdate;
RefPtr<PaymentRequest> mRequest;

Просмотреть файл

@ -85,7 +85,7 @@ public:
mBasicCardData = aBasicCardData;
return *this;
}
~ResponseData() = default;
virtual ~ResponseData() = default;
const Type& type() const { return mType; }
const GeneralData& generalData() const { return mGeneralData; }

Просмотреть файл

@ -65,7 +65,6 @@ struct IPCPaymentOptions
bool requestPayerEmail;
bool requestPayerPhone;
bool requestShipping;
bool requestBillingAddress;
nsString shippingType;
};
@ -208,22 +207,6 @@ union IPCPaymentActionResponse
IPCPaymentCompleteActionResponse;
};
struct IPCGeneralChangeDetails
{
nsString details;
};
struct IPCBasicCardChangeDetails
{
IPCPaymentAddress billingAddress;
};
union IPCMethodChangeDetails
{
IPCGeneralChangeDetails;
IPCBasicCardChangeDetails;
};
sync protocol PPaymentRequest
{
manager PBrowser;
@ -243,9 +226,6 @@ child:
nsString aPayerName,
nsString aPayerEmail,
nsString aPayerPhone);
async ChangePaymentMethod(nsString aRequestId,
nsString aMethodName,
IPCMethodChangeDetails aMethodDetails);
};
} // end of namespace dom

Просмотреть файл

@ -101,24 +101,6 @@ PaymentRequestChild::RecvChangePayerDetail(const nsString& aRequestId,
return IPC_OK();
}
mozilla::ipc::IPCResult
PaymentRequestChild::RecvChangePaymentMethod(const nsString& aRequestId,
const nsString& aMethodName,
const IPCMethodChangeDetails& aMethodDetails)
{
if (!mRequest) {
return IPC_FAIL_NO_REASON(this);
}
RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
MOZ_ASSERT(manager);
RefPtr<PaymentRequest> request(mRequest);
nsresult rv = manager->ChangePaymentMethod(request, aMethodName, aMethodDetails);
if (NS_WARN_IF(NS_FAILED(rv))) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();
}
void
PaymentRequestChild::ActorDestroy(ActorDestroyReason aWhy)
{

Просмотреть файл

@ -41,11 +41,6 @@ protected:
const nsString& aPayerEmail,
const nsString& aPayerPhone) override;
mozilla::ipc::IPCResult
RecvChangePaymentMethod(const nsString& aRequestId,
const nsString& aMethodName,
const IPCMethodChangeDetails& aMethodDetails) override;
void ActorDestroy(ActorDestroyReason aWhy) override;
private:

Просмотреть файл

@ -277,67 +277,6 @@ PaymentRequestParent::ChangePayerDetail(const nsAString& aRequestId,
return NS_OK;
}
nsresult
PaymentRequestParent::ChangePaymentMethod(const nsAString& aRequestId,
const nsAString& aMethodName,
nsIMethodChangeDetails* aMethodDetails)
{
nsAutoString requestId(aRequestId);
nsAutoString methodName(aMethodName);
nsCOMPtr<nsIMethodChangeDetails> methodDetails(aMethodDetails);
if (!NS_IsMainThread()) {
RefPtr<PaymentRequestParent> self = this;
nsCOMPtr<nsIRunnable> r =
NS_NewRunnableFunction("dom::PaymentRequestParent::ChangePaymentMethod",
[self, requestId, methodName, methodDetails] ()
{
self->ChangePaymentMethod(requestId, methodName, methodDetails);
});
return NS_DispatchToMainThread(r);
}
if (!mActorAlive) {
return NS_ERROR_FAILURE;
}
// Convert nsIMethodChangeDetails to IPCMethodChangeDetails
// aMethodChangeDetails can be null
IPCMethodChangeDetails ipcChangeDetails;
if (aMethodDetails) {
uint32_t dataType;
NS_ENSURE_SUCCESS(aMethodDetails->GetType(&dataType), NS_ERROR_FAILURE);
switch(dataType) {
case nsIMethodChangeDetails::GENERAL_DETAILS: {
nsCOMPtr<nsIGeneralChangeDetails> details = do_QueryInterface(methodDetails);
MOZ_ASSERT(details);
IPCGeneralChangeDetails ipcGeneralDetails;
NS_ENSURE_SUCCESS(details->GetDetails(ipcGeneralDetails.details()), NS_ERROR_FAILURE);
ipcChangeDetails = ipcGeneralDetails;
break;
}
case nsIMethodChangeDetails::BASICCARD_DETAILS: {
nsCOMPtr<nsIBasicCardChangeDetails> details = do_QueryInterface(methodDetails);
MOZ_ASSERT(details);
IPCBasicCardChangeDetails ipcBasicCardDetails;
nsCOMPtr<nsIPaymentAddress> address;
NS_ENSURE_SUCCESS(details->GetBillingAddress(getter_AddRefs(address)),
NS_ERROR_FAILURE);
IPCPaymentAddress ipcAddress;
NS_ENSURE_SUCCESS(SerializeAddress(ipcAddress, address), NS_ERROR_FAILURE);
ipcBasicCardDetails.billingAddress() = ipcAddress;
ipcChangeDetails = ipcBasicCardDetails;
break;
}
default: {
return NS_ERROR_FAILURE;
}
}
}
if (!SendChangePaymentMethod(requestId, methodName, ipcChangeDetails)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
mozilla::ipc::IPCResult
PaymentRequestParent::Recv__delete__()
{

Просмотреть файл

@ -29,9 +29,6 @@ public:
const nsAString& aPayerName,
const nsAString& aPayerEmail,
const nsAString& aPayerPhone);
nsresult ChangePaymentMethod(const nsAString& aRequestId,
const nsAString& aMethodName,
nsIMethodChangeDetails* aMethodDetails);
protected:
mozilla::ipc::IPCResult

Просмотреть файл

@ -8,7 +8,7 @@ const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm
const paymentSrv = Cc["@mozilla.org/dom/payments/payment-request-service;1"].getService(Ci.nsIPaymentRequestService);
function emitTestFail(message) {
sendAsyncMessage("test-fail", `${DummyUIService.testName}: ${message}`);
sendAsyncMessage("test-fail", message);
}
const billingAddress = Cc["@mozilla.org/dom/payments/payment-address;1"].
@ -50,9 +50,6 @@ specialAddress.init("USA", // country
const basiccardResponseData = Cc["@mozilla.org/dom/payments/basiccard-response-data;1"].
createInstance(Ci.nsIBasicCardResponseData);
const basiccardChangeDetails = Cc["@mozilla.org/dom/payments/basiccard-change-details;1"].
createInstance(Ci.nsIBasicCardChangeDetails);
const showResponse = Cc["@mozilla.org/dom/payments/payment-show-action-response;1"].
createInstance(Ci.nsIPaymentShowActionResponse);
@ -70,69 +67,8 @@ function completePaymentResponse(requestId) {
paymentSrv.respondPayment(completeResponse.QueryInterface(Ci.nsIPaymentActionResponse));
}
function showRequest(requestId) {
if (DummyUIService.showAction === "payment-method-change") {
basiccardChangeDetails.initData(billingAddress);
try {
paymentSrv.changePaymentMethod(requestId, "basic-card", basiccardChangeDetails.QueryInterface(Ci.nsIMethodChangeDetails));
} catch (error) {
emitTestFail(`Unexpected error (${error.name}) when calling PaymentRequestService::changePaymentMethod`);
}
return;
}
if (DummyUIService.showAction === "detailBasicCardResponse") {
try {
basiccardResponseData.initData("Bill A. Pacheco", // cardholderName
"4916855166538720", // cardNumber
"01", // expiryMonth
"2024", // expiryYear
"180", // cardSecurityCode
billingAddress); // billingAddress
} catch (e) {
emitTestFail("Fail to initialize basic card response data.");
}
}
if (DummyUIService.showAction === "simpleBasicCardResponse") {
try {
basiccardResponseData.initData("", // cardholderName
"4916855166538720", // cardNumber
"", // expiryMonth
"", // expiryYear
"", // cardSecurityCode
null); // billingAddress
} catch (e) {
emitTestFail("Fail to initialize basic card response data.");
}
}
if (DummyUIService.showAction === "specialAddressResponse") {
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));
}
const DummyUIService = {
testName: "",
showAction: "",
showPayment: showRequest,
abortPayment: abortPaymentResponse,
completePayment: completePaymentResponse,
updatePayment: (requestId) => {
const detailedResponseUI = {
showPayment: function(requestId) {
try {
basiccardResponseData.initData("Bill A. Pacheco", // cardholderName
"4916855166538720", // cardNumber
@ -152,37 +88,88 @@ const DummyUIService = {
""); // payer phone
paymentSrv.respondPayment(showResponse.QueryInterface(Ci.nsIPaymentActionResponse));
},
closePayment: (requestId) => {},
abortPayment: abortPaymentResponse,
completePayment: completePaymentResponse,
updatePayment: function(requestId) {
},
closePayment: function (requestId) {
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIPaymentUIService]),
};
paymentSrv.setTestingUIService(DummyUIService.QueryInterface(Ci.nsIPaymentUIService));
const simpleResponseUI = {
showPayment: function(requestId) {
try {
basiccardResponseData.initData("", // cardholderName
"4916855166538720", // cardNumber
"", // expiryMonth
"", // expiryYear
"", // cardSecurityCode
null); // 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(testName) {
DummyUIService.testName = testName;
DummyUIService.showAction = "detailBasicCardResponse";
sendAsyncMessage("set-detailed-ui-service-complete");
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));
});
addMessageListener("set-simple-ui-service", function(testName) {
DummyUIService.testName = testName;
DummyUIService.showAction = "simpleBasicCardResponse";
sendAsyncMessage("set-simple-ui-service-complete");
addMessageListener("set-simple-ui-service", function() {
paymentSrv.setTestingUIService(simpleResponseUI.QueryInterface(Ci.nsIPaymentUIService));
});
addMessageListener("set-special-address-ui-service", function(testName) {
DummyUIService.testName = testName;
DummyUIService.showAction = "specialAddressResponse";
sendAsyncMessage("set-special-address-ui-service-complete");
addMessageListener("set-special-address-ui-service", function() {
paymentSrv.setTestingUIService(specialAddressUI.QueryInterface(Ci.nsIPaymentUIService));
});
addMessageListener("method-change-to-basic-card", function(testName) {
DummyUIService.testName = testName;
DummyUIService.showAction = "payment-method-change";
sendAsyncMessage("method-change-to-basic-card-complete");
});
addMessageListener("error-response-test", function(testName) {
addMessageListener("error-response-test", function() {
// test empty cardNumber
try {
basiccardResponseData.initData("", "", "", "", "", null);
@ -262,7 +249,7 @@ addMessageListener("error-response-test", function(testName) {
emitTestFail("ShowResponse init expected 'NS_ERROR_FAILURE', but got " + e.name + ".");
}
}
sendAsyncMessage("error-response-test-complete");
sendAsyncMessage("error-response-complete");
});
addMessageListener("teardown", function() {

Просмотреть файл

@ -19,21 +19,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345
function testFailHandler(message) {
ok(false, message);
}
function testPassHandler(message) {
ok(true, message);
}
gScript.addMessageListener("test-fail", testFailHandler);
gScript.addMessageListener("test-pass", testPassHandler);
async function requestChromeAction(action, params) {
await new Promise(resolve => {
gScript.addMessageListener(`${action}-complete`, function completeListener() {
gScript.removeMessageListener(`${action}-complete`, completeListener);
resolve();
});
gScript.sendAsyncMessage(action, params);
});
}
const errorNetworksMethods = [{
supportedMethods: "basic-card",
@ -95,37 +81,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345
],
};
const updateDetails = {
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00"
}
},
shippingOptions: [
{
id: "NormalShipping",
label: "NormalShipping",
amount: {
currency: "USD",
value: "10.00"
},
selected: true,
},
{
id: "FastShipping",
label: "FastShipping",
amount: {
currency: "USD",
value: "30.00"
},
selected: false,
},
],
error: "",
};
const defaultOptions = {
requestPayerName: true,
requestPayerEmail: false,
@ -134,228 +89,168 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345
shippingType: "shipping"
};
async function testBasicCardRequestWithErrorNetworks() {
const testName = "testBasicCardRequestWithErrorNetworks";
return new Promise(async (resolve) => {
function testBasicCardRequestWithErrorNetworks() {
return new Promise((resolve, reject) => {
try {
const request = new PaymentRequest(errorNetworksMethods, defaultDetails, defaultOptions);
ok(false, `${testName}: Expected 'TypeError', but got success construction.`);
const payRequest = new PaymentRequest(errorNetworksMethods, defaultDetails, defaultOptions);
ok(false, "Expected 'TypeError', but got success construction.");
resolve();
} catch (e) {
is(e.name, "TypeError", `${testName}: Expected TypeError, but got ${e.name}`);
is(e.name, "TypeError", "Expected TypeError, but got " + e.name);
resolve();
}
resolve();
});
}
async function testBasicCardRequestWithUnconvertableData() {
const testName = "testBasicCardRequestWithUnconvertableData";
return new Promise(async (resolve) => {
function testBasicCardRequestWithUnconvertableData() {
return new Promise((resolve, reject) => {
try {
const request = new PaymentRequest(unconvertableDataMethods, defaultDetails, defaultOptions);
ok(false, `${testName}: Expected 'TypeError', but got success construction.`);
const payRequest = new PaymentRequest(unconvertableDataMethods, defaultDetails, defaultOptions);
ok(false, "Expected 'TypeError', but got success construction.");
resolve();
} catch (e) {
is(e.name, "TypeError", `${testName}: Expected TypeError, but got ${e.name}`);
is(e.name, "TypeError", "Expected TypeError, but got " + e.name);
resolve();
}
resolve();
});
}
async function testBasicCardRequestWithNullData() {
const testName = "testBasicCardRequestWithNullData";
return new Promise(async (resolve) => {
function testBasicCardRequestWithNullData() {
return new Promise((resolve, reject) => {
try {
const request = new PaymentRequest(nullDataMethods, defaultDetails, defaultOptions);
ok(request, `${testName}: PaymentRequest should be constructed with null data BasicCardRequest.`);
const payRequest = new PaymentRequest(nullDataMethods, defaultDetails, defaultOptions);
ok(payRequest, "PaymentRequest should be constructed with null data BasicCardRequest.");
resolve();
} catch (e) {
ok(false, `${testName}: Unexpected error: ${e.name}`);
ok(false, "Unexpected error: " + e.name);
resolve();
}
resolve();
});
}
async function testBasicCardRequestWithEmptyData() {
const testName = "testBasicCardRequestWithEmptyData";
return new Promise(async (resolve) => {
function testBasicCardRequestWithEmptyData() {
return new Promise((resolve, reject) => {
try {
const request = new PaymentRequest(emptyDataMethods, defaultDetails, defaultOptions);
ok(request, `${testName}: PaymentRequest should be constructed with empty data BasicCardRequest.`);
const payRequest = new PaymentRequest(emptyDataMethods, defaultDetails, defaultOptions);
ok(payRequest, "PaymentRequest should be constructed with empty data BasicCardRequest.");
resolve();
} catch (e) {
ok(false, `${testName}: Unexpected error: ${e.name}`);
ok(false, "Unexpected error: " + e.name);
resolve();
}
resolve();
});
}
async function testCanMakePaymentWithBasicCardRequest() {
const testName = "testCanMakePaymentWithBasicCardRequest";
return new Promise(async (resolve) => {
const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
try {
const result = await request.canMakePayment();
ok(result, `${testName}: canMakePayment() should be resolved with true.`);
} catch (e) {
ok(false, `${testName}: Unexpected error: ${e.name}`);
}
resolve();
function testCanMakePaymentWithBasicCardRequest() {
return new Promise((resolve, reject) => {
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
payRequest.canMakePayment().then( result => {
ok(result, "Should be resolved with true, but got false.");
resolve();
}).catch (e => {
ok(false, "Unexpected error: " + e.name);
resolve();
});
});
}
async function testBasicCardSimpleResponse() {
const testName = "testBasicCardSimpleResponse";
await requestChromeAction("set-simple-ui-service", testName);
return new Promise(async (resolve) => {
const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
try {
const response = await request.show();
ok(response.details, `${testName}: basiccard response should exists.`);
ok(!response.details.cardholderName, `${testName}: response.details.cardholderName should not exist.`);
is(response.details.cardNumber, "4916855166538720",
`${testName}: response.details.cardNumber should be '4916855166538720'.`);
ok(!response.details.expiryMonth, `${testName}: response.details.expiryMonth should not exist.`);
ok(!response.details.expiryYear, `${testName}: response.details.expiryYear should be '2024'.`);
ok(!response.details.cardSecurityCode, `${testName}: response.details.cardSecurityCode should not exist.`);
ok(!response.details.billingAddress, `${testName}: response.details.billingAddress should not exist.`);
await response.complete("success");
} catch (e) {
ok(false, `${testName}: Unexpected error: ${e.name}`);
}
await handler.destruct();
resolve();
function testBasicCardSimpleResponse() {
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
gScript.sendAsyncMessage("set-simple-ui-service");
return new Promise((resolve, reject) => {
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
payRequest.show().then(response => {
ok(response.details, "basiccard response should exists.");
ok(!response.details.cardholderName, "response.details.cardholderName should not exist.");
is(response.details.cardNumber, "4916855166538720", "response.details.cardNumber should be '4916855166538720'.");
ok(!response.details.expiryMonth, "response.details.expiryMonth should not exist.");
ok(!response.details.expiryYear, "response.details.expiryYear should be '2024'.");
ok(!response.details.cardSecurityCode, "response.details.cardSecurityCode should not exist.");
ok(!response.details.billingAddress, "response.details.billingAddress should not exist.");
response.complete("success").then(() =>{
resolve();
}).catch(e => {
ok(false, "Unexpected error: " + e.name);
resolve();
});
}).catch( e => {
ok(false, "Unexpected error: " + e.name);
resolve();
}).finally(handler.destruct);
});
}
async function testBasicCardDetailedResponse() {
const testName = "testBasicCardDetailedResponse";
await requestChromeAction("set-detailed-ui-service", testName);
return new Promise(async (resolve) => {
const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
try {
const response = await request.show();
ok(response.details, `${testName}: basiccard response should exists.`);
ok(response.details.cardholderName, `${testName}: response.details.cardholderName should not exist.`);
is(response.details.cardNumber, "4916855166538720",
`${testName}: response.details.cardNumber should be '4916855166538720'.`);
ok(response.details.expiryMonth, `${testName}: response.details.expiryMonth should not exist.`);
ok(response.details.expiryYear, `${testName}: response.details.expiryYear should be '2024'.`);
ok(response.details.cardSecurityCode, `${testName}: response.details.cardSecurityCode should not exist.`);
ok(response.details.billingAddress, `${testName}: response.details.billingAddress should not exist.`);
function testBasicCardDetailedResponse() {
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
gScript.sendAsyncMessage("set-detailed-ui-service");
return new Promise((resolve, reject) => {
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
payRequest.show().then(response => {
ok(response.details, "basiccard response should exists.");
is(response.details.cardholderName, "Bill A. Pacheco", "response.details.cardholderName should be 'Bill A. Pacheco'.");
is(response.details.cardNumber, "4916855166538720", "response.details.cardNumber should be '4916855166538720'.");
is(response.details.expiryMonth, "01", "response.details.expiryMonth should be '01'.");
is(response.details.expiryYear, "2024", "response.details.expiryYear should be '2024'.");
is(response.details.cardSecurityCode, "180", "response.details.cardSecurityCode should be '180'.");
const billingAddress = response.details.billingAddress;
is(billingAddress.country, "USA", `${testName}: country should be 'USA'.`);
is(billingAddress.addressLine.length, 1, `${testName}: addressLine.length should be 1.`);
is(billingAddress.addressLine[0], "Easton Ave", `${testName}: addressLine[0] should be 'Easton Ave'.`);
is(billingAddress.region, "CA", `${testName}: region should be 'CA'.`);
is(billingAddress.regionCode, "CA", `${testName}: regionCode should be 'CA'.`);
is(billingAddress.city, "San Bruno", `${testName}: city should be 'San Bruno'.`);
is(billingAddress.dependentLocality, "", `${testName}: dependentLocality should be empty.`);
is(billingAddress.postalCode, "94066", `${testName}: postalCode should be '94066'.`);
is(billingAddress.sortingCode, "123456", `${testName}: sortingCode should be '123456'.`);
is(billingAddress.organization, "", `${testName}: organization should be empty.`);
is(billingAddress.recipient, "Bill A. Pacheco", `${testName}: recipient should be 'Bill A. Pacheco'.`);
is(billingAddress.phone, "+14344413879", `${testName}: phone should be '+14344413879'.`);
await response.complete("success");
} catch (e) {
ok(false, `${testName}: Unexpected error: ${e.name}`);
}
await handler.destruct();
resolve();
is(billingAddress.country, "USA", "country should be 'USA'.");
is(billingAddress.addressLine.length, 1, "addressLine.length should be 1.");
is(billingAddress.addressLine[0], "Easton Ave", "addressLine[0] should be 'Easton Ave'.");
is(billingAddress.region, "CA", "region should be 'CA'.");
is(billingAddress.regionCode, "CA", "regionCode should be 'CA'.");
is(billingAddress.city, "San Bruno", "city should be 'San Bruno'.");
is(billingAddress.dependentLocality, "", "dependentLocality should be empty.");
is(billingAddress.postalCode, "94066", "postalCode should be '94066'.");
is(billingAddress.sortingCode, "123456", "sortingCode should be '123456'.");
is(billingAddress.organization, "", "organization should be empty." );
is(billingAddress.recipient, "Bill A. Pacheco", "recipient should be 'Bill A. Pacheco'.");
is(billingAddress.phone, "+14344413879", "phone should be '+14344413879'.");
response.complete("success").then(() =>{
resolve();
}).catch(e => {
ok(false, "Unexpected error: " + e.name);
resolve();
});
}).catch( e => {
ok(false, "Unexpected error: " + e.name);
resolve();
}).finally(handler.destruct);
});
}
async function testSpecialAddressResponse() {
const testName = "testSpecialAddressResponse";
await requestChromeAction("set-special-address-ui-service", testName);
return new Promise(async (resolve) => {
const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
try {
const response = await request.show();
ok(response.details, `${testName}: BasiccardResponse should exist.`);
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,
`${testName}: BasiccardResponse.billingAddress should exist.`);
"BasiccardResponse.billingAddress should exist.");
is(response.details.billingAddress.addressLine[0], ":$%@&*",
`${testName}: AddressLine should be ':$%@&*'`);
await response.complete("success");
} catch (e) {
ok(false, `${testName}: Unexpected error: ${e.name}`);
}
await handler.destruct();
resolve();
"AddressLine should be ':$%@&*'");
response.complete("success").then(()=>{
resolve();
});
}).finally(handler.destruct);
});
}
async function testMethodChangeWithoutRequestBillingAddress() {
const testName = "testMethodChangeWithoutRequestBillingAddress";
await requestChromeAction("method-change-to-basic-card", testName);
return new Promise(async (resolve) => {
const request = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
request.addEventListener("paymentmethodchange", async (event) => {
is(event.methodName, "basic-card", `${testName}: PaymentMethodChangeEvent.methodName should be 'basic-card'.`)
ok(event.methodDetails, `PaymentMethodChangeEvent.methodDetails should exist.`);
ok(!event.methodDetails.billingAddress, `PaymentMethodChangeEvent.methodDetails.billingAddres should not exist.`);
event.updateWith(updateDetails);
function testBasicCardErrorResponse() {
return new Promise((resolve, reject) => {
gScript.addMessageListener("error-response-complete",
function errorResponseCompleteHandler() {
gScript.removeMessageListener("error-response-complete",
errorResponseCompleteHandler);
resolve();
});
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
try {
const response = await request.show();
await response.complete("success");
} catch (error) {
ok(false, `${testName}: Unexpected error: ${error.name}`);
}
await handler.destruct();
resolve();
gScript.sendAsyncMessage("error-response-test");
});
}
async function testMethodChangeWithRequestBillingAddress() {
const testName = "testMethodChangeWithRequestBillingAddress";
await requestChromeAction("method-change-to-basic-card", testName);
return new Promise(async (resolve) => {
const options = {
requestPayerName: true,
requestBillingAddress: true,
requestShipping: true,
shippingType: "shipping",
};
const request = new PaymentRequest(defaultMethods, defaultDetails, options);
request.addEventListener("paymentmethodchange", async (event) => {
is(event.methodName, "basic-card", `${testName}: PaymentMethodChangeEvent.methodName should be 'basic-card'.`)
ok(event.methodDetails, `PaymentMethodChangeEvent.methodDetails should exist.`);
const billingAddress = event.methodDetails.billingAddress;
is(billingAddress.country, "USA", `${testName}: country should be 'USA'.`);
is(billingAddress.addressLine.length, 1, `${testName}: addressLine.length should be 1.`);
is(billingAddress.addressLine[0], "Easton Ave", `${testName}: addressLine[0] should be 'Easton Ave'.`);
is(billingAddress.region, "CA", `${testName}: region should be 'CA'.`);
is(billingAddress.regionCode, "CA", `${testName}: regionCode should be 'CA'.`);
is(billingAddress.city, "San Bruno", `${testName}: city should be 'San Bruno'.`);
is(billingAddress.dependentLocality, "", `${testName}: dependentLocality should be empty.`);
is(billingAddress.postalCode, "94066", `${testName}: postalCode should be '94066'.`);
is(billingAddress.sortingCode, "123456", `${testName}: sortingCode should be '123456'.`);
is(billingAddress.organization, "", `${testName}: organization should be empty.`);
is(billingAddress.recipient, "Bill A. Pacheco", `${testName}: recipient should be 'Bill A. Pacheco'.`);
is(billingAddress.phone, "+14344413879", `${testName}: phone should be '+14344413879'.`);
event.updateWith(updateDetails);
});
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
try {
const response = await request.show();
await response.complete("success");
} catch (error) {
ok(false, `${testName}: Unexpected error: ${error.name}`);
}
await handler.destruct();
resolve();
});
}
async function testBasicCardErrorResponse() {
const testName = "testBasicCardErrorResponse";
return requestChromeAction("error-response-test", testName);
}
async function teardown() {
function teardown() {
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.removeMessageListener("test-fail", testFailHandler)
@ -365,24 +260,21 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345
gScript.sendAsyncMessage("teardown");
}
async function runTests() {
try {
await testBasicCardRequestWithErrorNetworks();
await testBasicCardRequestWithUnconvertableData();
await testBasicCardRequestWithNullData();
await testBasicCardRequestWithEmptyData();
await testCanMakePaymentWithBasicCardRequest();
await testBasicCardSimpleResponse();
await testBasicCardDetailedResponse();
await testSpecialAddressResponse();
await testBasicCardErrorResponse();
await testMethodChangeWithoutRequestBillingAddress();
await testMethodChangeWithRequestBillingAddress()
await teardown();
} catch (e) {
ok(false, `test_basiccard.html: Unexpected error: ${e.name}`);
function runTests() {
testBasicCardRequestWithErrorNetworks()
.then(testBasicCardRequestWithUnconvertableData)
.then(testBasicCardRequestWithNullData)
.then(testBasicCardRequestWithEmptyData)
.then(testCanMakePaymentWithBasicCardRequest)
.then(testBasicCardSimpleResponse)
.then(testBasicCardDetailedResponse)
.then(testSpecialAddressResponse)
.then(testBasicCardErrorResponse)
.then(teardown)
.catch( e => {
ok(false, "Unexpected error: " + e.name);
SimpleTest.finish();
};
});
}
window.addEventListener('load', function() {

Просмотреть файл

@ -20,10 +20,6 @@ dictionary BasicCardResponse {
PaymentAddress? billingAddress;
};
dictionary BasicCardChangeDetails {
PaymentAddress? billingAddress;
};
dictionary BasicCardErrors {
DOMString cardNumber;
DOMString cardholderName;

Просмотреть файл

@ -98,7 +98,6 @@ dictionary PaymentOptions {
boolean requestPayerEmail = false;
boolean requestPayerPhone = false;
boolean requestShipping = false;
boolean requestBillingAddress = false;
PaymentShippingType shippingType = "shipping";
};

Просмотреть файл

@ -17,6 +17,7 @@ test(() => {
assert_idl_attribute(event, "methodDetails");
const { test } = event.methodDetails;
assert_equals(test, "pass");
assert_equals(event.methodDetails, methodDetails);
}, "Must have a methodDetails IDL attribute, which is initialized with to the methodName dictionary value");
test(() => {