Commit dd42859a authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[Payment Request] Add Web Platform Tests for hasEnrolledInstrument().

The failing expectations are required because hasEnrolledInstrument()
is not yet turned on by default in Blink. These tests pass when running
Chrome with --enable-features=PaymentRequestHasEnrolledInstrument.

Bug: 915907
Change-Id: I2189bfedad813e7942c7ddbd44aac78d1b895a30
Reviewed-on: https://chromium-review.googlesource.com/c/1461313
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630578}
parent 53abdbf0
......@@ -2019,6 +2019,7 @@ external/wpt/payment-request/change-shipping-option-manual.https.html [ WontFix
external/wpt/payment-request/change-shipping-option-select-last-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-request-abort-method-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-request-canmakepayment-method-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-request-hasenrolledinstrument-method-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-request-multiple-show-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-request-show-method-manual.https.html [ WontFix ]
external/wpt/payment-request/payment-response/complete-method-manual.https.html [ WontFix ]
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>Manual tests for PaymentRequest.hasEnrolledInstrument() method</title>
<link rel="help" href="https://w3c.github.io/payment-request/#hasenrolledinstrument-method">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({
explicit_done: true,
explicit_timeout: true,
});
const defaultMethods = Object.freeze([
{
supportedMethods: "basic-card",
data: {
supportedNetworks: [ 'visa' ],
},
}
]);
const defaultDetails = Object.freeze({
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});
function testHasNoEnrolledInstrument() {
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
assert_false(
await request.hasEnrolledInstrument(),
"No test enrolled in the test profile."
);
}, `hasEnrolledInstrument() resolves to false when user has no enrolled instrument.`);
}
function testHasEnrolledInstrument() {
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
assert_true(
await request.hasEnrolledInstrument(),
"A card is enrolled in the test profile."
);
}, `hasEnrolledInstrument() resolves to true when user has an enrolled instrument.`);
}
function testHasEnrolledInstrumentAgain() {
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
assert_true(
await request.hasEnrolledInstrument(),
"A card is enrolled in the test profile."
);
}, `hasEnrolledInstrument() can be called multiple times if the payment method details are identical.`);
}
function testInteractiveState() {
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise = request.show(); // Sets state to "interactive"
const hasEnrolledInstrumentPromise = request.hasEnrolledInstrument();
try {
const result = await hasEnrolledInstrumentPromise;
assert_true(
false,
"hasEnrolledInstrument() should have thrown InvalidStateError"
);
} catch(err) {
await promise_rejects(t, "InvalidStateError", hasEnrolledInstrumentPromise);
} finally {
request.abort();
await promise_rejects(t, "AbortError", acceptPromise);
}
}, `If request.[[state]] is "interactive", then return a promise rejected with an "InvalidStateError" DOMException.`);
}
function testClosedState() {
promise_test(async t => {
const request = new PaymentRequest(defaultMethods, defaultDetails);
const acceptPromise = request.show(); // Sets state to "interactive"
acceptPromise.catch(() => {}); // no-op, just to handle unhandled rejection in devtools.
await request.abort(); // Sets state to "closed"
const hasEnrolledInstrumentPromise = request.hasEnrolledInstrument();
try {
const result = await hasEnrolledInstrumentPromise;
assert_true(
false,
"hasEnrolledInstrument() should have thrown InvalidStateError"
);
} catch(err) {
await promise_rejects(t, "InvalidStateError", hasEnrolledInstrumentPromise);
}
}, `If request.[[state]] is "closed", then return a promise rejected with an "InvalidStateError" DOMException.`);
}
</script>
<h2>Manual tests for hasEnrolledInstrument() method</h2>
<p>
Follow the instructions from top to bottom. Click on each button in sequence
without refreshing the page. Some of the tests will bring up the Payment
Request UI and close them automatically. If a payment sheet stays open, the
test has failed.
</p>
<ol>
<li>Follow browser-specific instructions to remove all cards from the test profile.</li>
<li>
<button onclick="testHasNoEnrolledInstrument()">
hasEnrolledInstrument() resolves to false when user has no enrolled instrument.
</button>
</li>
<li>Add a test Visa card to your test profile, e.g. 4012888888881881.</li>
<li>
<button onclick="testHasEnrolledInstrument()">
hasEnrolledInstrument() resolves to true when user has an enrolled instrument.
</button>
</li>
<li>
<button onclick="testHasEnrolledInstrumentAgain()">
hasEnrolledInstrument() can be called multiple times if the payment method
details are identical.
</button>
</li>
<li>
<button onclick="testInteractiveState()">
If request.[[state]] is "interactive", then return a promise rejected with
an "InvalidStateError" DOMException.
</button>
</li>
<li>
<button onclick="testClosedState()">
If request.[[state]] is "closed", then return a promise rejected with an
"InvalidStateError" DOMException.
</button>
</li>
<li>
<button onclick="done()">Done!</button>
</li>
</ol>
<small>
If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
</small>
This is a testharness.js-based test.
FAIL Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException. assert_equals: If it throws, then it must be a NotAllowedError. expected "NotAllowedError" but got "TypeError"
Harness: the test ran to completion.
<!DOCTYPE html>
<meta charset="utf-8">
<title>Tests for PaymentRequest.hasEnrolledInstrument() method</title>
<link rel="help" href="https://w3c.github.io/payment-request/#hasenrolledinstrument-method">
<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>
const visaMethod = Object.freeze({
supportedMethods: "basic-card",
data: {
supportedNetworks: ['visa']
}
});
const mastercardMethod = Object.freeze({
supportedMethods: "basic-card",
data: {
supportedNetworks: ['mastercard']
}
});
const defaultDetails = Object.freeze({
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});
promise_test(async t => {
// This test may never actually hit its assertion, but that's allowed.
const request = new PaymentRequest([visaMethod], defaultDetails);
for (let i = 0; i < 1000; i++) {
try {
await request.hasEnrolledInstrument();
} catch (err) {
assert_equals(
err.name,
"NotAllowedError",
"If it throws, then it must be a NotAllowedError."
);
break;
}
}
for (let i = 0; i < 1000; i++) {
try {
const request2 = new PaymentRequest([mastercardMethod], defaultDetails);
await request2.hasEnrolledInstrument();
} catch (err) {
assert_equals(
err.name,
"NotAllowedError",
"If it throws, then it must be a NotAllowedError."
);
break;
}
}
}, `Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.`);
</script>
<small>
If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
</small>
This is a testharness.js-based test.
FAIL hasEnrolledInstrument() resolves to false for unsupported payment methods. promise_test: Unhandled rejection with value: object "TypeError: request.hasEnrolledInstrument is not a function"
Harness: the test ran to completion.
<!DOCTYPE html>
<meta charset="utf-8">
<title>Tests for PaymentRequest.hasEnrolledInstrument() method</title>
<link rel="help" href="https://w3c.github.io/payment-request/#hasenrolledinstrument-method">
<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>
const unsupportedMethods = [
{ supportedMethods: "this-is-not-supported" },
{ supportedMethods: "https://not.supported" },
];
const defaultDetails = Object.freeze({
total: {
label: "Total",
amount: {
currency: "USD",
value: "1.00",
},
},
});
promise_test(async t => {
const request = new PaymentRequest(unsupportedMethods, defaultDetails);
assert_false(
await request.hasEnrolledInstrument(),
"Payment method is supported."
);
}, `hasEnrolledInstrument() resolves to false for unsupported payment methods.`);
</script>
<small>
If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
</small>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment