-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial manual tests for basic card #6817
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
acf769a
Add defaults and helpers for Payments Basic Card
marcoscaceres a5a1cec
manual tests for when BasicCardRequest is empty
marcoscaceres 6713eb4
Improve code comments
marcoscaceres 7eae66d
check basic card support via pr.canMakePayment()
marcoscaceres 049070b
style: missing ;
marcoscaceres 6cf54d3
rework and simplify test
marcoscaceres ded4148
fix some nits
marcoscaceres 844f6c1
Improved manual test details
marcoscaceres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<!doctype html> | ||
<meta charset="utf8"> | ||
<title>Payment Method Basic Card - test passing empty BasicCardRequest members</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
setup({ explicit_done: true, explicit_timeout: true }); | ||
|
||
const amount = { value: "1.0", currency: "USD" }; | ||
const details = { | ||
total: { | ||
label: "Total", | ||
amount, | ||
}, | ||
}; | ||
const method = { | ||
supportedMethods: "basic-card", | ||
}; | ||
|
||
const defaultBillingAddress = { | ||
country: 'AF', | ||
addressLine: '1 wpt street', | ||
region: '', | ||
city: 'Kabul', | ||
dependentLocality: '', | ||
postalCode: '1001', | ||
sortingCode: '', | ||
languageCode: 'fa', | ||
organization: 'w3c', | ||
recipient: 'web platform test', | ||
phone: '+93555555555', | ||
}; | ||
|
||
const visaCredit = { | ||
cardNumber: "4111111111111111", | ||
cardSecurityCode: "123", | ||
cardholderName: "web platform test", | ||
expiryMonth: "01", | ||
expiryYear: "2026", | ||
}; | ||
|
||
async function getCardResponse(data) { | ||
const method = Object.assign({ data }, methodCard); | ||
const response = await new PaymentRequest([method], defaultDetails).show(); | ||
await response.complete("success"); | ||
return response.details; | ||
} | ||
|
||
/** | ||
* All tests expect the same return data, so we can just check the | ||
* same result over and over again. | ||
*/ | ||
function runPromiseTest(button, data, expectedCard = visaCredit, expectedAddress = defaultBillingAddress ) { | ||
button.disabled = true; | ||
promise_test(async () => { | ||
const card = await getCardResponse(data); | ||
for (const [member, expectedValue] of Object.entries(expectedCard)) { | ||
const msg = `Expected card.${member} to equal ${expectedValue}.`; | ||
assert_equals(card[member], expectedValue, msg); | ||
} | ||
const { billingAddress } = card; | ||
for (const [member, expectedValue] of Object.entries(expectedAddress)) { | ||
const msg = `billingAddress.${member} to equal ${expectedValue}.`; | ||
assert_equals(billingAddress[member], expectedValue); | ||
} | ||
}, button.textContent.trim()); | ||
} | ||
</script> | ||
<h2> | ||
Payment Method Basic Card - test passing empty BasicCardRequest values | ||
</h2> | ||
<p> | ||
This test checks that the Basic Card payment handler can accept any card. | ||
</p> | ||
<p> | ||
Click on each button in sequence from top to bottom without refreshing the page. | ||
Each button will bring up the Payment Request UI window. | ||
The test expects the following credit card. | ||
</p> | ||
<ol> | ||
<li>Add credit card: | ||
<dl> | ||
<dt>Cardholder name:</dt> | ||
<dd>web platform test</dd> | ||
<dt>Card number:</dt> | ||
<dd>4111111111111111</dd> | ||
<dt>Security code (CVV):</dt> | ||
<dd>123</dd> | ||
<dt>Expiry month:</dt> | ||
<dd>01</dd> | ||
<dt>Expiry year:</dt> | ||
<dd>2026</dd> | ||
</dl> | ||
</li> | ||
<li>Add billing address: | ||
<dl> | ||
<dt>Recipient:</dt> | ||
<dd>web platform test</dd> | ||
<dt>Address:</dt> | ||
<dd>1 web st</dd> | ||
<dt>Post code:</dt> | ||
<dd>1234</dd> | ||
<dt>Country:</dt> | ||
<dd>Afghanistan</dd> | ||
<dt>City:</dt> | ||
<dd>w3c</dd> | ||
<dt>Phone</dt> | ||
<dd>+12345678910</dd> | ||
</dl> | ||
</li> | ||
</ol> | ||
<hr> | ||
<ol> | ||
<li> | ||
<button onclick="runPromiseTest(this, {});"> | ||
When passed BasicCardRequest without members, allow the user to input of any credit card type. | ||
</button> | ||
</li> | ||
<li> | ||
<button onclick="runPromiseTest(this, { supportedNetworks: [], supportedTypes: [] });"> | ||
Returns any card type on any network, because zero length supportedNetworks and supportedTypes. | ||
</button> | ||
</li> | ||
<li> | ||
<button onclick="runPromiseTest(this, { supportedNetworks: [] });"> | ||
Returns any card type on any network, because supportedNetworks is missing and supportedTypes is empty. | ||
</button> | ||
</li> | ||
<li> | ||
<button onclick="runPromiseTest(this, { supportedTypes: [] });"> | ||
Returns any card type on any network missing supportedTypes, and empty supportedNetwork. | ||
</button> | ||
</li> | ||
</ol> | ||
|
||
<small> | ||
If you find a buggy test, please <a href="https://github.com/w3c/web-platform-tests/issues">file a bug</a> | ||
and tag one of the <a href="https://github.com/w3c/web-platform-tests/blob/master/payment-request/OWNERS">owners</a>. | ||
</small> |
89 changes: 89 additions & 0 deletions
89
payment-method-basic-card/payment-request-canmakepayment-method.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!DOCTYPE html> | ||
<!-- Copyright © 2017 World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). --> | ||
<meta charset="utf-8"> | ||
<title>Payment Method Basic Card: Tests that basic card is a supported method</title> | ||
<link rel="help" href="https://w3c.github.io/browser-payment-api/#show-method"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
const basicCard = Object.freeze({ supportedMethods: "basic-card", data: {} }); | ||
const defaultMethods = Object.freeze([basicCard]); | ||
const defaultDetails = Object.freeze({ | ||
total: { | ||
label: "Total", | ||
amount: { | ||
currency: "USD", | ||
value: "1.00", | ||
}, | ||
}, | ||
}); | ||
|
||
const notSupportedMethod = Object.freeze({ | ||
supportedMethods: "this-is-not-supported", | ||
}); | ||
|
||
promise_test(async t => { | ||
const request = new PaymentRequest([notSupportedMethod], defaultDetails); | ||
assert_false( | ||
await request.canMakePayment(), | ||
`canMakePaymentPromise should be false` | ||
); | ||
}, `Must return false when the PMI is not supported at by the user agent.`); | ||
|
||
function* pmiGenerator(howMany = 256) { | ||
for (i = 0; i < howMany; i++) { | ||
yield { | ||
supportedMethods: `this-is-not-supported-${i}`, | ||
data: { key: "value" }, | ||
}; | ||
} | ||
} | ||
|
||
promise_test(async t => { | ||
//Smoke test | ||
const canMakePaymentPromise = new PaymentRequest( | ||
[notSupportedMethod], | ||
defaultDetails | ||
).canMakePayment(); | ||
assert_false( | ||
await canMakePaymentPromise, | ||
"Expected canMakePaymentPromise smoke test to resolve with false" | ||
); | ||
// Actual test - Make a big array with random PMIs, | ||
// put basic-card in the middle of it! | ||
const pmis = [] | ||
.concat(Array.from(pmiGenerator(250))) | ||
.concat(basicCard) | ||
.concat(Array.from(pmiGenerator(250))); | ||
const request = new PaymentRequest(pmis, defaultDetails); | ||
assert_true( | ||
await request.canMakePayment(), | ||
`canMakePaymentPromise should be true, because basic-card is present` | ||
); | ||
}, `Must return true when basic-card is amongst unsupported PMIs.`); | ||
|
||
promise_test(async t => { | ||
const request = new PaymentRequest(defaultMethods, defaultDetails); | ||
try { | ||
assert_true( | ||
await request.canMakePayment(), | ||
`canMakePaymentPromise must resolve to true` | ||
); | ||
assert_true( | ||
await request.canMakePayment(), | ||
`canMakePaymentPromise must resolve to true` | ||
); | ||
// try to trigger optional behavior | ||
for (let i = 0; i < 1024; i++) { | ||
const temp = new PaymentRequest(defaultMethods, defaultDetails); | ||
await Promise.all([temp.canMakePayment(), request.canMakePayment()]); | ||
} | ||
} catch (err) { | ||
assert_equals( | ||
err.name, | ||
"NotAllowedError", | ||
"if it throws, then it must be a NotAllowedError." | ||
); | ||
} | ||
}, `If basic-card is supported, then return a promise that resolves to true.`); | ||
</script> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the other tests fail as such in Chrome:
promise_test: Unhandled rejection with value: object "TypeError: Failed to construct 'PaymentRequest': The provided value cannot be converted to a sequence."
Chrome bug, or test bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chrome bug in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for poking at it with a test!