mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 1442078 - Modify DOM tests that were broken by the change to the "show" specs. r=baku
MozReview-Commit-ID: KqecbNw496W --HG-- extra : rebase_source : 4c6a120183286e52243356a74b3fdf522ca09c2b
This commit is contained in:
parent
d02a6dc311
commit
673331c9c5
@ -207,6 +207,37 @@ const ErrorUIService = {
|
||||
|
||||
};
|
||||
|
||||
const CompleteUIService = {
|
||||
showPayment: function(requestId) {
|
||||
const showResponseData = Cc["@mozilla.org/dom/payments/general-response-data;1"].
|
||||
createInstance(Ci.nsIGeneralResponseData);
|
||||
|
||||
try {
|
||||
showResponseData.initData({});
|
||||
} catch (e) {
|
||||
emitTestFail("Fail to initialize response data with empty object.");
|
||||
}
|
||||
|
||||
let showResponse = Cc["@mozilla.org/dom/payments/payment-show-action-response;1"].
|
||||
createInstance(Ci.nsIPaymentShowActionResponse);
|
||||
showResponse.init(requestId,
|
||||
Ci.nsIPaymentActionResponse.PAYMENT_ACCEPTED,
|
||||
"", // payment method
|
||||
showResponseData, // payment method data
|
||||
"", // payer name
|
||||
"", // payer email
|
||||
""); // payer phone
|
||||
paymentSrv.respondPayment(showResponse.QueryInterface(Ci.nsIPaymentActionResponse));
|
||||
},
|
||||
abortPayment: function(requestId) {
|
||||
},
|
||||
completePayment: function(requestId) {
|
||||
},
|
||||
updatePayment: function(requestId) {
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPaymentUIService]),
|
||||
};
|
||||
|
||||
function testInitDataAndResponse() {
|
||||
const showResponseData = Cc["@mozilla.org/dom/payments/general-response-data;1"].
|
||||
createInstance(Ci.nsIGeneralResponseData);
|
||||
@ -277,6 +308,10 @@ addMessageListener("set-update-with-error-ui-service", function() {
|
||||
paymentSrv.setTestingUIService(ErrorUIService.QueryInterface(Ci.nsIPaymentUIService));
|
||||
});
|
||||
|
||||
addMessageListener("set-complete-ui-service", function() {
|
||||
paymentSrv.setTestingUIService(CompleteUIService.QueryInterface(Ci.nsIPaymentUIService));
|
||||
});
|
||||
|
||||
addMessageListener("test-init-data-and-response", testInitDataAndResponse);
|
||||
|
||||
addMessageListener("set-complete-status-success", function() {
|
||||
|
@ -44,6 +44,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345367
|
||||
}
|
||||
|
||||
function testAfterShow() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
const acceptPromise = payRequest.show();
|
||||
@ -53,7 +55,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345367
|
||||
}).catch( (err) => {
|
||||
ok(false, "Expected no error, but got '" + err.name + "'.");
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -176,6 +176,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345
|
||||
}
|
||||
|
||||
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);
|
||||
@ -196,11 +198,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345
|
||||
}).catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
@ -233,7 +237,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1375345
|
||||
}).catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345365
|
||||
}
|
||||
|
||||
function testAfterShow() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
const acceptPromise = payRequest.show();
|
||||
@ -75,12 +77,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345365
|
||||
}).catch( (err) => {
|
||||
ok(false, "Expected no error, but got '" + err.name + "'.");
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testAfterAbort() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
const acceptPromise = payRequest.show();
|
||||
@ -96,7 +100,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345365
|
||||
}).catch( (err) => {
|
||||
ok(false, "Expected no error, but got '" + err.name +"'.");
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -199,6 +199,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1388661
|
||||
}
|
||||
|
||||
function testUpdateWithInvalidCurrency() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
info("testUpdateWithInvalidCurrency");
|
||||
gScript.sendAsyncMessage("set-update-with-invalid-details-ui-service");
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -218,11 +220,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1388661
|
||||
}).catch(e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
function testUpdateWithInvalidAmount() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
info("testUpdateWithInvalidAmount");
|
||||
gScript.sendAsyncMessage("set-update-with-invalid-details-ui-service");
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -242,7 +246,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1388661
|
||||
}).catch(e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1389418
|
||||
}
|
||||
|
||||
function testUpdateWithValidPMI() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
gScript.sendAsyncMessage("set-ui-service");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
@ -163,11 +165,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1389418
|
||||
}).catch((e) => {
|
||||
ok(false, "Unexpected error '" + e.name + "'.");
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
function testUpdateWithInvalidPMI() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
gScript.sendAsyncMessage("set-ui-service");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
@ -199,7 +203,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1389418
|
||||
}).catch((e) => {
|
||||
is(e.name, "RangeError", "Expected 'RangeError'.");
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -122,12 +122,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1436903
|
||||
gScript.sendAsyncMessage("set-normal-ui-service");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
|
||||
|
||||
payRequest.addEventListener("shippingaddresschange", event => {
|
||||
event.updateWith(updateWithShippingAddress());
|
||||
});
|
||||
payRequest.addEventListener("shippingoptionchange", event => {
|
||||
event.updateWith(updateWithShippingOption());
|
||||
});
|
||||
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
payRequest.show().then(response => {
|
||||
response.complete("success").then(() =>{
|
||||
resolve();
|
||||
@ -138,7 +141,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1436903
|
||||
}).catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -181,6 +181,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
payRequest.addEventListener("shippingoptionchange", event => {
|
||||
event.updateWith(updateWithShippingOption());
|
||||
});
|
||||
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
payRequest.show().then(response => {
|
||||
is(response.requestId, "test payment", "response.requestId should be 'test payment'.");
|
||||
is(response.methodName, "testing-payment-method", "response.methodName should be 'testing-payment-method'.");
|
||||
@ -220,7 +222,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
}).catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
@ -230,6 +232,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
gScript.sendAsyncMessage("set-complete-status-fail");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
payRequest.show().then(response => {
|
||||
response.complete("fail").then(() => {
|
||||
resolve();
|
||||
@ -240,7 +244,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
}).catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
@ -250,6 +254,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
gScript.sendAsyncMessage("set-complete-status-unknown");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
payRequest.show().then(response => {
|
||||
response.complete("unknown").then(() => {
|
||||
resolve();
|
||||
@ -260,7 +266,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
}).catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
@ -270,6 +276,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
gScript.sendAsyncMessage("set-complete-status-unknown");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
payRequest.show().then(response => {
|
||||
response.complete().then(() => {
|
||||
resolve();
|
||||
@ -280,11 +288,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
}).catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
function testCannotMakePaymentShow() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(nonSupportedMethods, defaultDetails);
|
||||
payRequest.canMakePayment().then(result => {
|
||||
@ -296,11 +306,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
is(e.name, "NotSupportedError", "Should be rejected with 'NotSupportedError', but got " + e.name + ".");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
function testRejectShow() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
gScript.sendAsyncMessage("set-reject-ui-service");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
|
||||
@ -313,11 +325,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
}).catch(e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
function testUpdateWithError() {
|
||||
const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput(true);
|
||||
|
||||
gScript.sendAsyncMessage("set-update-with-error-ui-service");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails, defaultOptions);
|
||||
@ -336,7 +350,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
}).catch(e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
resolve();
|
||||
});
|
||||
}).finally(handler.destruct);
|
||||
});
|
||||
}
|
||||
|
||||
@ -352,6 +366,20 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
});
|
||||
}
|
||||
|
||||
function testShowUnsafe() {
|
||||
gScript.sendAsyncMessage("set-complete-ui-service");
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
payRequest.show().then(() => {
|
||||
ok(false, "Expected 'SecurityError', but got resolved")
|
||||
resolve();
|
||||
}).catch((err) => {
|
||||
is(err.name, "SecurityError", `Should be rejected with 'SecurityError', but got ${err.name}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
|
||||
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
|
||||
@ -372,6 +400,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1345366
|
||||
.then(testShowWithEmpty)
|
||||
.then(testUpdateWithError)
|
||||
.then(testNullDetailsResponse)
|
||||
.then(testShowUnsafe)
|
||||
.then(teardown)
|
||||
.catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
|
Loading…
Reference in New Issue
Block a user