Commit 432b256b authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

[ChromeDriver] Refactor ExecutePerformActions function

In ExecutePerformActions function, we dispatch key events first, mouse
events then touch events, but we should dispatch whatever actions come
first in the action sequence. This CL changes high level of structures
of processing actions and dispatching events in the action sequence,
and I still need to refactor some details when procession the actions
in a following CL.

Bug: 606367
Change-Id: I46e02e547d0e5d5c2ddcdc949efc6b141142ea2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1759855Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Lan Wei <lanwei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688692}
parent d634937a
......@@ -23,8 +23,6 @@ MouseEvent::MouseEvent(MouseEventType type,
modifiers(modifiers),
buttons(buttons),
click_count(click_count),
origin(kViewPort),
element_id(std::string()),
pointer_type(kMouse) {}
MouseEvent::MouseEvent(const MouseEvent& other) = default;
......@@ -35,13 +33,11 @@ TouchEvent::TouchEvent(TouchEventType type, int x, int y)
: type(type),
x(x),
y(y),
origin(kViewPort),
radiusX(1.0),
radiusY(1.0),
rotationAngle(0.0),
force(1.0),
id(0),
element_id(std::string()),
dispatch(true) {}
TouchEvent::TouchEvent(const TouchEvent& other) = default;
......
......@@ -54,8 +54,6 @@ struct MouseEvent {
int buttons;
// |click_count| should not be negative.
int click_count;
OriginType origin;
std::string element_id;
PointerType pointer_type;
};
......@@ -78,13 +76,11 @@ struct TouchEvent {
TouchEventType type;
int x;
int y;
OriginType origin;
double radiusX;
double radiusY;
double rotationAngle;
double force;
int id;
std::string element_id;
bool dispatch;
};
......
......@@ -617,7 +617,7 @@ Status ConvertKeysToKeyEvents(const base::string16& client_keys,
Status ConvertKeyActionToKeyEvent(const base::DictionaryValue* action_object,
base::DictionaryValue* input_state,
bool is_key_down,
std::vector<KeyEvent>* key_events) {
std::list<KeyEvent>* key_events) {
std::string raw_key;
if (!action_object->GetString("value", &raw_key))
return Status(kUnknownError, "missing 'value'");
......
......@@ -28,6 +28,6 @@ Status ConvertKeysToKeyEvents(const base::string16& keys,
Status ConvertKeyActionToKeyEvent(const base::DictionaryValue* action_object,
base::DictionaryValue* input_state,
bool is_key_down,
std::vector<KeyEvent>* client_key_events);
std::list<KeyEvent>* client_key_events);
#endif // CHROME_TEST_CHROMEDRIVER_KEY_CONVERTER_H_
This diff is collapsed.
......@@ -373,7 +373,7 @@ Status ExecutePerformActions(Session* session,
Status ProcessInputActionSequence(
Session* session,
const base::DictionaryValue* action_sequence,
std::unique_ptr<base::DictionaryValue>* result);
std::vector<std::unique_ptr<base::DictionaryValue>>* action_list);
Status ExecuteReleaseActions(Session* session,
WebView* web_view,
......
......@@ -66,7 +66,7 @@ TEST(WindowCommandsTest, ExecuteResume) {
TEST(WindowCommandsTest, ProcessInputActionSequencePointerMouse) {
Session session("1");
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
std::vector<std::unique_ptr<base::DictionaryValue>> action_list;
std::unique_ptr<base::DictionaryValue> action_sequence(
new base::DictionaryValue());
std::unique_ptr<base::ListValue> actions(new base::ListValue());
......@@ -94,12 +94,10 @@ TEST(WindowCommandsTest, ProcessInputActionSequencePointerMouse) {
action_sequence->SetList("actions", std::move(actions));
const base::DictionaryValue* input_action_sequence = action_sequence.get();
Status status =
ProcessInputActionSequence(&session, input_action_sequence, &result);
ProcessInputActionSequence(&session, input_action_sequence, &action_list);
ASSERT_TRUE(status.IsOk());
// check resulting action dictionary
const base::ListValue* actions_result;
const base::DictionaryValue* action_result;
std::string pointer_type;
std::string source_type;
std::string id;
......@@ -107,37 +105,49 @@ TEST(WindowCommandsTest, ProcessInputActionSequencePointerMouse) {
int x, y;
std::string button;
result->GetString("sourceType", &source_type);
result->GetString("pointerType", &pointer_type);
result->GetString("id", &id);
ASSERT_EQ(3U, action_list.size());
const base::DictionaryValue* action1 = action_list[0].get();
action1->GetString("type", &source_type);
action1->GetString("pointerType", &pointer_type);
action1->GetString("id", &id);
ASSERT_EQ("pointer", source_type);
ASSERT_EQ("mouse", pointer_type);
ASSERT_EQ("pointer1", id);
result->GetList("actions", &actions_result);
ASSERT_EQ(3U, actions_result->GetSize());
actions_result->GetDictionary(0, &action_result);
action_result->GetString("subtype", &action_type);
action_result->GetInteger("x", &x);
action_result->GetInteger("y", &y);
action1->GetString("subtype", &action_type);
action1->GetInteger("x", &x);
action1->GetInteger("y", &y);
ASSERT_EQ("pointerMove", action_type);
ASSERT_EQ(30, x);
ASSERT_EQ(60, y);
actions_result->GetDictionary(1, &action_result);
action_result->GetString("subtype", &action_type);
action_result->GetString("button", &button);
const base::DictionaryValue* action2 = action_list[1].get();
action2->GetString("type", &source_type);
action2->GetString("pointerType", &pointer_type);
action2->GetString("id", &id);
ASSERT_EQ("pointer", source_type);
ASSERT_EQ("mouse", pointer_type);
ASSERT_EQ("pointer1", id);
action2->GetString("subtype", &action_type);
action2->GetString("button", &button);
ASSERT_EQ("pointerDown", action_type);
ASSERT_EQ("left", button);
actions_result->GetDictionary(2, &action_result);
action_result->GetString("subtype", &action_type);
action_result->GetString("button", &button);
const base::DictionaryValue* action3 = action_list[2].get();
action3->GetString("type", &source_type);
action3->GetString("pointerType", &pointer_type);
action3->GetString("id", &id);
ASSERT_EQ("pointer", source_type);
ASSERT_EQ("mouse", pointer_type);
ASSERT_EQ("pointer1", id);
action3->GetString("subtype", &action_type);
action3->GetString("button", &button);
ASSERT_EQ("pointerUp", action_type);
ASSERT_EQ("left", button);
}
TEST(WindowCommandsTest, ProcessInputActionSequencePointerTouch) {
Session session("1");
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
std::vector<std::unique_ptr<base::DictionaryValue>> action_list;
std::unique_ptr<base::DictionaryValue> action_sequence(
new base::DictionaryValue());
std::unique_ptr<base::ListValue> actions(new base::ListValue());
......@@ -163,38 +173,48 @@ TEST(WindowCommandsTest, ProcessInputActionSequencePointerTouch) {
action_sequence->SetList("actions", std::move(actions));
const base::DictionaryValue* input_action_sequence = action_sequence.get();
Status status =
ProcessInputActionSequence(&session, input_action_sequence, &result);
ProcessInputActionSequence(&session, input_action_sequence, &action_list);
ASSERT_TRUE(status.IsOk());
// check resulting action dictionary
const base::ListValue* actions_result;
const base::DictionaryValue* action_result;
std::string pointer_type;
std::string source_type;
std::string id;
std::string action_type;
int x, y;
result->GetString("sourceType", &source_type);
result->GetString("pointerType", &pointer_type);
result->GetString("id", &id);
ASSERT_EQ(3U, action_list.size());
const base::DictionaryValue* action1 = action_list[0].get();
action1->GetString("type", &source_type);
action1->GetString("pointerType", &pointer_type);
action1->GetString("id", &id);
ASSERT_EQ("pointer", source_type);
ASSERT_EQ("touch", pointer_type);
ASSERT_EQ("pointer1", id);
result->GetList("actions", &actions_result);
ASSERT_EQ(3U, actions_result->GetSize());
actions_result->GetDictionary(0, &action_result);
action_result->GetString("subtype", &action_type);
action_result->GetInteger("x", &x);
action_result->GetInteger("y", &y);
action1->GetString("subtype", &action_type);
action1->GetInteger("x", &x);
action1->GetInteger("y", &y);
ASSERT_EQ("pointerMove", action_type);
ASSERT_EQ(30, x);
ASSERT_EQ(60, y);
actions_result->GetDictionary(1, &action_result);
action_result->GetString("subtype", &action_type);
const base::DictionaryValue* action2 = action_list[1].get();
action2->GetString("type", &source_type);
action2->GetString("pointerType", &pointer_type);
action2->GetString("id", &id);
ASSERT_EQ("pointer", source_type);
ASSERT_EQ("touch", pointer_type);
ASSERT_EQ("pointer1", id);
action2->GetString("subtype", &action_type);
ASSERT_EQ("pointerDown", action_type);
actions_result->GetDictionary(2, &action_result);
action_result->GetString("subtype", &action_type);
const base::DictionaryValue* action3 = action_list[2].get();
action3->GetString("type", &source_type);
action3->GetString("pointerType", &pointer_type);
action3->GetString("id", &id);
ASSERT_EQ("pointer", source_type);
ASSERT_EQ("touch", pointer_type);
ASSERT_EQ("pointer1", id);
action3->GetString("subtype", &action_type);
ASSERT_EQ("pointerUp", action_type);
}
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