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

[Chromedriver] Add triple click tests in Chromedriver

When we are using Chromedriver ExecutePerformActions to simulate
three mouse click, it should set the mouse click count to 3, but if we
keep clicking, the click count should keep increasing on Windows and
Mac, reset to 1 otherwise. It should keep the mouse click count and
decide if we should increase the count or set to 1 when we have a mouse
press based on the interval of two mouse presses and difference between
the current mouse positions and the last one. I added three more tests
to verify these cases.

Bug: 1119679
Change-Id: I6f628e625e680870a77e18495eb0b4fab024fbbc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508987Reviewed-by: default avatarShengfa Lin <shengfa@google.com>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823399}
parent 97652c2a
...@@ -977,6 +977,85 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer): ...@@ -977,6 +977,85 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
self._driver.PerformActions(actions) self._driver.PerformActions(actions)
self.assertEquals(1, len(self._driver.FindElements('tag name', 'br'))) self.assertEquals(1, len(self._driver.FindElements('tag name', 'br')))
def testActionsMouseTripleClick(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'window.click_counts = [];'
'div.addEventListener("click", event => {'
' window.click_counts.push(event.detail);'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
click_counts = self._driver.ExecuteScript('return window.click_counts')
self.assertEquals(3, len(click_counts))
self.assertEquals(1, click_counts[0])
self.assertEquals(2, click_counts[1])
self.assertEquals(3, click_counts[2])
def testActionsMouseResetCountOnOtherButton(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'div.addEventListener("dblclick", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerDown", "button": 1},
{"type": "pointerUp", "button": 1}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
self.assertEquals(0, len(self._driver.FindElements('tag name', 'br')))
def testActionsMouseResetCountOnMove(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/empty.html'))
self._driver.ExecuteScript(
'document.body.innerHTML = "<div>old</div>";'
'var div = document.getElementsByTagName("div")[0];'
'div.style["width"] = "100px";'
'div.style["height"] = "100px";'
'div.addEventListener("dblclick", function() {'
' var div = document.getElementsByTagName("div")[0];'
' div.innerHTML="new<br>";'
'});'
'return div;')
actions = ({"actions": [{
"type":"pointer",
"actions":[{"type": "pointerMove", "x": 10, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0},
{"type": "pointerMove", "x": 30, "y": 10},
{"type": "pointerDown", "button": 0},
{"type": "pointerUp", "button": 0}],
"parameters": {"pointerType": "mouse"},
"id": "pointer1"}]})
self._driver.PerformActions(actions)
self.assertEquals(0, len(self._driver.FindElements('tag name', 'br')))
def testActionsMouseDrag(self): def testActionsMouseDrag(self):
self._driver.Load(self.GetHttpUrlForFile('/chromedriver/drag.html')) self._driver.Load(self.GetHttpUrlForFile('/chromedriver/drag.html'))
target = self._driver.FindElement('css selector', '#target') target = self._driver.FindElement('css selector', '#target')
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h"
#include "chrome/test/chromedriver/basic_types.h" #include "chrome/test/chromedriver/basic_types.h"
#include "chrome/test/chromedriver/chrome/browser_info.h" #include "chrome/test/chromedriver/chrome/browser_info.h"
#include "chrome/test/chromedriver/chrome/chrome.h" #include "chrome/test/chromedriver/chrome/chrome.h"
...@@ -417,17 +418,18 @@ Status ElementInViewCenter(Session* session, ...@@ -417,17 +418,18 @@ Status ElementInViewCenter(Session* session,
return Status(kOk); return Status(kOk);
} }
int GetMouseClickCount(float x, int GetMouseClickCount(int last_click_count,
float x,
float y, float y,
float last_x, float last_x,
float last_y, float last_y,
int click_count, int button_id,
int last_button_id,
const base::TimeTicks& timestamp, const base::TimeTicks& timestamp,
const base::TimeTicks& last_mouse_click_time) { const base::TimeTicks& last_mouse_click_time) {
const int kDoubleClickTimeMS = 500; const int kDoubleClickTimeMS = 500;
const int kDoubleClickRange = 4; const int kDoubleClickRange = 4;
if (last_click_count == 0)
if (click_count == 0)
return 1; return 1;
base::TimeDelta time_difference = timestamp - last_mouse_click_time; base::TimeDelta time_difference = timestamp - last_mouse_click_time;
...@@ -440,7 +442,16 @@ int GetMouseClickCount(float x, ...@@ -440,7 +442,16 @@ int GetMouseClickCount(float x,
if (std::abs(y - last_y) > kDoubleClickRange / 2) if (std::abs(y - last_y) > kDoubleClickRange / 2)
return 1; return 1;
return click_count + 1; if (last_button_id != button_id)
return 1;
#if !defined(OS_MAC) && !defined(OS_WIN)
// On Mac and Windows, we keep increasing the click count, but on the other
// platforms, we reset the count to 1 when it is greater than 3.
if (last_click_count >= 3)
return 1;
#endif
return last_click_count + 1;
} }
const char kLandscape[] = "landscape"; const char kLandscape[] = "landscape";
...@@ -1549,6 +1560,7 @@ Status ExecutePerformActions(Session* session, ...@@ -1549,6 +1560,7 @@ Status ExecutePerformActions(Session* session,
std::map<std::string, gfx::Point> action_locations; std::map<std::string, gfx::Point> action_locations;
std::map<std::string, bool> has_touch_start; std::map<std::string, bool> has_touch_start;
std::map<std::string, int> buttons; std::map<std::string, int> buttons;
std::map<std::string, int> last_pressed_buttons;
std::map<std::string, std::string> button_type; std::map<std::string, std::string> button_type;
int viewport_width = 0, viewport_height = 0; int viewport_width = 0, viewport_height = 0;
int init_x = 0, init_y = 0; int init_x = 0, init_y = 0;
...@@ -1619,10 +1631,12 @@ Status ExecutePerformActions(Session* session, ...@@ -1619,10 +1631,12 @@ Status ExecutePerformActions(Session* session,
std::string pointer_type; std::string pointer_type;
action->GetString("pointerType", &pointer_type); action->GetString("pointerType", &pointer_type);
if (pointer_type == "mouse" || pointer_type == "pen") if (pointer_type == "mouse" || pointer_type == "pen") {
buttons[id] = input_state->FindKey("pressed")->GetInt(); buttons[id] = input_state->FindKey("pressed")->GetInt();
else if (pointer_type == "touch") last_pressed_buttons[id] = buttons[id];
} else if (pointer_type == "touch") {
has_touch_start[id] = false; has_touch_start[id] = false;
}
} }
} }
...@@ -1719,6 +1733,8 @@ Status ExecutePerformActions(Session* session, ...@@ -1719,6 +1733,8 @@ Status ExecutePerformActions(Session* session,
event.delta_x = delta_x; event.delta_x = delta_x;
event.delta_y = delta_y; event.delta_y = delta_y;
buttons[id] |= StringToModifierMouseButton(button_type[id]); buttons[id] |= StringToModifierMouseButton(button_type[id]);
last_pressed_buttons[id] =
StringToModifierMouseButton(button_type[id]);
session->mouse_position = WebPoint(event.x, event.y); session->mouse_position = WebPoint(event.x, event.y);
dispatch_wheel_events.push_back(event); dispatch_wheel_events.push_back(event);
Status status = web_view->DispatchMouseEvents( Status status = web_view->DispatchMouseEvents(
...@@ -1771,10 +1787,14 @@ Status ExecutePerformActions(Session* session, ...@@ -1771,10 +1787,14 @@ Status ExecutePerformActions(Session* session,
if (event.type == kPressedMouseEventType) { if (event.type == kPressedMouseEventType) {
base::TimeTicks timestamp = base::TimeTicks::Now(); base::TimeTicks timestamp = base::TimeTicks::Now();
event.click_count = GetMouseClickCount( event.click_count = GetMouseClickCount(
event.x, event.y, session->mouse_position.x, session->click_count, event.x, event.y,
session->mouse_position.y, session->click_count, session->mouse_position.x, session->mouse_position.y,
timestamp, session->mouse_click_timestamp); StringToModifierMouseButton(button_type[id]),
last_pressed_buttons[id], timestamp,
session->mouse_click_timestamp);
buttons[id] |= StringToModifierMouseButton(button_type[id]); buttons[id] |= StringToModifierMouseButton(button_type[id]);
last_pressed_buttons[id] =
StringToModifierMouseButton(button_type[id]);
session->mouse_position = WebPoint(event.x, event.y); session->mouse_position = WebPoint(event.x, event.y);
session->click_count = event.click_count; session->click_count = event.click_count;
session->mouse_click_timestamp = timestamp; session->mouse_click_timestamp = timestamp;
...@@ -1793,8 +1813,8 @@ Status ExecutePerformActions(Session* session, ...@@ -1793,8 +1813,8 @@ Status ExecutePerformActions(Session* session,
action_input_states[j]->FindKey("pressed")->GetInt() & action_input_states[j]->FindKey("pressed")->GetInt() &
~(1 << event.button)); ~(1 << event.button));
} else if (event.type == kMovedMouseEventType) { } else if (event.type == kMovedMouseEventType) {
if (!(action_input_states[j]->FindKey("pressed")->GetInt() | if (action_input_states[j]->FindKey("pressed")->GetInt() ==
(1 << event.button))) { 0) {
pressure = 0; pressure = 0;
} }
} }
......
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