Commit e9284683 authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

[ChromeDriver] Dispatch touch events with their actual timestamp

When we are handling the consequence touch move events, sometimes, we
will coalesce them together, and we need the events' timestamp to
decide to which one dispatch first. I use the actual timestamp when
the event is generated and about to dispatch in
Input.DispatchTouchEvent function.

Bug: 1020674
Change-Id: I8a56f6f532df3ca6182c323c6f8c14f4825589e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1943107Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720508}
parent ed5b20ab
...@@ -29,6 +29,8 @@ MouseEvent::MouseEvent(const MouseEvent& other) = default; ...@@ -29,6 +29,8 @@ MouseEvent::MouseEvent(const MouseEvent& other) = default;
MouseEvent::~MouseEvent() {} MouseEvent::~MouseEvent() {}
TouchEvent::TouchEvent() : TouchEvent(kPause, 0, 0) {}
TouchEvent::TouchEvent(TouchEventType type, int x, int y) TouchEvent::TouchEvent(TouchEventType type, int x, int y)
: type(type), : type(type),
x(x), x(x),
......
...@@ -67,6 +67,7 @@ enum TouchEventType { ...@@ -67,6 +67,7 @@ enum TouchEventType {
}; };
struct TouchEvent { struct TouchEvent {
TouchEvent();
TouchEvent(TouchEventType type, TouchEvent(TouchEventType type,
int x, int x,
int y); int y);
......
...@@ -614,23 +614,43 @@ Status WebViewImpl::DispatchTouchEventWithMultiPoints( ...@@ -614,23 +614,43 @@ Status WebViewImpl::DispatchTouchEventWithMultiPoints(
return Status(kOk); return Status(kOk);
base::DictionaryValue params; base::DictionaryValue params;
std::unique_ptr<base::ListValue> point_list(new base::ListValue);
Status status(kOk); Status status(kOk);
for (auto it = events.begin(); it != events.end(); ++it) { size_t touch_count = 1;
std::string type = GetAsString(it->type); for (const TouchEvent& event : events) {
if (!type.empty()) std::unique_ptr<base::ListValue> point_list(new base::ListValue);
params.SetString("type", type); int32_t current_time =
(base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds();
params.SetInteger("timestamp", current_time);
std::string type = GetAsString(event.type);
params.SetString("type", type);
if (type == "touchStart" || type == "touchMove") { if (type == "touchStart" || type == "touchMove") {
std::unique_ptr<base::DictionaryValue> point = GenerateTouchPoint(*it); point_list->Append(GenerateTouchPoint(event));
point_list->Append(std::move(point)); for (auto point = touch_points_.begin(); point != touch_points_.end();
++point) {
if (point->first != event.id) {
point_list->Append(GenerateTouchPoint(point->second));
}
}
touch_points_[event.id] = event;
} }
} params.Set("touchPoints", std::move(point_list));
params.Set("touchPoints", std::move(point_list));
if (async_dispatch_events) { if (async_dispatch_events || touch_count < events.size()) {
status = client_->SendCommandAndIgnoreResponse("Input.dispatchTouchEvent", status = client_->SendCommandAndIgnoreResponse("Input.dispatchTouchEvent",
params); params);
} else { } else {
status = client_->SendCommand("Input.dispatchTouchEvent", params); status = client_->SendCommand("Input.dispatchTouchEvent", params);
}
if (status.IsError())
return status;
if (type != "touchStart" && type != "touchMove") {
for (auto point = touch_points_.begin(); point != touch_points_.end();) {
point = touch_points_.erase(point);
}
break;
}
touch_count++;
} }
return Status(kOk); return Status(kOk);
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/containers/flat_map.h"
#include "chrome/test/chromedriver/chrome/web_view.h" #include "chrome/test/chromedriver/chrome/web_view.h"
namespace base { namespace base {
...@@ -214,6 +215,7 @@ class WebViewImpl : public WebView { ...@@ -214,6 +215,7 @@ class WebViewImpl : public WebView {
std::unique_ptr<HeapSnapshotTaker> heap_snapshot_taker_; std::unique_ptr<HeapSnapshotTaker> heap_snapshot_taker_;
std::unique_ptr<DebuggerTracker> debugger_; std::unique_ptr<DebuggerTracker> debugger_;
std::unique_ptr<CastTracker> cast_tracker_; std::unique_ptr<CastTracker> cast_tracker_;
base::flat_map<int, TouchEvent> touch_points_;
}; };
// Responsible for locking a WebViewImpl and its associated data structure to // Responsible for locking a WebViewImpl and its associated data structure to
......
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