Skip to content
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

Assert modifier #1

Draft
wants to merge 2 commits into
base: label-modifier-click
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE HTML>
<title>clicks on label element with modifier keys </title>
<link rel="author" title="Mu-An Chiou" href="mailto:hi@muan.co">
<link rel="help" href="https://html.spec.whatwg.org/multipage/forms.html#the-label-element:the-label-element-10">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<div id="log"></div>
<div style="user-select: none;">
<label id="click-label" for="click">foo</label><input id="click" type="checkbox" />
<label id="shift-label" for="shift">foo</label><input id="shift" type="checkbox" />
<label id="alt-label" for="alt">foo</label><input id="alt" type="checkbox" />
<label id="meta-label" for="meta">foo</label><input id="meta" type="checkbox" />
</div>
<script>
"use strict";

function clickWithModifier(label, key) {
new test_driver.Actions()
.keyDown(key)
.pointerMove(0, 0, { origin: label })
.pointerDown()
.pointerUp()
.addTick()
.keyUp(key)
.send()
}

async_test(t => {
const label = document.getElementById("shift-label");
const input = document.getElementById("shift");

label.addEventListener("click", t.step_func(function (event) {
assert_true(event.shiftKey, 'shiftKey should be pressed on click');
t.done()
}));
clickWithModifier(label, "\uE008"); // ShiftLeft

}, "label with for attribute should proxy click events to the associated element on shift click");

async_test(t => {
const label = document.getElementById("alt-label");
const input = document.getElementById("alt");

label.addEventListener("click", t.step_func(function (event) {
assert_true(event.altKey, 'altKey should be pressed on click');
t.done()
}));
clickWithModifier(label, "\uE00A"); // AltLeft

}, "label with for attribute should proxy click events to the associated element on alt click");

async_test(t => {
const label = document.getElementById("meta-label");
const input = document.getElementById("meta");

label.addEventListener("click", t.step_func(function (event) {
assert_true(event.metaKey, 'metaKey should be pressed on click');
t.done()
}));
clickWithModifier(label, "\uE03D"); // OSLeft

}, "label with for attribute should proxy click events to the associated element on meta click");

</script>
4 changes: 2 additions & 2 deletions resources/testdriver-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
if (this.actions.has(i)) {
actions.push(this.actions.get(i));
} else {
actions.push({"type": "pause"});
actions.push({"type": "pause", duration: 0});
}
}
return data;
Expand Down Expand Up @@ -375,7 +375,7 @@
if (this.actions.has(i)) {
actions.push(this.actions.get(i));
} else {
actions.push({"type": "pause"});
actions.push({"type": "pause", duration: 0});
}
}
return data;
Expand Down