Bug 1398991 - Mochitest for spec change on PaymentRequest.shippingOption. r=baku

This patch changes the test_construction.html with following modification.
1. Modify the test testWithDuplicateShippingOptionsParameters to expect a
   TypeError when constructing wiht duplicate shippingOption ids.
2. Add test testShippingOtpionAttribute for shippingOption setting checking
   with following conditions
   1. No selected shippingOption and PaymentOptions.requestShipping is false
   2. One selected shippingOption and PaymentOptions.requestShipping is false
   3. One selected shippingOption and PaymentOptions.requestShipping is true
   4. Multiple selected shippingOptions and PaymentOptions.requestShipping is
      true.
This commit is contained in:
Eden Chuang 2017-09-15 14:20:05 +08:00
Родитель a15d19dc9d
Коммит 62b089b5ed
2 изменённых файлов: 75 добавлений и 95 удалений

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

@ -331,67 +331,6 @@ function checkNonBasicCardRequest(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()) {
@ -443,23 +382,6 @@ function checkNonBasicCardRequestHandler() {
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()) {
@ -473,8 +395,6 @@ function checkMultipleRequestsHandler () {
}
if (payRequest.paymentDetails.id == "payment details") {
checkComplexRequest(payRequest);
} else if (payRequest.paymentDetails.id == "duplicate shipping options details") {
checkDuplicateShippingOptionsRequest(payRequest);
} else {
checkSimplestRequest(payRequest);
}
@ -505,7 +425,6 @@ function checkCrossOriginTopLevelPrincipalHandler() {
addMessageListener("check-simplest-request", checkSimplestRequestHandler);
addMessageListener("check-complex-request", checkComplexRequestHandler);
addMessageListener("check-duplicate-shipping-options-request", checkDuplicateShippingOptionsRequestHandler);
addMessageListener("check-multiple-requests", checkMultipleRequestsHandler);
addMessageListener("check-nonbasiccard-request", checkNonBasicCardRequestHandler);
addMessageListener("check-cross-origin-top-level-principal", checkCrossOriginTopLevelPrincipalHandler);

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

@ -199,13 +199,81 @@ 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);
try {
const payRequest = new PaymentRequest(simplestMethods,
duplicateShippingOptionsDetails,
{requestShipping: true});
ok(false, "Construction should fail with duplicate shippingOption Ids.");
resolve();
});
gScript.sendAsyncMessage("check-duplicate-shipping-options-request");
} catch (e) {
is(e.name, "TypeError", "Expected 'TypeError' with duplicate shippingOption Ids.");
resolve();
}
});
}
function testShippingOtpionAttribute() {
return new Promise((resolve, reject) => {
const details = {
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
shippingOptions: [
{
id: "option1",
label: "option1",
amount: {
currency: "USD",
value: "1.00",
},
selected: false,
},
{
id: "option2",
label: "option2",
amount: {
currency: "USD",
value: "1.00",
},
selected: false,
},
],
};
const payRequest1 = new PaymentRequest(simplestMethods,
details,
{requestShipping: false});
ok(payRequest1, "PaymentRequest should be created");
ok(!payRequest1.shippingOption,
"request.shippingOption should be null in default, when options.requestShipping is false");
details.shippingOptions[0].selected = true;
const payRequest2 = new PaymentRequest(simplestMethods,
details,
{requestShipping: false});
ok(payRequest2, "PaymentRequest should be created");
ok(!payRequest2.shippingOption,
"request.shippingOption should be null in default, when options.requestShipping is false");
const payRequest3 = new PaymentRequest(simplestMethods,
details,
{requestShipping: true});
ok(payRequest3, "PaymentRequest should be created");
ok(payRequest3.shippingOption,
"request.shippingOption should not be null when both shoppingOtpion.selected and options.requestOptions are true");
is(payRequest3.shippingOption, "option1",
"request.shippingOption should be 'option1'");
details.shippingOptions[1].selected = true;
const payRequest4 = new PaymentRequest(simplestMethods,
details,
{requestShipping: true});
ok(payRequest4, "PaymentRequest should be created");
ok(payRequest4.shippingOption,
"request.shippingOption should not be null when both shoppingOtpion.selected and options.requestOptions are true");
is(payRequest4.shippingOption, "option2",
"request.shippingOption should be 'option2' which is the last one selected.");
resolve();
});
}
@ -213,10 +281,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345361
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();
@ -262,6 +328,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345361
.then(testWithDuplicateShippingOptionsParameters)
.then(testMultipleRequests)
.then(testCrossOriginTopLevelPrincipal)
.then(testShippingOtpionAttribute)
.then(teardown)
.catch( e => {
ok(false, "Unexpected error: " + e.name);
@ -281,11 +348,5 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345361
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1345361">Mozilla Bug 1345361</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>