Skip to content

Commit 47ce936

Browse files
[CodeHealth] Update PE attribute tests for a cleaner wpt.fyi status.
- Remove redundant assert messages. - Combine related asserts into fewer tests. - Add missing type checks for inherited attributes. - Clean up the use of action Promises. Change-Id: I1e87af6e55d13be23a959bd0ee5e28d96a510ab9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4086645 Reviewed-by: Kevin Ellis <[email protected]> Commit-Queue: Mustaq Ahmed <[email protected]> Cr-Commit-Position: refs/heads/main@{#1081495}
1 parent 3b757bc commit 47ce936

File tree

3 files changed

+96
-112
lines changed

3 files changed

+96
-112
lines changed

pointerevents/pointerevent_attributes_hoverable_pointers.html

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,37 @@
3131
return;
3232
var expectedEventType = eventList[Object.keys(detected_eventTypes).length];
3333
detected_eventTypes[event.type] = true;
34-
var pointerTestName = testNamePrefix + ' ' + expectedPointerType + ' ' + expectedEventType;
34+
var pointerTestName = (testNamePrefix ? testNamePrefix + ' ' : '')
35+
+ expectedPointerType + ' ' + expectedEventType;
3536

3637
detected_pointertypes[event.pointerType] = true;
3738

3839
test(function() {
39-
assert_equals(event.type, expectedEventType, "Event.type should be " + expectedEventType)
40-
}, pointerTestName + "'s type should be " + expectedEventType);
40+
assert_equals(event.type, expectedEventType);
41+
}, pointerTestName + ".type should be " + expectedEventType);
4142

4243
// Test button and buttons
4344
if (event.type == 'pointerdown') {
4445
test(function() {
45-
assert_equals(event.button, 0, "Button attribute is 0")
46-
}, pointerTestName + "'s button attribute is 0 when left mouse button is pressed.");
46+
assert_equals(event.button, 0);
47+
}, pointerTestName + ".button attribute is 0 when left mouse button is pressed.");
4748
test(function() {
48-
assert_equals(event.buttons, 1, "Buttons attribute is 1")
49-
}, pointerTestName + "'s buttons attribute is 1 when left mouse button is pressed.");
49+
assert_equals(event.buttons, 1);
50+
}, pointerTestName + ".buttons attribute is 1 when left mouse button is pressed.");
5051
} else if (event.type == 'pointerup') {
5152
test(function() {
52-
assert_equals(event.button, 0, "Button attribute is 0")
53-
}, pointerTestName + "'s button attribute is 0 when left mouse button is just released.");
53+
assert_equals(event.button, 0);
54+
}, pointerTestName + ".button attribute is 0 when left mouse button is just released.");
5455
test(function() {
55-
assert_equals(event.buttons, 0, "Buttons attribute is 0")
56-
}, pointerTestName + "'s buttons attribute is 0 when left mouse button is just released.");
56+
assert_equals(event.buttons, 0);
57+
}, pointerTestName + ".buttons attribute is 0 when left mouse button is just released.");
5758
} else {
5859
test(function() {
59-
assert_equals(event.button, -1, "Button attribute is -1")
60-
}, pointerTestName + "'s button is -1 when mouse buttons are in released state.");
60+
assert_equals(event.button, -1);
61+
}, pointerTestName + ".button is -1 when mouse buttons are in released state.");
6162
test(function() {
62-
assert_equals(event.buttons, 0, "Buttons attribute is 0")
63-
}, pointerTestName + "'s buttons is 0 when mouse buttons are in released state.");
63+
assert_equals(event.buttons, 0);
64+
}, pointerTestName + ".buttons is 0 when mouse buttons are in released state.");
6465
}
6566

6667
// Test clientX and clientY
@@ -70,38 +71,37 @@
7071
assert_greater_than_equal(event.clientY, targetBoundingClientRect.top, "clientY should be greater or equal than top of the box");
7172
assert_less_than_equal(event.clientX, targetBoundingClientRect.right, "clientX should be less or equal than right of the box");
7273
assert_less_than_equal(event.clientY, targetBoundingClientRect.bottom, "clientY should be less or equal than bottom of the box");
73-
}, pointerTestName + "'s ClientX and ClientY attributes are correct.");
74+
}, pointerTestName + ".clientX and .clientY attributes are correct.");
7475
} else {
7576
test(function () {
76-
assert_true(event.clientX < targetBoundingClientRect.left || event.clientX >= targetBoundingClientRect.right || event.clientY < targetBoundingClientRect.top || event.clientY >= targetBoundingClientRect.bottom, "ClientX/Y should be out of the boundaries of the box");
77-
}, pointerTestName + "'s ClientX and ClientY attributes are correct.");
77+
assert_true(event.clientX < targetBoundingClientRect.left || event.clientX >= targetBoundingClientRect.right || event.clientY < targetBoundingClientRect.top || event.clientY >= targetBoundingClientRect.bottom);
78+
}, pointerTestName + ".clientX and .clientY attributes are correct.");
7879
}
7980

8081
check_PointerEvent(event, testNamePrefix);
8182

8283
// Test isPrimary
8384
test(function () {
84-
assert_equals(event.isPrimary, true, "isPrimary should be true");
85-
}, pointerTestName + ".isPrimary attribute is correct.");
85+
assert_equals(event.isPrimary, true);
86+
}, pointerTestName + ".isPrimary attribute is true.");
8687

8788
// Test pointerId value
8889
if (isNaN(expectedPointerId)) {
8990
expectedPointerId = event.pointerId;
9091
} else {
9192
test(function () {
92-
assert_equals(event.pointerId, expectedPointerId, "pointerId should remain the same for the same active pointer");
93+
assert_equals(event.pointerId, expectedPointerId);
9394
}, pointerTestName + ".pointerId should be the same as previous pointer events for this active pointer.");
9495
}
9596
}
9697

97-
function run() {
98+
async function run() {
9899
var test_pointerEvent = setup_pointerevent_test("pointerevent attributes", [input_pointertype]);
99100
var square1 = document.getElementById("square1");
100101
var rectSquare1 = square1.getBoundingClientRect();
101102
var innerFrame = document.getElementById('innerFrame');
102103
var square2 = innerFrame.contentDocument.getElementById('square2');
103104
var rectSquare2 = square2.getBoundingClientRect();
104-
var actions_promise;
105105

106106
eventList.forEach(function(eventName) {
107107
on_event(square1, eventName, function (event) {
@@ -119,24 +119,16 @@
119119
checkPointerEventAttributes(event, rectSquare2, "Inner frame ");
120120
if (Object.keys(detected_eventTypes).length == eventList.length) {
121121
square2.style.visibility = 'hidden';
122-
// Make sure the test finishes after all the input actions are completed.
123-
actions_promise.then( () => {
124-
test_pointerEvent.done();
125-
});
122+
test_pointerEvent.done();
126123
}
127124
});
128125
});
129126

130127
// Inject mouse or pen inputs.
131-
actions_promise = clickInTarget(input_pointertype, square1).then(function() {
132-
return moveToDocument(input_pointertype);
133-
}).then(function() {
134-
return clickInTarget(input_pointertype, square2);
135-
}).then(function() {
136-
return moveToDocument(input_pointertype);
137-
}).then(function() {
138-
test_pointerEvent.done();
139-
});
128+
await clickInTarget(input_pointertype, square1);
129+
await moveToDocument(input_pointertype);
130+
await clickInTarget(input_pointertype, square2);
131+
await moveToDocument(input_pointertype);
140132
}
141133
</script>
142134
</head>

pointerevents/pointerevent_attributes_nohover_pointers.html

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,59 +28,59 @@
2828
return;
2929
var expectedEventType = eventList[Object.keys(detected_eventTypes).length];
3030
detected_eventTypes[event.type] = true;
31-
var pointerTestName = testNamePrefix + ' ' + expectedPointerType + ' ' + expectedEventType;
31+
var pointerTestName = (testNamePrefix ? testNamePrefix + ' ' : '')
32+
+ expectedPointerType + ' ' + expectedEventType;
3233

3334
detected_pointertypes[event.pointerType] = true;
3435

3536
test(function() {
36-
assert_equals(event.type, expectedEventType, "Event.type should be " + expectedEventType)
37-
}, pointerTestName + "'s type should be " + expectedEventType);
37+
assert_equals(event.type, expectedEventType);
38+
}, pointerTestName + ".type should be " + expectedEventType);
3839

3940
// Test button and buttons
4041
test(function() {
41-
assert_equals(event.button, 0, "Button attribute is 0")
42-
}, pointerTestName + "'s button attribute is 0 on touch-down.");
42+
assert_equals(event.button, 0);
43+
}, pointerTestName + ".button attribute is 0 on touch-down.");
4344

4445
if (event.type == 'pointerdown' || event.type == 'pointerover' || event.type == 'pointerenter') {
4546
test(function() {
46-
assert_equals(event.buttons, 1, "Buttons attribute is 1")
47-
}, pointerTestName + "'s buttons attribute is 1 on touch-down.");
47+
assert_equals(event.buttons, 1);
48+
}, pointerTestName + ".buttons attribute is 1 on touch-down.");
4849
} else {
4950
test(function() {
50-
assert_equals(event.buttons, 0, "Buttons attribute is 0")
51-
}, pointerTestName + "'s buttons is 0 on touch-release.");
51+
assert_equals(event.buttons, 0);
52+
}, pointerTestName + ".buttons is 0 on touch-release.");
5253
}
5354

5455
// Test clientX and clientY
5556
test(function () {
56-
assert_true(event.clientX >= targetBoundingClientRect.left && event.clientX < targetBoundingClientRect.right && event.clientY >= targetBoundingClientRect.top && event.clientY < targetBoundingClientRect.bottom, "ClientX/Y should be in the boundaries of the box");
57-
}, pointerTestName + "'s ClientX and ClientY attributes are correct.");
57+
assert_true(event.clientX >= targetBoundingClientRect.left && event.clientX < targetBoundingClientRect.right && event.clientY >= targetBoundingClientRect.top && event.clientY < targetBoundingClientRect.bottom);
58+
}, pointerTestName + ".clientX and .clientY attributes are correct.");
5859

5960
check_PointerEvent(event, testNamePrefix);
6061

6162
// Test isPrimary
6263
test(function () {
63-
assert_equals(event.isPrimary, true, "isPrimary should be true");
64-
}, pointerTestName + ".isPrimary attribute is correct.");
64+
assert_equals(event.isPrimary, true);
65+
}, pointerTestName + ".isPrimary attribute is true.");
6566

6667
// Test pointerId value
6768
if (isNaN(expectedPointerId)) {
6869
expectedPointerId = event.pointerId;
6970
} else {
7071
test(function () {
71-
assert_equals(event.pointerId, expectedPointerId, "pointerId should remain the same for the same active pointer");
72+
assert_equals(event.pointerId, expectedPointerId);
7273
}, pointerTestName + ".pointerId should be the same as previous pointer events for this active pointer.");
7374
}
7475
}
7576

76-
function run() {
77+
async function run() {
7778
var test_pointerEvent = setup_pointerevent_test("pointerevent attributes", ['touch']);
7879
var square1 = document.getElementById("square1");
7980
var rectSquare1 = square1.getBoundingClientRect();
8081
var innerFrame = document.getElementById('innerFrame');
8182
var square2 = innerFrame.contentDocument.getElementById('square2');
8283
var rectSquare2 = square2.getBoundingClientRect();
83-
var actions_promise;
8484

8585
eventList.forEach(function(eventName) {
8686
on_event(square1, eventName, function (event) {
@@ -98,18 +98,14 @@
9898
checkPointerEventAttributes(event, rectSquare2, "Inner frame ");
9999
if (Object.keys(detected_eventTypes).length == eventList.length) {
100100
square2.style.visibility = 'hidden';
101-
// Make sure the test finishes after all the input actions are completed.
102-
actions_promise.then( () => {
103-
test_pointerEvent.done();
104-
});
101+
test_pointerEvent.done();
105102
}
106103
});
107104
});
108105

109106
// Inject touch inputs.
110-
actions_promise = clickInTarget("touch", square1).then(function() {
111-
return clickInTarget("touch", square2);
112-
});
107+
await clickInTarget("touch", square1);
108+
await clickInTarget("touch", square2);
113109
}
114110
</script>
115111
</head>

pointerevents/pointerevent_support.js

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,27 @@ const ButtonsBitfield = {
4242
};
4343

4444
// Check for conformance to PointerEvent interface
45-
// TA: 1.1, 1.2, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11, 1.12, 1.13
45+
// https://w3c.github.io/pointerevents/#pointerevent-interface
4646
function check_PointerEvent(event, testNamePrefix) {
4747
if (testNamePrefix === undefined)
4848
testNamePrefix = "";
4949

5050
// Use expectedPointerType if set otherwise just use the incoming event pointerType in the test name.
51-
var pointerTestName = testNamePrefix + ' ' + (expectedPointerType == null ? event.pointerType : expectedPointerType) + ' ' + event.type;
51+
var pointerTestName = (testNamePrefix ? testNamePrefix + ' ' : '')
52+
+ (expectedPointerType == null ? event.pointerType : expectedPointerType) + ' ' + event.type;
5253

5354
if (expectedPointerType != null) {
5455
test(function () {
55-
assert_equals(event.pointerType, expectedPointerType, "pointerType should be the one specified in the test page.");
56-
}, pointerTestName + " event pointerType is correct.");
56+
assert_equals(event.pointerType, expectedPointerType);
57+
}, pointerTestName + ".pointerType is correct.");
5758
}
5859

5960
test(function () {
60-
assert_true(event instanceof event.target.ownerDocument.defaultView.PointerEvent, "event is a PointerEvent event");
61+
assert_true(event instanceof event.target.ownerDocument.defaultView.PointerEvent);
6162
}, pointerTestName + " event is a PointerEvent event");
6263

6364

64-
// Check attributes for conformance to WebIDL:
65-
// * attribute exists
66-
// * has proper type
67-
// * if the attribute is "readonly", it cannot be changed
68-
// TA: 1.1, 1.2
65+
// Check attributes for conformance to WebIDL (existence, type, being readable).
6966
var idl_type_check = {
7067
"long": function (v) { return typeof v === "number" && Math.round(v) === v; },
7168
"float": function (v) { return typeof v === "number"; },
@@ -74,60 +71,60 @@ function check_PointerEvent(event, testNamePrefix) {
7471
"object": function (v) { return typeof v === "object" }
7572
};
7673
[
77-
["readonly", "long", "pointerId"],
78-
["readonly", "float", "width"],
79-
["readonly", "float", "height"],
80-
["readonly", "float", "pressure"],
81-
["readonly", "long", "tiltX"],
82-
["readonly", "long", "tiltY"],
83-
["readonly", "string", "pointerType"],
84-
["readonly", "boolean", "isPrimary"],
85-
["readonly", "long", "detail", 0],
86-
["readonly", "object", "fromElement", null],
87-
["readonly", "object", "toElement", null],
88-
["readonly", "boolean", "isTrusted", true]
74+
["long", "pointerId"],
75+
["float", "width"],
76+
["float", "height"],
77+
["float", "pressure"],
78+
["long", "tiltX"],
79+
["long", "tiltY"],
80+
["string", "pointerType"],
81+
["boolean", "isPrimary"],
82+
["long", "detail", 0],
83+
["object", "fromElement"],
84+
["object", "toElement"],
85+
["boolean", "isTrusted"],
86+
["boolean", "composed"],
87+
["boolean", "bubbles"]
8988
].forEach(function (attr) {
90-
var readonly = attr[0];
91-
var type = attr[1];
92-
var name = attr[2];
93-
var value = attr[3];
89+
var type = attr[0];
90+
var name = attr[1];
9491

95-
// existence check
9692
test(function () {
97-
assert_true(name in event, name + " attribute in " + event.type + " event");
98-
}, pointerTestName + "." + name + " attribute exists");
99-
100-
// readonly check
101-
if (readonly === "readonly") {
102-
test(function () {
103-
assert_readonly(event.type, name, event.type + "." + name + " cannot be changed");
104-
}, pointerTestName + "." + name + " is readonly");
105-
}
93+
// Existence check.
94+
assert_true(name in event, "attribute exists");
10695

107-
// type check
108-
test(function () {
109-
assert_true(idl_type_check[type](event[name]), name + " attribute of type " + type);
110-
}, pointerTestName + "." + name + " IDL type " + type + " (JS type was " + typeof event[name] + ")");
111-
112-
// value check if defined
113-
if (value !== undefined) {
114-
test(function () {
115-
assert_equals(event[name], value, name + " attribute value");
116-
}, pointerTestName + "." + name + " value is " + value + ".");
117-
}
96+
// Readonly check.
97+
assert_readonly(event.type, name, "attribute is readonly");
98+
99+
// Type check.
100+
assert_true(idl_type_check[type](event[name]),
101+
"attribute type " + type + " (JS type was " + typeof event[name] + ")");
102+
}, pointerTestName + "." + name + " conforms to WebIDL");
118103
});
119104

120-
// Check the composed value
105+
// Check values for inherited attributes.
121106
// https://w3c.github.io/pointerevents/#attributes-and-default-actions
107+
test(function () {
108+
assert_equals(event.fromElement, null);
109+
}, pointerTestName + ".fromElement value is null");
110+
test(function () {
111+
assert_equals(event.toElement, null);
112+
}, pointerTestName + ".toElement value is null");
113+
test(function () {
114+
assert_equals(event.isTrusted, true);
115+
}, pointerTestName + ".isTrusted value is true");
122116
test(function () {
123117
let expected = (event.type != 'pointerenter' && event.type != 'pointerleave');
124-
assert_equals(event.composed, expected, "composed attribute value");
118+
assert_equals(event.composed, expected);
125119
}, pointerTestName + ".composed value is valid");
120+
test(function () {
121+
let expected = (event.type != 'pointerenter' && event.type != 'pointerleave');
122+
assert_equals(event.bubbles, expected);
123+
}, pointerTestName + ".bubbles value is valid");
126124

127-
// Check the pressure value
128-
// TA: 1.6, 1.7, 1.8
125+
// Check the pressure value.
126+
// https://w3c.github.io/pointerevents/#dom-pointerevent-pressure
129127
test(function () {
130-
// TA: 1.6
131128
assert_greater_than_equal(event.pressure, 0, "pressure is greater than or equal to 0");
132129
assert_less_than_equal(event.pressure, 1, "pressure is less than or equal to 1");
133130

@@ -145,7 +142,6 @@ function check_PointerEvent(event, testNamePrefix) {
145142

146143
// Check mouse-specific properties.
147144
if (event.pointerType === "mouse") {
148-
// TA: 1.9, 1.10, 1.13
149145
test(function () {
150146
assert_equals(event.width, 1, "width of mouse should be 1");
151147
assert_equals(event.height, 1, "height of mouse should be 1");

0 commit comments

Comments
 (0)