Bug 1367694 - Mochitest for resetting details.shippingOptions when there are duplicate option IDs. r=baku

This commit is contained in:
Jocelyn Liu 2017-06-20 14:07:16 -07:00
Родитель 809522fb3a
Коммит ffb43e0faf
5 изменённых файлов: 185 добавлений и 3 удалений

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

@ -227,6 +227,67 @@ function checkComplexRequest(payRequest) {
}
}
function checkDuplicateShippingOptionsRequest(payRequest) {
if (payRequest.paymentMethods.length != 1) {
emitTestFail("paymentMethods' length should be 1.");
}
const methodData = payRequest.paymentMethods.queryElementAt(0, Ci.nsIPaymentMethodData);
if (!methodData) {
emitTestFail("Fail to get payment methodData.");
}
let supportedMethod = methodData.supportedMethods;
if (supportedMethod != "basic-card") {
emitTestFail("supported method should be 'basic-card'.");
}
// checking the passed PaymentDetails parameter
const details = payRequest.paymentDetails;
if (details.id != "duplicate shipping options details" ) {
emitTestFail("details.id should be 'duplicate shipping options details'.");
}
if (details.totalItem.label != "Total") {
emitTestFail("total item's label should be 'Total'.");
}
if (details.totalItem.amount.currency != "USD") {
emitTestFail("total item's currency should be 'USD'.");
}
if (details.totalItem.amount.value != "1.00") {
emitTestFail("total item's value should be '1.00'.");
}
if (details.displayItems) {
emitTestFail("details.displayItems should be undefined.");
}
if (details.modifiers) {
emitTestFail("details.displayItems should be undefined.");
}
const shippingOptions = details.shippingOptions;
if (!shippingOptions) {
emitTestFail("details.shippingOptions should not be undefined.");
}
if (shippingOptions.length != 0) {
emitTestFail("shippingOptions' length should be 0.");
}
// checking the default generated PaymentOptions parameter
const paymentOptions = payRequest.paymentOptions;
if (paymentOptions.requestPayerName) {
emitTestFail("requestPayerName option should be false.");
}
if (paymentOptions.requestPayerEmail) {
emitTestFail("requestPayerEmail option should be false.");
}
if (paymentOptions.requestPayerPhone) {
emitTestFail("requestPayerPhone option should be false.");
}
if (paymentOptions.requestShipping) {
emitTestFail("requestShipping option should be false.");
}
if (paymentOptions.shippingType != "shipping") {
emitTestFail("shippingType option should be 'shipping'.")
}
}
function checkSimplestRequestHandler() {
const paymentEnum = paymentSrv.enumerate();
if (!paymentEnum.hasMoreElements()) {
@ -261,6 +322,23 @@ function checkComplexRequestHandler() {
sendAsyncMessage("check-complete");
}
function checkDuplicateShippingOptionsRequestHandler() {
const paymentEnum = paymentSrv.enumerate();
if (!paymentEnum.hasMoreElements()) {
emitTestFail("PaymentRequestService should have at least one payment request.");
}
while (paymentEnum.hasMoreElements()) {
let payRequest = paymentEnum.getNext().QueryInterface(Ci.nsIPaymentRequest);
if (!payRequest) {
emitTestFail("Fail to get existing payment request.");
break;
}
checkDuplicateShippingOptionsRequest(payRequest);
}
paymentSrv.cleanup();
sendAsyncMessage("check-complete");
}
function checkMultipleRequestsHandler () {
const paymentEnum = paymentSrv.enumerate();
if (!paymentEnum.hasMoreElements()) {
@ -272,10 +350,12 @@ function checkMultipleRequestsHandler () {
emitTestFail("Fail to get existing payment request.");
break;
}
if (payRequest.paymentDetails.id != "payment details") {
checkSimplestRequest(payRequest);
} else {
if (payRequest.paymentDetails.id == "payment details") {
checkComplexRequest(payRequest);
} else if (payRequest.paymentDetails.id == "duplicate shipping options details") {
checkDuplicateShippingOptionsRequest(payRequest);
} else {
checkSimplestRequest(payRequest);
}
}
paymentSrv.cleanup();
@ -284,6 +364,7 @@ function checkMultipleRequestsHandler () {
addMessageListener("check-simplest-request", checkSimplestRequestHandler);
addMessageListener("check-complex-request", checkComplexRequestHandler);
addMessageListener("check-duplicate-shipping-options-request", checkDuplicateShippingOptionsRequestHandler);
addMessageListener("check-multiple-requests", checkMultipleRequestsHandler);
addMessageListener("teardown", function() {

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

@ -22,6 +22,8 @@ add_task(async function() {
checkComplexPayment(payment);
} else if (payment.paymentDetails.id == "simple details") {
checkSimplePayment(payment);
} else if (payment.paymentDetails.id == "duplicate shipping options details") {
checkDupShippingOptionsPayment(payment);
} else {
ok(false, "Unknown payment.");
}

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

@ -101,6 +101,34 @@ function checkComplexPayment(aPayment) {
is(paymentOptions.shippingType, "shipping", "shippingType option should be 'shipping'");
}
function checkDupShippingOptionsPayment(aPayment) {
// checking the passed PaymentMethods parameter
is(aPayment.paymentMethods.length, 1, "paymentMethods' length should be 1.");
const methodData = aPayment.paymentMethods.queryElementAt(0, Ci.nsIPaymentMethodData);
ok(methodData, "Fail to get payment methodData.");
is(methodData.supportedMethods, "MyPay", "modifier's supported method name should be 'MyPay'.");
is(methodData.data, "", "method data should be empty");
// checking the passed PaymentDetails parameter
const details = aPayment.paymentDetails;
is(details.id, "duplicate shipping options details", "details.id should be 'duplicate shipping options details'.");
is(details.totalItem.label, "Donation", "total item's label should be 'Donation'.");
is(details.totalItem.amount.currency, "USD", "total item's currency should be 'USD'.");
is(details.totalItem.amount.value, "55.00", "total item's value should be '55.00'.");
const shippingOptions = details.shippingOptions;
is(shippingOptions.length, 0, "shippingOptions' length should be 0.");
// checking the passed PaymentOptions parameter
const paymentOptions = aPayment.paymentOptions;
ok(paymentOptions.requestPayerName, "payerName option should be true");
ok(paymentOptions.requestPayerEmail, "payerEmail option should be true");
ok(paymentOptions.requestPayerPhone, "payerPhone option should be true");
ok(paymentOptions.requestShipping, "requestShipping option should be true");
is(paymentOptions.shippingType, "shipping", "shippingType option should be 'shipping'");
}
function cleanup() {
const paymentSrv = Cc["@mozilla.org/dom/payments/payment-request-service;1"].getService(Ci.nsIPaymentRequestService);
if (paymentSrv) {

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

@ -66,6 +66,28 @@
},
};
const dupShippingOptionsDetails = {
id: "duplicate shipping options details",
total: {
label: "Donation",
amount: { currency: "USD", value: "55.00" }
},
shippingOptions: [
{
id: "dupShipping",
label: "NormalShipping",
amount: { currency: "USD", value: "10.00", },
selected: true,
},
{
id: "dupShipping",
label: "FastShipping",
amount: { currency: "USD", value: "30.00", },
selected: false,
},
],
};
const options = {
requestPayerName: true,
requestPayerEmail: true,
@ -79,6 +101,9 @@
options);
const paymentRequest2 = new PaymentRequest(supportedInstruments,
simpleDetails);
const paymentRequest3 = new PaymentRequest(supportedInstruments,
dupShippingOptionsDetails,
options);
</script>
</body>
</html>

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

@ -121,6 +121,37 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345361
shippingType: "shipping"
};
const duplicateShippingOptionsDetails = {
id: "duplicate shipping options details",
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00"
}
},
shippingOptions: [
{
id: "dupShipping",
label: "NormalShipping",
amount: {
currency: "USD",
value: "10.00"
},
selected: true,
},
{
id: "dupShipping",
label: "FastShipping",
amount: {
currency: "USD",
value: "30.00"
},
selected: false,
},
],
};
function testWithSimplestParameters() {
return new Promise((resolve, reject) => {
@ -146,12 +177,26 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345361
});
}
function testWithDuplicateShippingOptionsParameters() {
return new Promise((resolve, reject) => {
const payRequest = new PaymentRequest(simplestMethods, duplicateShippingOptionsDetails);
ok(payRequest, "PaymentRequest should be created");
gScript.addMessageListener("check-complete", function checkCompleteHandler() {
gScript.removeMessageListener("check-complete", checkCompleteHandler);
resolve();
});
gScript.sendAsyncMessage("check-duplicate-shipping-options-request");
});
}
function testMultipleRequests() {
return new Promise((resolve, reject) => {
const payRequest1 = new PaymentRequest(complexMethods, complexDetails, complexOptions);
const payRequest2 = new PaymentRequest(simplestMethods, simplestDetails);
const payRequest3 = new PaymentRequest(simplestMethods, duplicateShippingOptionsDetails);
ok(payRequest1, "PaymentRequest with complex parameters should be created");
ok(payRequest2, "PaymentRequest with simplest parameters should be created");
ok(payRequest3, "PaymentRequest with duplicate shipping options parameters should be created");
gScript.addMessageListener("check-complete", function checkCompleteHandler() {
gScript.removeMessageListener("check-complete", checkCompleteHandler);
resolve();
@ -173,6 +218,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345361
function runTests() {
testWithSimplestParameters()
.then(testWithComplexParameters)
.then(testWithDuplicateShippingOptionsParameters)
.then(testMultipleRequests)
.then(teardown)
.catch( e => {