зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1345365 - Mochitest for PaymentRequest API canMakePayment() and abort(). r=baku
--HG-- extra : rebase_source : 854f2a94f2951f979c9bf5173c39c8fc1c11555c
This commit is contained in:
Родитель
5b3b71aae6
Коммит
f9257bbf5b
|
@ -38,3 +38,4 @@ include('/ipc/chromium/chromium-config.mozbuild')
|
|||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
|
||||
MOCHITEST_MANIFESTS += ['test/mochitest.ini']
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
"use strict";
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
const { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
const DummyUIService = {
|
||||
canMakePayment: function(requestId) {
|
||||
let canMakeResponse = Cc["@mozilla.org/dom/payments/payment-canmake-action-response;1"].
|
||||
createInstance(Ci.nsIPaymentCanMakeActionResponse);
|
||||
canMakeResponse.init(requestId, true);
|
||||
return canMakeResponse.QueryInterface(Ci.nsIPaymentActionResponse);
|
||||
},
|
||||
showPayment: function(requestId) {
|
||||
return null;
|
||||
},
|
||||
abortPayment: function(requestId) {
|
||||
let abortResponse = Cc["@mozilla.org/dom/payments/payment-abort-action-response;1"].
|
||||
createInstance(Ci.nsIPaymentAbortActionResponse);
|
||||
abortResponse.init(requestId, Ci.nsIPaymentActionResponse.ABORT_SUCCEEDED);
|
||||
return abortResponse.QueryInterface(Ci.nsIPaymentActionResponse);
|
||||
},
|
||||
completePayment: function(requestId) {
|
||||
return null;
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPaymentUIService]),
|
||||
};
|
||||
|
||||
const paymentSrv = Cc["@mozilla.org/dom/payments/payment-request-service;1"].getService(Ci.nsIPaymentRequestService);
|
||||
paymentSrv.setTestingUIService(DummyUIService.QueryInterface(Ci.nsIPaymentUIService));
|
||||
|
||||
addMessageListener('teardown', function() {
|
||||
paymentSrv.cleanup();
|
||||
paymentSrv.setTestingUIService(null);
|
||||
sendAsyncMessage('teardown-complete');
|
||||
});
|
|
@ -0,0 +1,9 @@
|
|||
[DEFAULT]
|
||||
# skip-if !e10s will be removed once non-e10s is supported
|
||||
skip-if = !e10s
|
||||
scheme = https
|
||||
support-files =
|
||||
CanMakePaymentChromeScript.js
|
||||
|
||||
[test_canMakePayment.html]
|
||||
[test_abortPayment.html]
|
|
@ -0,0 +1,86 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1345367
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1345367</title>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript">
|
||||
|
||||
"use strict";
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
const defaultMethods = [{
|
||||
supportedMethods: ["basic-card"],
|
||||
}];
|
||||
const defaultDetails = {
|
||||
total: {
|
||||
label: "Total",
|
||||
amount: {
|
||||
currency: "USD",
|
||||
value: "1.00"
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function testBeforeShow() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
payRequest.abort().then((result) => {
|
||||
ok(false, "Should throw 'InvalidStateError', but got resolved.");
|
||||
resolve();
|
||||
}).catch((err) => {
|
||||
is(err.name, "InvalidStateError",
|
||||
"Expected 'InvalidStateError', but got '" + err.name + "'");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testAfterShow() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
const acceptPromise = payRequest.show();
|
||||
payRequest.abort().then((abortResult) => {
|
||||
is(abortResult, undefined, "Should be resolved with undefined.");
|
||||
resolve();
|
||||
}).catch( (err) => {
|
||||
ok(false, "Expected no error, but got '" + err.name + "'.");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
testBeforeShow()
|
||||
.then(testAfterShow)
|
||||
.then(SimpleTest.finish)
|
||||
.catch( e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
SpecialPowers.pushPrefEnv({
|
||||
'set': [
|
||||
['dom.payments.request.enabled', true],
|
||||
]
|
||||
}, runTests);
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1345367">Mozilla Bug 1345367</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,151 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1345365
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for PaymentRequest API canMakePayment()</title>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript">
|
||||
|
||||
"use strict";
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var gUrl = SimpleTest.getTestFileURL('CanMakePaymentChromeScript.js');
|
||||
var gScript = SpecialPowers.loadChromeScript(gUrl);
|
||||
|
||||
const defaultMethods = [{
|
||||
supportedMethods: ["basic-card"],
|
||||
}];
|
||||
const defaultDetails = {
|
||||
total: {
|
||||
label: "Total",
|
||||
amount: {
|
||||
currency: "USD",
|
||||
value: "1.00"
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function testSimple() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
payRequest.canMakePayment().then((result) => {
|
||||
ok(result, "Should be resolved with true, but got false.");
|
||||
resolve();
|
||||
}).catch((err) => {
|
||||
ok(false, "Expected no error, but got '" + err.name +"'.");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testAfterShow() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
const acceptPromise = payRequest.show();
|
||||
payRequest.canMakePayment().then((result) => {
|
||||
ok(false, "Should throw 'InvalidStateError', but got resolved.");
|
||||
resolve();
|
||||
}).catch( (err) => {
|
||||
is(err.name, "InvalidStateError",
|
||||
"Expected 'InvalidStateError', but got '" + err.name + "'.");
|
||||
payRequest.abort().then((abortResult) => {
|
||||
is(abortResult, undefined, "abort() should be resolved with undefined.");
|
||||
resolve();
|
||||
}).catch( (err) => {
|
||||
ok(false, "Expected no error, but got '" + err.name + "'.");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testAfterAbort() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
const acceptPromise = payRequest.show();
|
||||
payRequest.abort().then((abortResult) => {
|
||||
payRequest.canMakePayment().then((result) => {
|
||||
ok(false, "Should throw 'InvalidStateError', but got resolved.");
|
||||
resolve();
|
||||
}).catch( (err) => {
|
||||
is(err.name, "InvalidStateError",
|
||||
"Expected 'InvalidStateError', but got '" + err.name + "'.");
|
||||
resolve();
|
||||
});
|
||||
}).catch( (err) => {
|
||||
ok(false, "Expected no error, but got '" + err.name +"'.");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testNotAllowed() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let payRequest = new PaymentRequest(defaultMethods, defaultDetails);
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
try {
|
||||
await payRequest.canMakePayment();
|
||||
} catch(err) {
|
||||
is(err.name, "NotAllowedError",
|
||||
"Expected 'NotAllowError', but got '" + err.name + "'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
try {
|
||||
await new PaymentRequest(defaultMethods, defaultDetails).canMakePayment();
|
||||
} catch(err) {
|
||||
is(err.name, "NotAllowedError",
|
||||
"Expected 'NotAllowError', but got '" + err.name + "'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
|
||||
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
|
||||
gScript.destroy();
|
||||
SimpleTest.finish();
|
||||
});
|
||||
gScript.sendAsyncMessage("teardown");
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
testSimple()
|
||||
.then(testAfterShow)
|
||||
.then(testAfterAbort)
|
||||
.then(testNotAllowed)
|
||||
.then(teardown)
|
||||
.catch(e => {
|
||||
ok(false, "Unexpected error: " + e.name);
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
SpecialPowers.pushPrefEnv({
|
||||
'set': [
|
||||
['dom.payments.request.enabled', true],
|
||||
]
|
||||
}, runTests);
|
||||
});
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1345365">Mozilla Bug 1345365</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче