Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests, address PR feedback, refactor
- Loading branch information
Showing
4 changed files
with
86 additions
and
47 deletions.
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
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
55 changes: 55 additions & 0 deletions
55
...atform-tests/to-upstream/html/editing/activation/click-event-properties-dontupstream.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,55 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>click() should do nothing on disabled elements</title> | ||
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/#attr-button-type-submit-state"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<button>Click me</button> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
// these tests should not be upstreamed since: | ||
// 1. we're testing pageX/Y and scroll offsets by setting scrollX/Y which should be readonly; jsdom doesn't implement | ||
// scroll() and friends (yet) | ||
// 2. getBoundingClientRect() doesn't know about layout/scrolling, so jsdom can return some unusual offsetX/Y values | ||
// during dispatch despite the calculation logic being correct (see below) | ||
// 3. equivalent tests are being added upstream in https://github.com/web-platform-tests/wpt/pull/38912 that use scroll() | ||
// and expect correct offsetX/Y values during dispatch | ||
test(() => { | ||
window.scrollX = 10; | ||
window.scrollY = 20; | ||
const e = new MouseEvent("click", { | ||
clientX: 1, clientY: 2, view: window | ||
}); | ||
assert_equals(e.x, 1); | ||
assert_equals(e.y, 2); | ||
assert_equals(e.pageX, 11); | ||
assert_equals(e.pageY, 22); | ||
assert_equals(e.offsetX, 11); | ||
assert_equals(e.offsetY, 22); | ||
}, "MouseEvent should provide the correct computed values when the dispatch flag is not set"); | ||
|
||
async_test(t => { | ||
const element = document.querySelector("button"); | ||
element.addEventListener("click", t.step_func_done(e => { | ||
// changing these during dispatch should not mess up pageX/Y | ||
window.scrollX = 0; | ||
window.scrollY = 0; | ||
// coordinate reflects the right values as of the start of dispatch 👍 | ||
assert_equals(e.pageX, 110); | ||
assert_equals(e.pageY, 220); | ||
// these values are slightly wonky if there is a scroll offset, since getBoundingClientRect doesn't (yet) | ||
// consider scrolling or layout | ||
assert_equals(e.offsetX, 100); | ||
assert_equals(e.offsetY, 200); | ||
})); | ||
window.scrollX = 10; | ||
window.scrollY = 20; | ||
element.dispatchEvent(new MouseEvent("click", { | ||
clientX: 100, clientY: 200, view: window | ||
})); | ||
}, "MouseEvent should provide the correct computed values when the dispatch flag is set"); | ||
</script> |
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