1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Clicking with primary vs non-primary buttons</title>
<link rel="help" href="https://wicg.github.io/auxclick/">
<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>
<style>
#target {
background-color: green;
height: 200px;
width: 200px;
}
</style>
</head>
<body>
<h1>Clicking with primary vs non-primary buttons</h1>
<p>Double-click on the green box with a non-primary button. When using mouse any button other than the left button is non-primary. If a "PASS" result appears, the test passes; otherwise, it fails.</p>
<div id="target"></div>
<script>
var test_auxclick = async_test("auxclick event sequence received.");
var actions_promise;
var target = document.querySelector('#target');
document.addEventListener('contextmenu', event => { event.preventDefault(); });
['click', 'dblclick'].forEach(eventName => {
target.addEventListener(eventName, () => {
test_auxclick.step(() => {
assert_unreached(eventName + ' event should not be dispatched for non-primary buttons.');
});
});
document.addEventListener(eventName, () => {
test_auxclick.step(() => {
assert_unreached('document should not receive ' + eventName + ' for non-primary buttons.');
});
}, true);
});
var click_count = 0;
var events = [];
['mousedown', 'mouseup'].forEach(eventName => {
target.addEventListener(eventName, event => {
events.push(event.type);
});
});
target.addEventListener('auxclick', event => {
events.push(event.type);
click_count++;
if (click_count==1) {
test (() => {
assert_equals(event.detail, click_count, 'detail attribute of auxclick should be the click count.');
}, "First auxclick should have detail=1 indicating the fire click");
} else {
test (() => {
assert_equals(event.detail, click_count, 'detail attribute of auxclick should be the click count.');
}, "Second auxclick should have detail=2 indicating the fire click");
test_auxclick.step(() => {
assert_array_equals(events, ['mousedown', 'mouseup', 'auxclick', 'mousedown', 'mouseup', 'auxclick'],
'There should be two auxclick events for a non-primary button double click each preceded by one mousemove and one mouseup');
assert_equals(event.detail, click_count, 'detail attribute of auxclick should be the click count.');
});
// Make sure the test finishes after all the input actions are completed.
actions_promise.then( () => {
test_auxclick.done();
});
}
});
// Inject mouse double click events.
var actions = new test_driver.Actions();
actions_promise = actions.pointerMove(0, 0, {origin: target})
.pointerDown({button: actions.ButtonType.MIDDLE})
.pointerUp({button: actions.ButtonType.MIDDLE})
.pointerDown({button: actions.ButtonType.MIDDLE})
.pointerUp({button: actions.ButtonType.MIDDLE})
.send();
</script>
</body>
</html>
|