Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

// META: title=Link header RFC 8288 parsing rules
// META: script=/common/utils.js
// META: script=/payment-method-manifest/resources/helpers.js
promise_test(async t => {
const testId = token();
const manifestUrl = createPaymentMethodManifestUrl(testId);
const pmiUrl = createPaymentMethodIdentifierUrl(
testId, {link: `<${manifestUrl}>; rel=payment-method-manifest`});
const request = new PaymentRequest(
[{supportedMethods: pmiUrl}],
{total: {label: 'Total', amount: {currency: 'USD', value: '1.00'}}});
try {
await request.canMakePayment();
} catch (err) {
}
const logs = await waitForServerAccessLogs(t, testId, 2);
assert_equals(
logs.length, 2,
'Browser must issue exactly 2 server requests (HEAD for PMI, GET for Manifest)');
assert_equals(logs[0].endpoint, 'payment-method-identifier',
'First request must hit PMI URL');
assert_equals(logs[0].method, 'HEAD', 'PMI request must use HEAD method');
assert_equals(logs[1].endpoint, 'payment-method-manifest',
'Second request must hit manifest URL');
assert_equals(logs[1].method, 'GET', 'Manifest request must use GET method');
}, 'Link header rel parameter supports unquoted values per RFC 8288');
promise_test(async t => {
const testId = token();
const manifestUrl = createPaymentMethodManifestUrl(testId);
const pmiUrl = createPaymentMethodIdentifierUrl(
testId, {link: `<${manifestUrl}>; rel="other payment-method-manifest"`});
const request = new PaymentRequest(
[{supportedMethods: pmiUrl}],
{total: {label: 'Total', amount: {currency: 'USD', value: '1.00'}}});
try {
await request.canMakePayment();
} catch (err) {
}
const logs = await waitForServerAccessLogs(t, testId, 2);
assert_equals(
logs.length, 2,
'Browser must issue exactly 2 server requests (HEAD for PMI, GET for Manifest)');
assert_equals(logs[0].endpoint, 'payment-method-identifier',
'First request must hit PMI URL');
assert_equals(logs[0].method, 'HEAD', 'PMI request must use HEAD method');
assert_equals(logs[1].endpoint, 'payment-method-manifest',
'Second request must hit manifest URL');
assert_equals(logs[1].method, 'GET', 'Manifest request must use GET method');
}, 'Link header rel attribute supports space-separated relation tokens per RFC 8288');
promise_test(async t => {
const testId = token();
const manifestUrl = createPaymentMethodManifestUrl(testId);
const pmiUrl = createPaymentMethodIdentifierUrl(
testId, {link: `<${manifestUrl}>; rel="PAYMENT-METHOD-MANIFEST"`});
const request = new PaymentRequest(
[{supportedMethods: pmiUrl}],
{total: {label: 'Total', amount: {currency: 'USD', value: '1.00'}}});
try {
await request.canMakePayment();
} catch (err) {
}
const logs = await waitForServerAccessLogs(t, testId, 2);
assert_equals(
logs.length, 2,
'Browser must issue exactly 2 server requests (HEAD for PMI, GET for Manifest)');
assert_equals(logs[0].endpoint, 'payment-method-identifier',
'First request must hit PMI URL');
assert_equals(logs[0].method, 'HEAD', 'PMI request must use HEAD method');
assert_equals(logs[1].endpoint, 'payment-method-manifest',
'Second request must hit manifest URL');
assert_equals(logs[1].method, 'GET', 'Manifest request must use GET method');
}, 'Link header rel parameter matching is ASCII case-insensitive');
promise_test(async t => {
const testId = token();
const manifestUrl = createPaymentMethodManifestUrl(testId);
const pmiUrl = createPaymentMethodIdentifierUrl(
testId,
{link: `<${manifestUrl}>; rel="payment-method-manifest"; foo=bar`});
const request = new PaymentRequest(
[{supportedMethods: pmiUrl}],
{total: {label: 'Total', amount: {currency: 'USD', value: '1.00'}}});
try {
await request.canMakePayment();
} catch (err) {
}
const logs = await waitForServerAccessLogs(t, testId, 2);
assert_equals(
logs.length, 2,
'Browser must issue exactly 2 server requests (HEAD for PMI, GET for Manifest)');
assert_equals(logs[0].endpoint, 'payment-method-identifier',
'First request must hit PMI URL');
assert_equals(logs[0].method, 'HEAD', 'PMI request must use HEAD method');
assert_equals(logs[1].endpoint, 'payment-method-manifest',
'Second request must hit manifest URL');
assert_equals(logs[1].method, 'GET', 'Manifest request must use GET method');
}, 'Link header with additional parameters is parsed correctly');
promise_test(async t => {
const testId = token();
const manifestUrl = createPaymentMethodManifestUrl(testId);
const otherUrl = new URL('resources/other.json', location.href).href;
const pmiUrl = createPaymentMethodIdentifierUrl(testId, {
link: `<${otherUrl}>; rel="other", <${
manifestUrl}>; rel="payment-method-manifest"`,
});
const request = new PaymentRequest(
[{supportedMethods: pmiUrl}],
{total: {label: 'Total', amount: {currency: 'USD', value: '1.00'}}});
try {
await request.canMakePayment();
} catch (err) {
}
const logs = await waitForServerAccessLogs(t, testId, 2);
assert_equals(
logs.length, 2,
'Browser must issue exactly 2 server requests (HEAD for PMI, GET for Manifest)');
assert_equals(logs[0].endpoint, 'payment-method-identifier',
'First request must hit PMI URL');
assert_equals(logs[0].method, 'HEAD', 'PMI request must use HEAD method');
assert_equals(logs[1].endpoint, 'payment-method-manifest',
'Second request must hit correct manifest URL');
assert_equals(logs[1].method, 'GET', 'Manifest request must use GET method');
}, 'Link header with comma-separated targets correctly identifies payment-method-manifest link');