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;
MouseEvent::~MouseEvent() {}
TouchEvent::TouchEvent() : TouchEvent(kPause, 0, 0) {}
TouchEvent::TouchEvent(TouchEventType type, int x, int y)
: type(type),
x(x),
......
......@@ -67,6 +67,7 @@ enum TouchEventType {
};
struct TouchEvent {
TouchEvent();
TouchEvent(TouchEventType type,
int x,
int y);
......
......@@ -614,23 +614,43 @@ Status WebViewImpl::DispatchTouchEventWithMultiPoints(
return Status(kOk);
base::DictionaryValue params;
std::unique_ptr<base::ListValue> point_list(new base::ListValue);
Status status(kOk);
for (auto it = events.begin(); it != events.end(); ++it) {
std::string type = GetAsString(it->type);
if (!type.empty())
params.SetString("type", type);
size_t touch_count = 1;
for (const TouchEvent& event : events) {
std::unique_ptr<base::ListValue> point_list(new base::ListValue);
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") {
std::unique_ptr<base::DictionaryValue> point = GenerateTouchPoint(*it);
point_list->Append(std::move(point));
point_list->Append(GenerateTouchPoint(event));
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));
if (async_dispatch_events) {
status = client_->SendCommandAndIgnoreResponse("Input.dispatchTouchEvent",
params);
} else {
status = client_->SendCommand("Input.dispatchTouchEvent", params);
params.Set("touchPoints", std::move(point_list));
if (async_dispatch_events || touch_count < events.size()) {
status = client_->SendCommandAndIgnoreResponse("Input.dispatchTouchEvent",
params);
} else {
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);
}
......
......@@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/containers/flat_map.h"
#include "chrome/test/chromedriver/chrome/web_view.h"
namespace base {
......@@ -214,6 +215,7 @@ class WebViewImpl : public WebView {
std::unique_ptr<HeapSnapshotTaker> heap_snapshot_taker_;
std::unique_ptr<DebuggerTracker> debugger_;
std::unique_ptr<CastTracker> cast_tracker_;
base::flat_map<int, TouchEvent> touch_points_;
};
// 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