зеркало из https://github.com/mozilla/gecko-dev.git
Bug 938304 - navigator.mozPay(): callbacks do not pass through result (desktop fix). r=ferjm
--HG-- rename : webapprt/test/chrome/mozpay-success.html => webapprt/test/chrome/mozpay-failure.html
This commit is contained in:
Родитель
1d5515c4c1
Коммит
218dad110d
|
@ -14,20 +14,21 @@ XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|||
"nsIMessageSender");
|
||||
|
||||
function paymentSuccess(aRequestId) {
|
||||
return paymentCallback(aRequestId, "Payment:Success");
|
||||
return function(aResult) {
|
||||
closePaymentWindow(aRequestId, function() {
|
||||
cpmm.sendAsyncMessage("Payment:Success", { requestId: aRequestId,
|
||||
result: aResult });
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function paymentFailed(aRequestId) {
|
||||
return paymentCallback(aRequestId, "Payment:Failed");
|
||||
}
|
||||
|
||||
function paymentCallback(aRequestId, aMsg) {
|
||||
return function(aResult) {
|
||||
closePaymentWindow(aRequestId, function() {
|
||||
cpmm.sendAsyncMessage(aMsg, { result: aResult,
|
||||
requestId: aRequestId });
|
||||
});
|
||||
};
|
||||
return function(aErrorMsg) {
|
||||
closePaymentWindow(aRequestId, function() {
|
||||
cpmm.sendAsyncMessage("Payment:Failed", { requestId: aRequestId,
|
||||
errorMsg: aErrorMsg });
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
let payments = {};
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
let { PaymentManager } = Cu.import("resource://gre/modules/Payment.jsm", {});
|
||||
Cu.import("resource://webapprt/modules/WebappRT.jsm");
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let providerWindow = null;
|
||||
let providerUri = "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-success.html?req=";
|
||||
let curTest = 0;
|
||||
|
||||
let tests = [];
|
||||
tests.push({
|
||||
providerUri: "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-success.html?req=",
|
||||
message: "Success."
|
||||
});
|
||||
tests.push({
|
||||
providerUri: "https://example.com:443/webapprtChrome/webapprt/test/chrome/mozpay-failure.html?req=",
|
||||
message: "Chocolate rejected."
|
||||
});
|
||||
|
||||
let jwt = "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJhdWQiOiAibW9j" +
|
||||
"a3BheXByb3ZpZGVyLnBocGZvZ2FwcC5jb20iLCAiaXNzIjogIkVudGVyI" +
|
||||
"HlvdSBhcHAga2V5IGhlcmUhIiwgInJlcXVlc3QiOiB7Im5hbWUiOiAiUG" +
|
||||
|
@ -21,17 +32,19 @@ function test() {
|
|||
PaymentManager.registeredProviders["mock/payments/inapp/v1"] = {
|
||||
name: "mockprovider",
|
||||
description: "Mock Payment Provider",
|
||||
uri: providerUri,
|
||||
uri: tests[curTest].providerUri,
|
||||
requestMethod: "GET"
|
||||
};
|
||||
|
||||
let providerWindow;
|
||||
|
||||
let winObserver = function(win, topic) {
|
||||
if (topic == "domwindowopened") {
|
||||
win.addEventListener("load", function onLoadWindow() {
|
||||
win.removeEventListener("load", onLoadWindow, false);
|
||||
|
||||
if (win.document.getElementById("content").getAttribute("src") ==
|
||||
(providerUri + jwt)) {
|
||||
(tests[curTest].providerUri + jwt)) {
|
||||
ok(true, "Payment provider window shown.");
|
||||
providerWindow = win;
|
||||
}
|
||||
|
@ -43,25 +56,45 @@ function test() {
|
|||
|
||||
let mutObserver = null;
|
||||
|
||||
loadWebapp("mozpay.webapp", undefined, function onLoad() {
|
||||
function onLoad() {
|
||||
let msg = gAppBrowser.contentDocument.getElementById("msg");
|
||||
mutObserver = new MutationObserver(function(mutations) {
|
||||
if (msg.textContent == "Success.") {
|
||||
ok(true, "Payment success.");
|
||||
} else {
|
||||
ok(false, "Payment success.");
|
||||
}
|
||||
is(msg.textContent, tests[curTest].message, "Got: " + tests[curTest].message);
|
||||
|
||||
if (providerWindow == null) {
|
||||
if (!providerWindow) {
|
||||
ok(false, "Payment provider window shown.");
|
||||
} else {
|
||||
providerWindow.close();
|
||||
providerWindow = null;
|
||||
}
|
||||
|
||||
finish();
|
||||
runNextTest();
|
||||
});
|
||||
mutObserver.observe(msg, { childList: true });
|
||||
});
|
||||
}
|
||||
|
||||
loadWebapp("mozpay.webapp", undefined, onLoad);
|
||||
|
||||
function runNextTest() {
|
||||
providerWindow = null;
|
||||
if (mutObserver) {
|
||||
mutObserver.disconnect();
|
||||
}
|
||||
|
||||
curTest++;
|
||||
|
||||
if (curTest < tests.length) {
|
||||
PaymentManager.registeredProviders["mock/payments/inapp/v1"].uri = tests[curTest].providerUri;
|
||||
|
||||
gAppBrowser.addEventListener("load", function onLoadH() {
|
||||
gAppBrowser.removeEventListener("load", onLoadH, true);
|
||||
onLoad();
|
||||
}, true);
|
||||
gAppBrowser.reload();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
Services.ww.unregisterNotification(winObserver);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
mozPaymentProvider.paymentFailed('Chocolate rejected.');
|
||||
</script>
|
||||
<p id="msg">Webapp waiting to pay...</p>
|
||||
</body>
|
||||
</html>
|
|
@ -37,7 +37,7 @@
|
|||
document.getElementById("msg").textContent = "Success.";
|
||||
};
|
||||
request.onerror = function onerror() {
|
||||
document.getElementById("msg").textContent = "Failure.";
|
||||
document.getElementById("msg").textContent = request.error.name;
|
||||
};
|
||||
</script>
|
||||
<p id="msg">Webapp waiting to be paid...</p>
|
||||
|
|
|
@ -26,6 +26,7 @@ support-files =
|
|||
mozpay.webapp^headers^
|
||||
mozpay.html
|
||||
mozpay-success.html
|
||||
mozpay-failure.html
|
||||
getUserMedia.webapp
|
||||
getUserMedia.webapp^headers^
|
||||
getUserMedia.html
|
||||
|
|
Загрузка…
Ссылка в новой задаче