Commit e4e4440f authored by Joel Einbinder's avatar Joel Einbinder Committed by Commit Bot

ChromeDriver: Convert mouse events into touch events

This patch uses Input.dispatchTouchEvent instead of
Emulation.setEmitTouchEventsForMouse. This gives more predictable
behavior and allows for each touch event to be awaited.

Bug: chromedriver:2144
Change-Id: Ic243c216e2f832844a64f8f2af894eb6cc4234d1
Reviewed-on: https://chromium-review.googlesource.com/1182506
Commit-Queue: Joel Einbinder <einbinder@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584904}
parent 7b57f349
......@@ -68,22 +68,6 @@ Status MobileEmulationOverrideManager::ApplyOverrideIfNeeded() {
if (status.IsError())
return status;
#if 0 // Temporarily disabled due to https://crbug.com/chromedriver/2144
base::DictionaryValue emit_touch_for_mouse_params;
emit_touch_for_mouse_params.SetBoolean("enabled", true);
emit_touch_for_mouse_params.SetString("configuration", "mobile");
status = client_->SendCommand("Emulation.setEmitTouchEventsForMouse",
emit_touch_for_mouse_params);
// OK if Emulation.setEmitTouchEventsForMouse isn't available, as it was
// added in Chrome v62. TODO(johnchen@chromium.org): Remove check for
// Emulation.setEmitTouchEventsForMouse not found error when ChromeDriver
// stops supporting v61.
if (status.IsError() &&
status.message().find(
"'Emulation.setEmitTouchEventsForMouse' wasn't found") ==
std::string::npos)
return status;
#endif
}
return Status(kOk);
......
......@@ -401,8 +401,57 @@ Status WebViewImpl::GetFrameByFunction(const std::string& frame,
return dom_tracker_->GetFrameIdForNode(node_id, out_frame);
}
Status WebViewImpl::DispatchTouchEventsForMouseEvents(
const std::list<MouseEvent>& events,
const std::string& frame) {
// Touch events are filtered by the compositor if there are no touch listeners
// on the page. Wait two frames for the compositor to sync with the main
// thread to get consistent behavior.
base::DictionaryValue params;
params.SetString("expression",
"new Promise(x => setTimeout(() => setTimeout(x, 20), 20)");
params.SetBoolean("awaitPromise", true);
client_->SendCommand("Runtime.evaluate", params);
for (std::list<MouseEvent>::const_iterator it = events.begin();
it != events.end(); ++it) {
base::DictionaryValue params;
switch (it->type) {
case kPressedMouseEventType:
params.SetString("type", "touchStart");
break;
case kReleasedMouseEventType:
params.SetString("type", "touchEnd");
break;
case kMovedMouseEventType:
if (it->button == kNoneMouseButton)
continue;
params.SetString("type", "touchMove");
break;
}
std::unique_ptr<base::ListValue> touchPoints(new base::ListValue);
if (it->type != kReleasedMouseEventType) {
std::unique_ptr<base::DictionaryValue> touchPoint(
new base::DictionaryValue);
touchPoint->SetInteger("x", it->x);
touchPoint->SetInteger("y", it->y);
touchPoints->Append(std::move(touchPoint));
}
params.SetList("touchPoints", std::move(touchPoints));
params.SetInteger("modifiers", it->modifiers);
Status status = client_->SendCommand("Input.dispatchTouchEvent", params);
if (status.IsError())
return status;
}
return Status(kOk);
}
Status WebViewImpl::DispatchMouseEvents(const std::list<MouseEvent>& events,
const std::string& frame) {
if (mobile_emulation_override_manager_->IsEmulatingTouch())
return DispatchTouchEventsForMouseEvents(events, frame);
double page_scale_factor = 1.0;
for (std::list<MouseEvent>::const_iterator it = events.begin();
it != events.end(); ++it) {
......
......@@ -154,6 +154,8 @@ class WebViewImpl : public WebView {
Status InitProfileInternal();
Status StopProfileInternal();
Status DispatchTouchEventsForMouseEvents(const std::list<MouseEvent>& events,
const std::string& frame);
std::string id_;
bool w3c_compliant_;
......
......@@ -88,10 +88,6 @@ _NEGATIVE_FILTER = [
'ChromeDriverTest.testHoverOverElement',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=833
'ChromeDriverTest.testAlertOnNewWindow',
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=2144
'MobileEmulationCapabilityTest.testClickElement',
'MobileEmulationCapabilityTest.testNetworkConnectionTypeIsAppliedToAllTabs',
'MobileEmulationCapabilityTest.testNetworkConnectionTypeIsAppliedToAllTabsImmediately',
]
_VERSION_SPECIFIC_FILTER = {}
......
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