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