Commit 4f6da930 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Rewrite hr-timestamp/input-events.html to a browser test

hr-timestamp/input-events.htmlEvent timestamp tests that the received
events on the page should be equal to the timestamp provided by the
eventSender's recorded last event. But we should deprecate eventSender in
the future, and GpuBenchmarking sends events based on the current system
time, which cannot be equal to the received events' timestamp.


Bug: 1047176
Change-Id: I225dec07b1928ae254d61e8a8384ebfc7dab75e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2173421
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Reviewed-by: default avatarMajid Valipour <majidvp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790868}
parent 6f8564e7
This diff is collapsed.
......@@ -134,7 +134,7 @@ void SyntheticGestureTargetAura::DispatchWebGestureEventToPlatform(
: ui::EventMomentumPhase::END;
ui::ScrollEvent scroll_event(event_type, web_gesture.PositionInWidget(),
web_gesture.PositionInWidget(),
ui::EventTimeForNow(), flags,
web_gesture.TimeStamp(), flags,
web_gesture.data.fling_start.velocity_x,
web_gesture.data.fling_start.velocity_y, 0, 0, 2,
momentum_phase, ui::ScrollEventPhase::kNone);
......@@ -157,8 +157,8 @@ void SyntheticGestureTargetAura::DispatchWebMouseEventToPlatform(
}
ui::MouseEvent mouse_event(event_type, web_mouse_event.PositionInWidget(),
web_mouse_event.PositionInWidget(),
ui::EventTimeForNow(), flags, changed_button_flags,
pointer_details);
web_mouse_event.TimeStamp(), flags,
changed_button_flags, pointer_details);
aura::Window* window = GetWindow();
mouse_event.ConvertLocationToTarget(window, window->GetRootWindow());
......
......@@ -1036,6 +1036,7 @@ test("content_browsertests") {
"../browser/renderer_host/input/compositor_event_ack_browsertest.cc",
"../browser/renderer_host/input/event_latency_aura_browsertest.cc",
"../browser/renderer_host/input/fling_browsertest.cc",
"../browser/renderer_host/input/input_event_browsertest.cc",
"../browser/renderer_host/input/interaction_mq_dynamic_browsertest.cc",
"../browser/renderer_host/input/main_thread_event_queue_browsertest.cc",
"../browser/renderer_host/input/mouse_latency_browsertest.cc",
......
......@@ -90,6 +90,16 @@ base::TimeDelta DocumentLoadTiming::MonotonicTimeToPseudoWallTime(
return monotonic_time + reference_wall_time_ - reference_monotonic_time_;
}
int64_t DocumentLoadTiming::ZeroBasedDocumentTimeToMonotonicTime(
double dom_event_time) const {
if (reference_monotonic_time_.is_null())
return 0;
base::TimeTicks monotonic_time =
reference_monotonic_time_ +
base::TimeDelta::FromMillisecondsD(dom_event_time);
return monotonic_time.since_origin().InMilliseconds();
}
void DocumentLoadTiming::MarkNavigationStart() {
// Allow the embedder to override navigationStart before we record it if
// they have a more accurate timestamp.
......
......@@ -50,6 +50,7 @@ class CORE_EXPORT DocumentLoadTiming final {
base::TimeDelta MonotonicTimeToZeroBasedDocumentTime(base::TimeTicks) const;
base::TimeDelta MonotonicTimeToPseudoWallTime(base::TimeTicks) const;
int64_t ZeroBasedDocumentTimeToMonotonicTime(double dom_event_time) const;
void MarkNavigationStart();
void SetNavigationStart(base::TimeTicks);
......
......@@ -3317,6 +3317,11 @@ double Internals::monotonicTimeToZeroBasedDocumentTime(
.InSecondsF();
}
int64_t Internals::zeroBasedDocumentTimeToMonotonicTime(double dom_event_time) {
return document_->Loader()->GetTiming().ZeroBasedDocumentTimeToMonotonicTime(
dom_event_time);
}
int64_t Internals::currentTimeTicks() {
return base::TimeTicks::Now().since_origin().InMicroseconds();
}
......
......@@ -543,6 +543,10 @@ class Internals final : public ScriptWrappable {
// document time in seconds
double monotonicTimeToZeroBasedDocumentTime(double, ExceptionState&);
// Translate an event's DOMHighResTimeStamp in seconds into a monotonic time
// in milliseconds.
int64_t zeroBasedDocumentTimeToMonotonicTime(double dom_event_time);
// Returns the current time ticks (in microseconds).
int64_t currentTimeTicks();
......
......@@ -366,6 +366,11 @@
boolean setScrollbarVisibilityInScrollableArea(Node node, boolean visible);
[RaisesException] double monotonicTimeToZeroBasedDocumentTime(double platformTime);
// Translate an event's DOMHighResTimeStamp in seconds into a monotonic time
// in milliseconds.
long long zeroBasedDocumentTimeToMonotonicTime(double domHighResTimeStamp);
long long currentTimeTicks();
DOMString getScrollAnimationState(Node node);
......
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script type="text/javascript">
'use strict';
const testCases = {
'mousedown': () => eventSender.mouseDown(),
'keydown': () => eventSender.keyDown('x'),
'touchstart': () => {
eventSender.addTouchPoint(1, 1);
eventSender.touchStart();
},
'click': () => eventSender.gestureTap(1, 1),
'wheel': () => eventSender.mouseScrollBy(0, -50),
};
let receivedEvents = [];
for (let eventName in testCases)
createTest(eventName, testCases[eventName]);
function createTest(eventName, dispatchEventFn) {
async_test(function(t) {
document.addEventListener(eventName, t.step_func(function(e) {
receivedEvents.push(eventName);
// Prevent default to ensure contextmenu is not shown which can
// potentially hijack other events.
e.preventDefault();
const platformTimestamp = eventSender.lastEventTimestamp(); // in seconds
const expectedUnclampedTimestamp = internals.monotonicTimeToZeroBasedDocumentTime(platformTimestamp) * 1000; // in milliseconds
// Time clamping logic in Blink can introduce at most 2*100us of
// difference. Use 0.200001 instead of 0.2 to deal with floating
// point comparison issues.
assert_approx_equals(e.timeStamp, expectedUnclampedTimestamp, 0.200001);
t.done();
}));
dispatchEventFn();
t.step_timeout(function() {
assert_unreached("timeout with received events: " + receivedEvents.join(', '));
}, 5000);
}, "Event timestamp should be equal to the timestamp provided by the platform for " + eventName);
}
</script>
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