blob: 0efc9eb80b3dd4ac63a0906a98aa22bc2e0f16d1 [file] [log] [blame] [edit]
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test for the 'secure-payment-confirmation' payment method enrollment - cross origin</title>
<link rel="help" href="https://w3c.github.io/secure-payment-confirmation#client-extension-processing-registration">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="utils.sub.js"></script>
<script>
'use strict';
promise_test(async t => {
// Make sure that we are testing enrolling an SPC credential in a
// cross-origin iframe.
assert_not_equals(window.location.hostname, '{{hosts[alt][]}}',
'This test must not be run on the alt hostname.');
const authenticator = await window.test_driver.add_virtual_authenticator(
AUTHENTICATOR_OPTS);
t.add_cleanup(() => {
return window.test_driver.remove_virtual_authenticator(authenticator);
});
const frame = document.createElement('iframe');
frame.allow = 'payment';
frame.src = 'https://{{hosts[alt][]}}:{{ports[https][0]}}' +
'/secure-payment-confirmation/resources/iframe-enroll.html';
const resultPromise = new Promise(resolve => {
window.addEventListener('message', function handler(evt) {
if (evt.source === frame.contentWindow) {
window.removeEventListener('message', handler);
document.body.removeChild(frame);
resolve(evt.data);
}
});
});
document.body.appendChild(frame);
const result = await resultPromise;
// Because we specified the 'payment' permission, the enrollment should work.
assert_own_property(result, 'id');
assert_own_property(result, 'rawId');
assert_not_own_property(result, 'error');
}, 'SPC enrollment in cross-origin iframe');
promise_test(async t => {
// Make sure that we are testing enrolling an SPC credential in a
// cross-origin iframe.
assert_not_equals(window.location.hostname, '{{hosts[alt][]}}',
'This test must not be run on the alt hostname.');
const authenticator = await window.test_driver.add_virtual_authenticator(
AUTHENTICATOR_OPTS);
t.add_cleanup(() => {
return window.test_driver.remove_virtual_authenticator(authenticator);
});
const frame = document.createElement('iframe');
// This iframe does *not* have a payments permission specified on it, and so
// should not allow SPC credential creation.
frame.src = 'https://{{hosts[alt][]}}:{{ports[https][0]}}' +
'/secure-payment-confirmation/resources/iframe-enroll.html';
const resultPromise = new Promise(resolve => {
window.addEventListener('message', function handler(evt) {
if (evt.source === frame.contentWindow) {
window.removeEventListener('message', handler);
document.body.removeChild(frame);
resolve(evt.data);
}
});
});
document.body.appendChild(frame);
const result = await resultPromise;
// Because we didn't specify the 'payment' permission, the enrollment should
// result in an error.
assert_own_property(result, 'error');
assert_true(result.error instanceof DOMException);
assert_equals(result.error.name, 'NotSupportedError');
assert_not_own_property(result, 'id');
assert_not_own_property(result, 'rawId');
}, 'SPC enrollment in cross-origin iframe without payment permission');
</script>