Skip to content

Commit

Permalink
Updating reset action for IE driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jul 10, 2018
1 parent 94678f7 commit 1eaa2d7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 66 deletions.
113 changes: 51 additions & 62 deletions cpp/iedriver/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#define MODIFIER_KEY_CTRL 2
#define MODIFIER_KEY_ALT 4

// "Key" values for mouse buttons
#define WD_MOUSE_LBUTTON 0xE05EU
#define WD_MOUSE_RBUTTON 0xE05FU

namespace webdriver {

InputManager::InputManager() {
Expand Down Expand Up @@ -255,81 +259,52 @@ InputState InputManager::CloneCurrentInputState(void) {

void InputManager::Reset(BrowserHandle browser_wrapper) {
LOG(TRACE) << "Entering InputManager::Reset";
Json::Value reset_sequence(Json::arrayValue);

Json::Value mouse_input_source;
mouse_input_source["type"] = "pointer";
mouse_input_source["id"] = "default mouse";
Json::Value mouse_parameters;
mouse_parameters["pointerType"] = "mouse";
mouse_input_source["parameters"] = mouse_parameters;
mouse_input_source["actions"] = Json::Value(Json::arrayValue);

if (this->current_input_state_.is_left_button_pressed ||
this->current_input_state_.is_right_button_pressed) {
if (this->current_input_state_.is_left_button_pressed) {
LOG(DEBUG) << "Releasing left mouse button";
Json::Value left_button_up;
left_button_up["type"] = "pointerUp";
left_button_up["button"] = WD_CLIENT_LEFT_MOUSE_BUTTON;
mouse_input_source["actions"].append(left_button_up);
}

if (this->current_input_state_.is_right_button_pressed) {
LOG(DEBUG) << "Releasing right mouse button";
Json::Value right_button_up;
right_button_up["type"] = "pointerUp";
right_button_up["button"] = WD_CLIENT_RIGHT_MOUSE_BUTTON;
mouse_input_source["actions"].append(right_button_up);
LOG(DEBUG) << "Releasing " << this->pressed_keys_.size() << " keys";
std::vector<wchar_t> local_pressed_keys(this->pressed_keys_);

HWND browser_window_handle = browser_wrapper->GetContentWindowHandle();
InputState current_input_state = this->CloneCurrentInputState();
this->inputs_.clear();
std::vector<wchar_t>::const_reverse_iterator it = local_pressed_keys.rbegin();
for (; it != local_pressed_keys.rend(); ++it) {
std::wstring key_value = L"";
key_value.append(1, *it);
std::wstring key_description = this->GetKeyDescription(*it);
LOG(DEBUG) << "Key: " << LOGWSTRING(key_description);
if (*it == WD_MOUSE_LBUTTON) {
this->AddMouseInput(browser_window_handle, MOUSEEVENTF_LEFTUP, 0, 0);
} else if (*it == WD_MOUSE_RBUTTON) {
this->AddMouseInput(browser_window_handle, MOUSEEVENTF_RIGHTUP, 0, 0);
} else {
this->AddKeyboardInput(browser_window_handle,
key_value,
true,
&current_input_state);
}
}

Json::Value keyboard_input_source;
keyboard_input_source["type"] = "key";
keyboard_input_source["id"] = "default keyboard";
keyboard_input_source["actions"] = Json::Value(Json::arrayValue);

if (this->pressed_keys_.size() > 0) {
for (size_t i = 0; i < mouse_input_source["actions"].size(); ++i) {
Json::Value pause_action;
pause_action["type"] = "pause";
pause_action["duration"] = 0;
keyboard_input_source["actions"].append(pause_action);
}

LOG(DEBUG) << "Releasing " << this->pressed_keys_.size() << " keys";
std::vector<wchar_t>::const_reverse_iterator it = this->pressed_keys_.rbegin();
for (; it != this->pressed_keys_.rend(); ++it) {
std::wstring key_value = L"";
key_value.append(1, *it);
std::wstring key_description= this->GetKeyDescription(*it);
LOG(DEBUG) << "Key: " << LOGWSTRING(key_description);
Json::Value keyup;
keyup["type"] = "keyUp";
keyup["value"] = StringUtilities::ToString(key_value);
keyboard_input_source["actions"].append(keyup);
}
this->pressed_keys_.clear();
// If there are inputs in the array, then we've queued up input actions
// to be played back. So play them back.
if (this->inputs_.size() > 0) {
LOG(DEBUG) << "Processing a total of " << this->inputs_.size() << " input events";
this->action_simulator_->SimulateActions(browser_wrapper,
this->inputs_,
&this->current_input_state_);
}

::Sleep(50);

if (this->current_input_state_.mouse_x > 0 ||
this->current_input_state_.mouse_y > 0) {
LOG(DEBUG) << "Resetting mouse position";
this->current_input_state_.mouse_x = 0;
this->current_input_state_.mouse_y = 0;
}

if (mouse_input_source["actions"].size() > 0) {
reset_sequence.append(mouse_input_source);
}

if (keyboard_input_source["actions"].size() > 0) {
reset_sequence.append(keyboard_input_source);
}

if (reset_sequence.size() > 0) {
std::string error_info = "";
this->PerformInputSequence(browser_wrapper, reset_sequence, &error_info);
if (this->pressed_keys_.size() > 0) {
LOG(WARN) << "Pressed keys should have been empty, but had " << this->pressed_keys_.size() << " values.";
this->pressed_keys_.clear();
}
}

Expand Down Expand Up @@ -657,6 +632,18 @@ void InputManager::AddMouseInput(HWND window_handle, long input_action, int x, i
mouse_input.mi.dwExtraInfo = 0;
mouse_input.mi.mouseData = 0;
mouse_input.mi.time = 0;
if (input_action == MOUSEEVENTF_LEFTDOWN) {
this->UpdatePressedKeys(WD_MOUSE_LBUTTON, true);
}
if (input_action == MOUSEEVENTF_RIGHTDOWN) {
this->UpdatePressedKeys(WD_MOUSE_RBUTTON, true);
}
if (input_action == MOUSEEVENTF_LEFTUP) {
this->UpdatePressedKeys(WD_MOUSE_LBUTTON, false);
}
if (input_action == MOUSEEVENTF_RIGHTUP) {
this->UpdatePressedKeys(WD_MOUSE_RBUTTON, false);
}
this->inputs_.push_back(mouse_input);
}

Expand Down Expand Up @@ -1364,6 +1351,8 @@ void InputManager::SetupKeyDescriptions() {
this->key_descriptions_[WD_KEY_R_DOWN] = L"ArrowDown";
this->key_descriptions_[WD_KEY_R_INSERT] = L"Insert";
this->key_descriptions_[WD_KEY_R_DELETE] = L"Delete";
this->key_descriptions_[WD_MOUSE_LBUTTON] = L"Left Mouse Button";
this->key_descriptions_[WD_MOUSE_RBUTTON] = L"Right Mouse Button";
}

} // namespace webdriver
8 changes: 4 additions & 4 deletions cpp/iedriverserver/IEDriverServer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,13,0,0
PRODUCTVERSION 3,13,0,0
FILEVERSION 3,13,0,1
PRODUCTVERSION 3,13,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -68,12 +68,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Software Freedom Conservancy"
VALUE "FileDescription", "Command line server for the IE driver"
VALUE "FileVersion", "3.13.0.0"
VALUE "FileVersion", "3.13.0.1"
VALUE "InternalName", "IEDriverServer.exe"
VALUE "LegalCopyright", "Copyright (C) 2017"
VALUE "OriginalFilename", "IEDriverServer.exe"
VALUE "ProductName", "Selenium WebDriver"
VALUE "ProductVersion", "3.13.0.0"
VALUE "ProductVersion", "3.13.0.1"
END
END
BLOCK "VarFileInfo"
Expand Down

0 comments on commit 1eaa2d7

Please sign in to comment.