-
Notifications
You must be signed in to change notification settings - Fork 3k
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
PaymentRequest "paymentmethodchanged" event #10912
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
22d3794
Test PaymentRequest.onpaymentmenthodchange attr
marcoscaceres 7412321
test PaymentRequest.methodDetails attr
marcoscaceres 4a17712
test PaymentRequest.methodName attr
marcoscaceres 0f9fc77
Remove copyright pasta
marcoscaceres fcb8fab
No basic card support for this
marcoscaceres f70f5a1
methodDetails attribute moved to PaymentMethodChangeEvent
marcoscaceres b90f717
moved to PaymentMethodChangeEvent.methodName
marcoscaceres 5eb8ca3
Test for PaymentMethodChangeEvent.methodDetails
marcoscaceres 65ca97b
Test for PaymentMethodChangeEvent.methodName
marcoscaceres eb34a27
Use PaymentMethodChangeEvent interface
marcoscaceres 773c20a
Add test suggested by @domenic
marcoscaceres 99cbcd2
lint: ignore CONTENT-VISUAL for pament test
marcoscaceres fa14f79
fixed missing src
marcoscaceres 4375122
Revert "lint: ignore CONTENT-VISUAL for pament test"
marcoscaceres File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
payment-request/PaymentMethodChangeEvent/methodDetails-attribute.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,21 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Test for PaymentMethodChangeEvent.methodDetails attribute</title> | ||
<link rel="help" href="https://w3c.github.io/browser-payment-api/#dom-paymentmethodchangeevent-methoddetails"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
"use strict"; | ||
test(() => { | ||
const methodDetails = { | ||
test: "pass" | ||
} | ||
const event = new PaymentMethodChangeEvent("test", { | ||
methodName: "wpt-test", | ||
methodDetails | ||
}); | ||
assert_idl_attribute(event, "methodDetails"); | ||
const { test } = event.methodDetails; | ||
assert_equals(test, "pass"); | ||
assert_equals(event.methodDetails, methodDetails); | ||
}, "Must have a methodDetails IDL attribute, which is initialized with to the methodName dictionary value"); |
16 changes: 16 additions & 0 deletions
16
payment-request/PaymentMethodChangeEvent/methodName-attribute.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,16 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Test for PaymentMethodChangeEvent.methodName attribute</title> | ||
<link rel="help" href="https://w3c.github.io/browser-payment-api/#dom-paymentmethodchangeevent-src"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
"use strict"; | ||
test(() => { | ||
const event = new PaymentMethodChangeEvent("test", { | ||
methodName: "wpt-test", | ||
}); | ||
assert_idl_attribute(event, "methodName"); | ||
const { methodName } = event; | ||
assert_equals(methodName, "wpt-test"); | ||
}, "Must have a methodName IDL attribute, which is initialized with to the methodName dictionary value"); |
70 changes: 70 additions & 0 deletions
70
payment-request/onpaymentmenthodchange-attribute.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,70 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Test for onpaymentmethodchange attribute</title> | ||
<link rel="help" href="https://w3c.github.io/browser-payment-api/#onpaymentmethodchange-attribute"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
"use strict"; | ||
const testMethod = Object.freeze({ supportedMethods: "not-a-real-method" }); | ||
const applePay = Object.freeze({ supportedMethods: "https://apple.com/apple-pay" }); | ||
const defaultMethods = Object.freeze([testMethod, applePay]); | ||
const defaultDetails = Object.freeze({ | ||
total: { | ||
label: "Total", | ||
amount: { | ||
currency: "USD", | ||
value: "1.00", | ||
}, | ||
}, | ||
}); | ||
|
||
test(() => { | ||
const request = new PaymentRequest(defaultMethods, defaultDetails); | ||
assert_idl_attribute(request, "onpaymentmethodchange"); | ||
}, "Must have a onpaymentmethodchange IDL attribute"); | ||
|
||
test(() => { | ||
const request = new PaymentRequest(defaultMethods, defaultDetails); | ||
const ev = new Event("paymentmethodchange"); | ||
let didHandle = false; | ||
request.onpaymentmethodchange = evt => { | ||
assert_equals(ev, evt, "must be same event"); | ||
didHandle = true; | ||
}; | ||
request.dispatchEvent(ev); | ||
assert_true(didHandle, "event did not fire"); | ||
}, `onpaymentmethodchange attribute is a generic handler for "paymentmethodchange"`); | ||
|
||
test(() => { | ||
const request = new PaymentRequest(defaultMethods, defaultDetails); | ||
const ev = new PaymentMethodChangeEvent("paymentmethodchange"); | ||
let didHandle = false; | ||
request.onpaymentmethodchange = evt => { | ||
assert_equals(ev, evt, "must be same event"); | ||
didHandle = true; | ||
}; | ||
request.dispatchEvent(ev); | ||
assert_true(didHandle, "event did not fire"); | ||
}, `onpaymentmethodchange attribute is a handler for PaymentMethodChangeEvent`); | ||
|
||
test(() => { | ||
const request = new PaymentRequest(defaultMethods, defaultDetails); | ||
const ev = new PaymentMethodChangeEvent("paymentmethodchange", { | ||
methodName: "test" | ||
}); | ||
let didHandle = false; | ||
let didListen = false; | ||
request.onpaymentmethodchange = evt => { | ||
assert_equals(ev, evt, "must be same event"); | ||
didHandle = true; | ||
}; | ||
request.addEventListener("paymentmethodchange", evt => { | ||
assert_equals(ev, evt, "must be same event"); | ||
didListen = true; | ||
}); | ||
request.dispatchEvent(ev); | ||
assert_true(didHandle, "onpaymentmethodchange did not receive the event"); | ||
assert_true(didListen, "addEventListener did not receive the event"); | ||
}, `onpaymentmethodchange attribute and listeners both work`); | ||
</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.
Nit: I thought generally the assertion message should say what should be true (e.g. "must be same event") but for many you are indicating what doesn't happen if it fails.
e.g. this should be "event fired"
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.
Yeah, it's a bit all over the place and a matter of preference. The messages only show up when tests fail, so I tend to explain why something failed rather than why something passed. So:
Why did X fail? ..."event did not fire".