mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-11-04 10:05:51 +00:00
94 lines
2.7 KiB
HTML
94 lines
2.7 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1097928
|
|
-->
|
|
<html>
|
|
<head>
|
|
<title>Test for navigator.mozPaymentProvider exposure. Bug 1097928</title>
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
</head>
|
|
<body>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
</div>
|
|
<pre id="test">
|
|
<script type="application/javascript;version=1.8">
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
// We create two iframes. The first one is a regular iframe with no payment
|
|
// information and so it should not have access to the MozPaymentProvider
|
|
// API. For the second iframe we set a dummy payment request ID which should
|
|
// expose the MozPaymentProvider API.
|
|
let tests = [function() {
|
|
// Iframe with no payment information.
|
|
let iframe = document.createElement("iframe");
|
|
iframe.setAttribute("mozbrowser", "true");
|
|
iframe.src = "file_mozpayproviderchecker.html";
|
|
|
|
document.getElementById("content").appendChild(iframe);
|
|
|
|
iframe.addEventListener("load", function onLoad() {
|
|
iframe.removeEventListener("load", onLoad);
|
|
iframe.contentWindow.postMessage(JSON.stringify({
|
|
iframeType: "regular"
|
|
}), "*");
|
|
}, false);
|
|
}, function() {
|
|
// Payment iframe.
|
|
let paymentIframe = document.createElement("iframe");
|
|
paymentIframe.setAttribute("mozbrowser", "true");
|
|
paymentIframe.src = "file_mozpayproviderchecker.html";
|
|
|
|
document.getElementById("content").appendChild(paymentIframe);
|
|
|
|
let Ci = SpecialPowers.Ci;
|
|
let docshell = SpecialPowers.wrap(paymentIframe.contentWindow)
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
.QueryInterface(Ci.nsIDocShell);
|
|
docshell.paymentRequestId = "dummyid";
|
|
|
|
paymentIframe.addEventListener("load", function onLoad() {
|
|
paymentIframe.removeEventListener("load", onLoad);
|
|
paymentIframe.contentWindow.postMessage(JSON.stringify({
|
|
iframeType: "payment"
|
|
}), "*");
|
|
}, false);
|
|
}];
|
|
|
|
function receiveMessage(event) {
|
|
let message = JSON.parse(event.data);
|
|
switch (message.iframeType) {
|
|
case "regular":
|
|
ok(!message.exposed, "MozPaymentProvider is not exposed in regular iframe");
|
|
break;
|
|
case "payment":
|
|
ok(message.exposed, "MozPaymentProvider is exposed in payment iframe");
|
|
break;
|
|
default:
|
|
ok(false, "Unexpected iframe type");
|
|
SimpleTest.finish();
|
|
}
|
|
runTest();
|
|
}
|
|
|
|
function runTest() {
|
|
if (!tests.length) {
|
|
ok(true, "Done!");
|
|
SimpleTest.finish();
|
|
return;
|
|
}
|
|
tests.shift()();
|
|
}
|
|
|
|
window.addEventListener("message", receiveMessage, false, true);
|
|
runTest();
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|