Commit d5c9dc60 authored by Liquan(Max) Gu's avatar Liquan(Max) Gu Committed by Commit Bot

[EventTiming] Filter event types

EventTiming cares about the following types, according to
https://github.com/wicg/event-timing.

* MouseEvents
* PointerEvents
* TouchEvents
* KeyboardEvents
* WheelEvents
* InputEvents
* CompositionEvents

For this reason, this CL is to filter out events other than these.

Bug: 823744
Change-Id: I5491d15256ca72ac7d22f1e547ce65851c0493a0
Reviewed-on: https://chromium-review.googlesource.com/1087798
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565617}
parent ca04c733
<!DOCTYPE html>
<html>
<meta charset=utf-8 />
<title>Event Timing only times certain types of trusted event.
</title>
<button id='button' onclick='mainThreadBusy(500)'
onfocus='mainThreadBusy(500)'>Generate a 'click' event</button>
<script src=../../resources/testharness.js></script>
<script src=../../resources/testharnessreport.js></script>
<script src=./resources/event-timing-support.js></script>
<script>
let trustedClickStart = 0;
function trustedClickAndBlockMain(id) {
return new Promise((resolve, reject) => {
trustedClickStart = performance.now();
clickOnElement(id);
mainThreadBusy(500);
resolve();
});
}
function untrustedClickAndBlockMain(id) {
return new Promise((resolve, reject) => {
const target = document.getElementById(id);
target.dispatchEvent(new MouseEvent('click'));
// Block mainthread in the callback, as dispatchEvent() is an sync call.
resolve();
});
}
function trustedFocusAndBlockMain(id) {
return new Promise((resolve, reject) => {
const target = document.getElementById(id);
trustedFocusStart = performance.now();
target.focus();
// Block mainthread in the callback, as focus() is an sync call.
resolve();
});
}
async_test(function(t) {
new PerformanceObserver(entryList => {
const observerCallbackTime = performance.now();
const entries = entryList.getEntries();
t.step(()=>{
assert_equals(entries.length, 1,
"Observe more than one entries: " +
JSON.stringify(entries) + ".");
assert_equals(entries[0].name, 'click',
"The observed entry should be a click");
assert_greater_than(observerCallbackTime, entries[0].startTime,
"assert(untrustedClickStart > entries[0].startTime) failed");
assert_greater_than(entries[0].startTime, trustedClickStart,
"assert(entries[0].startTime > trustedClickStart) failed");
});
t.done();
}).observe({ entryTypes: ['event'] });
// untrusted event of a type event timing cares about
untrustedClickAndBlockMain('button').then(wait);
// trusted event of a type event timing doesn't cares about
trustedFocusAndBlockMain('button').then(wait);
// trusted event of a type event timing cares about
trustedClickAndBlockMain('button').then(wait);
}, "Event Timing only times certain types of trusted event.");
</script>
</html>
......@@ -216,6 +216,10 @@ bool Event::IsDragEvent() const {
return false;
}
bool Event::IsCompositionEvent() const {
return false;
}
bool Event::IsClipboardEvent() const {
return false;
}
......
......@@ -179,6 +179,7 @@ class CORE_EXPORT Event : public ScriptWrappable {
virtual bool IsRelatedEvent() const;
virtual bool IsPointerEvent() const;
virtual bool IsInputEvent() const;
virtual bool IsCompositionEvent() const;
// Drag events are a subset of mouse events.
virtual bool IsDragEvent() const;
......
......@@ -72,6 +72,10 @@ const AtomicString& CompositionEvent::InterfaceName() const {
return EventNames::CompositionEvent;
}
bool CompositionEvent::IsCompositionEvent() const {
return true;
}
void CompositionEvent::Trace(blink::Visitor* visitor) {
UIEvent::Trace(visitor);
}
......
......@@ -61,6 +61,8 @@ class CompositionEvent final : public UIEvent {
const AtomicString& InterfaceName() const override;
bool IsCompositionEvent() const override;
void Trace(blink::Visitor*) override;
private:
......
......@@ -22,10 +22,18 @@ EventTiming::EventTiming(LocalDOMWindow* window) {
performance_ = DOMWindowPerformance::performance(*window);
}
bool EventTiming::ShouldReportForEventTiming(const Event* event) const {
return (event->IsMouseEvent() || event->IsPointerEvent() ||
event->IsTouchEvent() || event->IsKeyboardEvent() ||
event->IsWheelEvent() || event->IsInputEvent() ||
event->IsCompositionEvent()) &&
event->isTrusted();
}
void EventTiming::WillDispatchEvent(const Event* event) {
// Assume each event can be dispatched only once.
DCHECK(!finished_will_dispatch_event_);
if (!performance_ || !event->isTrusted())
if (!performance_ || !ShouldReportForEventTiming(event))
return;
// Although we screen the events for timing by setting these conditions here,
......
......@@ -26,6 +26,7 @@ class CORE_EXPORT EventTiming final {
void DidDispatchEvent(const Event*);
private:
bool ShouldReportForEventTiming(const Event* event) const;
// The time the first event handler or default action started to execute.
TimeTicks processing_start_;
bool finished_will_dispatch_event_ = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment