Skip to content

Commit

Permalink
Bug 1435155 - Redact the shipping address as it is visible before the…
Browse files Browse the repository at this point in the history
… promise from PaymentRequest.show() resolves successfully. r=baku

Spec PR: w3c/payment-request#654

MozReview-Commit-ID: 2AiKI7htRhk

UltraBlame original commit: 8a29a154e88dc58d0ffde543a2159d70638ce53c
  • Loading branch information
marco-c committed Oct 2, 2019
1 parent 096435e commit 2a78234
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
17 changes: 13 additions & 4 deletions dom/payments/PaymentRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,14 @@ PaymentRequest::RespondShowPayment(const nsAString& aMethodName,
return;
}






RefPtr<PaymentResponse> paymentResponse =
new PaymentResponse(GetOwner(), mInternalId, mId, aMethodName,
mShippingOption, mShippingAddress, aDetails,
mShippingOption, mFullShippingAddress, aDetails,
aPayerName, aPayerEmail, aPayerPhone);
mResponse = paymentResponse;
mAcceptPromise->MaybeResolve(paymentResponse);
Expand Down Expand Up @@ -940,11 +945,15 @@ PaymentRequest::UpdateShippingAddress(const nsAString& aCountry,
const nsAString& aRecipient,
const nsAString& aPhone)
{
mShippingAddress = new PaymentAddress(GetOwner(), aCountry, aAddressLine,
nsTArray<nsString> emptyArray;
mShippingAddress = new PaymentAddress(GetOwner(), aCountry, emptyArray,
aRegion, aCity, aDependentLocality,
aPostalCode, aSortingCode, aLanguageCode,
aOrganization, aRecipient, aPhone);

EmptyString(), EmptyString(), EmptyString());
mFullShippingAddress = new PaymentAddress(GetOwner(), aCountry, aAddressLine,
aRegion, aCity, aDependentLocality,
aPostalCode, aSortingCode, aLanguageCode,
aOrganization, aRecipient, aPhone);

return DispatchUpdateEvent(NS_LITERAL_STRING("shippingaddresschange"));
}
Expand Down
2 changes: 2 additions & 0 deletions dom/payments/PaymentRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class PaymentRequest final : public DOMEventTargetHelper

RefPtr<PaymentAddress> mShippingAddress;

RefPtr<PaymentAddress> mFullShippingAddress;

nsString mShippingOption;

Nullable<PaymentShippingType> mShippingType;
Expand Down
4 changes: 2 additions & 2 deletions dom/payments/test/ShowPaymentChromeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ shippingAddress.init("USA",
addressLine,
"CA",
"San Bruno",
"",
"Test locality",
"94066",
"123456",
"en",
"",
"Testing Org",
"Bill A. Pacheco",
"+1-434-441-3879");

Expand Down
28 changes: 24 additions & 4 deletions dom/payments/test/test_showPayment.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

const defaultMethods = [{
supportedMethods: "basic-card",
data: {
data: {
supportedNetworks: ['unionpay', 'visa', 'mastercard', 'amex', 'discover',
'diners', 'jcb', 'mir',
],
Expand Down Expand Up @@ -160,6 +160,16 @@
return new Promise((resolve, reject) => {
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
payRequest.addEventListener("shippingaddresschange", event => {
is(payRequest.shippingAddress.country, "USA", "payRequest.shippingAddress.country should be 'USA' from event.");
is(payRequest.shippingAddress.addressLine.length, 0, "payRequest.shippingAddress.addressLine.length should be 0 from event.");
is(payRequest.shippingAddress.region, "CA", "payRequest.shippingAddress.region should be 'CA' from event.");
is(payRequest.shippingAddress.city, "San Bruno", "payRequest.shippingAddress.city should be 'San Bruno' from event.");
is(payRequest.shippingAddress.dependentLocality, "Test locality", "payRequest.shippingAddress.dependentLocality should be 'Test locality' from event.");
is(payRequest.shippingAddress.postalCode, "94066", "payRequest.shippingAddress.postalCode should be '94066' from event.");
is(payRequest.shippingAddress.sortingCode, "123456", "payRequest.shippingAddress.sortingCode should be '123456' from event.");
is(payRequest.shippingAddress.organization, "", "payRequest.shippingAddress.organization should be empty from event.");
is(payRequest.shippingAddress.recipient, "", "payRequest.shippingAddress.recipient should be empty from event.");
is(payRequest.shippingAddress.phone, "", "payRequest.shippingAddress.phone should be empty from event.");
event.updateWith(updateWithShippingAddress());
});
payRequest.addEventListener("shippingoptionchange", event => {
Expand All @@ -174,16 +184,26 @@
is(response.shippingAddress.addressLine[0], "Easton Ave", "response.shippingAddress.addressLine[0] should be 'Easton Ave'.");
is(response.shippingAddress.region, "CA", "response.shippingAddress.region should be 'CA'.");
is(response.shippingAddress.city, "San Bruno", "response.shippingAddress.city should be 'San Bruno'.");
is(response.shippingAddress.dependentLocality, "", "response.shippingAddress.dependentLocality should be empty.");
is(response.shippingAddress.dependentLocality, "Test locality", "response.shippingAddress.dependentLocality should be 'Test locality'.");
is(response.shippingAddress.postalCode, "94066", "response.shippingAddress.postalCode should be '94066'.");
is(response.shippingAddress.sortingCode, "123456", "response.shippingAddress.sortingCode should be '123456'.");
is(response.shippingAddress.organization, "", "response.shippingAddress.organization should be empty.");
is(response.shippingAddress.organization, "Testing Org", "response.shippingAddress.organization should be 'Testing Org'.");
is(response.shippingAddress.recipient, "Bill A. Pacheco", "response.shippingAddress.recipient should be 'Bill A. Pacheco'.");
is(response.shippingAddress.phone, "+1-434-441-3879", "response.shippingAddress.phone should be '+1-434-441-3879'.");
is(response.shippingOption, "FastShipping", "response.shippingOption should be 'FastShipping'.");
is(response.payerName, "Bill A. Pacheco", "response.payerName should be 'Bill A. Pacheco'.");
ok(!response.payerEamil, "response.payerEmail should be empty");
ok(!response.payerEmail, "response.payerEmail should be empty");
ok(!response.payerPhone, "response.payerPhone should be empty");
is(payRequest.shippingAddress.country, "USA", "payRequest.shippingAddress.country should be 'USA' from promise.");
is(payRequest.shippingAddress.addressLine.length, 0, "payRequest.shippingAddress.addressLine.length should be 0 from promise.");
is(payRequest.shippingAddress.region, "CA", "payRequest.shippingAddress.region should be 'CA' from promise.");
is(payRequest.shippingAddress.city, "San Bruno", "payRequest.shippingAddress.city should be 'San Bruno' from promise.");
is(payRequest.shippingAddress.dependentLocality, "Test locality", "payRequest.shippingAddress.dependentLocality should be 'Test locality' from promise.");
is(payRequest.shippingAddress.postalCode, "94066", "payRequest.shippingAddress.postalCode should be '94066' from promise.");
is(payRequest.shippingAddress.sortingCode, "123456", "payRequest.shippingAddress.sortingCode should be '123456' from promise.");
is(payRequest.shippingAddress.organization, "", "payRequest.shippingAddress.organization should be empty from promise.");
is(payRequest.shippingAddress.recipient, "", "payRequest.shippingAddress.recipient should be empty from promise.");
is(payRequest.shippingAddress.phone, "", "payRequest.shippingAddress.phone should be empty from promise.");
response.complete("success").then(() =>{
resolve();
}).catch(e => {
Expand Down

0 comments on commit 2a78234

Please sign in to comment.