Skip to content

Commit

Permalink
IE driver code cleanup - moving #defines from header files
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jan 24, 2019
1 parent cb63104 commit 269c234
Show file tree
Hide file tree
Showing 32 changed files with 148 additions and 91 deletions.
2 changes: 2 additions & 0 deletions cpp/iedriver/Alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "DocumentHost.h"
#include "StringUtilities.h"

#define INVALID_CONTROL_ID -1

namespace webdriver {

Alert::Alert(std::shared_ptr<DocumentHost> browser, HWND handle) {
Expand Down
2 changes: 0 additions & 2 deletions cpp/iedriver/Alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <string>
#include <vector>

#define INVALID_CONTROL_ID -1

namespace webdriver {

// Forward declaration of classes.
Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/AsyncScriptExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "ElementRepository.h"
#include "Script.h"
#include "StringUtilities.h"
#include "WebDriverConstants.h"

namespace webdriver {

Expand Down
2 changes: 0 additions & 2 deletions cpp/iedriver/AsyncScriptExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "messages.h"
#include "json.h"

#define ASYNC_SCRIPT_EVENT_NAME L"WD_ASYNC_SCRIPT_START_EVENT"

namespace webdriver {

// Structure to be used for comunication between threads
Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/Browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "CustomTypes.h"
#include "messages.h"
#include "StringUtilities.h"
#include "WebDriverConstants.h"

namespace webdriver {

Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/BrowserFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "FileUtilities.h"
#include "RegistryUtilities.h"
#include "StringUtilities.h"
#include "WebDriverConstants.h"

#define HTML_GETOBJECT_MSG L"WM_HTML_GETOBJECT"
#define OLEACC_LIBRARY_NAME L"OLEACC.DLL"
Expand Down
3 changes: 0 additions & 3 deletions cpp/iedriver/BrowserFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

#include <string>

#define ALERT_WINDOW_CLASS "#32770"
#define HTML_DIALOG_WINDOW_CLASS "Internet Explorer_TridentDlgFrame"

namespace webdriver {

struct ProcessWindowInfo {
Expand Down
2 changes: 0 additions & 2 deletions cpp/iedriver/CommandExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#ifndef WEBDRIVER_IE_COMMANDEXECUTOR_H_
#define WEBDRIVER_IE_COMMANDEXECUTOR_H_

#define EVENT_NAME L"WD_START_EVENT"

namespace webdriver {

// Structure to be used for comunication between threads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "../IECommandExecutor.h"
#include "../Generated/atoms.h"
#include "../Script.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "../InputManager.h"
#include "../Script.h"
#include "../StringUtilities.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "errorcodes.h"
#include "../Browser.h"
#include "../IECommandExecutor.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "errorcodes.h"
#include "../Browser.h"
#include "../IECommandExecutor.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/CommandHandlers/FindElementCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "errorcodes.h"
#include "../Browser.h"
#include "../IECommandExecutor.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "errorcodes.h"
#include "../Browser.h"
#include "../IECommandExecutor.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "../IECommandExecutor.h"
#include "../InputManager.h"
#include "../ProxyManager.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand Down
7 changes: 4 additions & 3 deletions cpp/iedriver/CommandHandlers/GetTimeoutsCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "errorcodes.h"
#include "../Browser.h"
#include "../IECommandExecutor.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand All @@ -32,9 +33,9 @@ void GetTimeoutsCommandHandler::ExecuteInternal(
const ParametersMap& command_parameters,
Response* response) {
Json::Value response_value;
response_value["implicit"] = executor.implicit_wait_timeout();
response_value["script"] = executor.async_script_timeout();
response_value["pageLoad"] = executor.page_load_timeout();
response_value[IMPLICIT_WAIT_TIMEOUT_NAME] = executor.implicit_wait_timeout();
response_value[SCRIPT_TIMEOUT_NAME] = executor.async_script_timeout();
response_value[PAGE_LOAD_TIMEOUT_NAME] = executor.page_load_timeout();
response->SetSuccessResponse(response_value);
}

Expand Down
25 changes: 13 additions & 12 deletions cpp/iedriver/CommandHandlers/NewSessionCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../IECommandExecutor.h"
#include "../InputManager.h"
#include "../ProxyManager.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand Down Expand Up @@ -348,14 +349,14 @@ Json::Value NewSessionCommandHandler::ProcessCapabilities(const IECommandExecuto
void NewSessionCommandHandler::SetTimeoutSettings(const IECommandExecutor& executor, const Json::Value& capabilities) {
LOG(TRACE) << "Entering NewSessionCommandHandler::SetTimeoutSettings";
IECommandExecutor& mutable_executor = const_cast<IECommandExecutor&>(executor);
if (capabilities.isMember("implicit")) {
mutable_executor.set_implicit_wait_timeout(capabilities["implicit"].asUInt64());
if (capabilities.isMember(IMPLICIT_WAIT_TIMEOUT_NAME)) {
mutable_executor.set_implicit_wait_timeout(capabilities[IMPLICIT_WAIT_TIMEOUT_NAME].asUInt64());
}
if (capabilities.isMember("pageLoad")) {
mutable_executor.set_page_load_timeout(capabilities["pageLoad"].asUInt64());
if (capabilities.isMember(PAGE_LOAD_TIMEOUT_NAME)) {
mutable_executor.set_page_load_timeout(capabilities[PAGE_LOAD_TIMEOUT_NAME].asUInt64());
}
if (capabilities.isMember("script")) {
mutable_executor.set_async_script_timeout(capabilities["script"].asUInt64());
if (capabilities.isMember(SCRIPT_TIMEOUT_NAME)) {
mutable_executor.set_async_script_timeout(capabilities[SCRIPT_TIMEOUT_NAME].asUInt64());
}
}

Expand Down Expand Up @@ -487,9 +488,9 @@ Json::Value NewSessionCommandHandler::CreateReturnedCapabilities(const IECommand
}

Json::Value timeouts;
timeouts["implicit"] = executor.implicit_wait_timeout();
timeouts["pageLoad"] = executor.page_load_timeout();
timeouts["script"] = executor.async_script_timeout();
timeouts[IMPLICIT_WAIT_TIMEOUT_NAME] = executor.implicit_wait_timeout();
timeouts[PAGE_LOAD_TIMEOUT_NAME] = executor.page_load_timeout();
timeouts[SCRIPT_TIMEOUT_NAME] = executor.async_script_timeout();
capabilities[TIMEOUTS_CAPABILITY] = timeouts;

Json::Value ie_options;
Expand Down Expand Up @@ -770,9 +771,9 @@ bool NewSessionCommandHandler::ValidateCapabilities(
std::vector<std::string>::const_iterator timeout_name_iterator = timeout_names.begin();
for (; timeout_name_iterator != timeout_names.end(); ++timeout_name_iterator) {
std::string timeout_name = *timeout_name_iterator;
if (timeout_name != "pageLoad" &&
timeout_name != "implicit" &&
timeout_name != "script") {
if (timeout_name != PAGE_LOAD_TIMEOUT_NAME &&
timeout_name != IMPLICIT_WAIT_TIMEOUT_NAME &&
timeout_name != SCRIPT_TIMEOUT_NAME) {
*error_message = "Invalid capabilities in " +
capability_set_name + ": " +
"a timeout named " + timeout_name +
Expand Down
20 changes: 11 additions & 9 deletions cpp/iedriver/CommandHandlers/SetTimeoutsCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "errorcodes.h"
#include "../Browser.h"
#include "../IECommandExecutor.h"
#include "../WebDriverConstants.h"

namespace webdriver {

Expand All @@ -36,27 +37,28 @@ void SetTimeoutsCommandHandler::ExecuteInternal(
ParametersMap::const_iterator timeout_parameter_iterator = command_parameters.begin();
for (; timeout_parameter_iterator != command_parameters.end(); ++timeout_parameter_iterator) {
std::string timeout_type = timeout_parameter_iterator->first;
if (timeout_type != "implicit" &&
timeout_type != "script" &&
timeout_type != "pageLoad") {
Json::Value timeout_value = timeout_parameter_iterator->second;
if (timeout_type != IMPLICIT_WAIT_TIMEOUT_NAME &&
timeout_type != SCRIPT_TIMEOUT_NAME &&
timeout_type != PAGE_LOAD_TIMEOUT_NAME) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Invalid timeout type specified: " + timeout_type);
return;
}
if (!timeout_parameter_iterator->second.isNumeric() ||
!timeout_parameter_iterator->second.isIntegral()) {
if (!timeout_value.isNumeric() ||
!timeout_value.isIntegral()) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Timeout value for timeout type " + timeout_type + " must be an integer");
return;
}
timeout = timeout_parameter_iterator->second.asInt64();
timeout = timeout_value.asInt64();
if (timeout < 0 || timeout > MAX_SAFE_INTEGER) {
response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Timeout value for timeout type " + timeout_type + " must be an integer between 0 and 2^53 - 1");
return;
}
if (timeout_type == "implicit") {
if (timeout_type == IMPLICIT_WAIT_TIMEOUT_NAME) {
mutable_executor.set_implicit_wait_timeout(timeout);
} else if (timeout_type == "script") {
} else if (timeout_type == SCRIPT_TIMEOUT_NAME) {
mutable_executor.set_async_script_timeout(timeout);
} else if (timeout_type == "pageLoad") {
} else if (timeout_type == PAGE_LOAD_TIMEOUT_NAME) {
mutable_executor.set_page_load_timeout(timeout);
}
}
Expand Down
9 changes: 0 additions & 9 deletions cpp/iedriver/CustomTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@

#include <memory>

#define IGNORE_UNEXPECTED_ALERTS "ignore"
#define ACCEPT_UNEXPECTED_ALERTS "accept"
#define DISMISS_UNEXPECTED_ALERTS "dismiss"
#define ACCEPT_AND_NOTIFY_UNEXPECTED_ALERTS "accept and notify"
#define DISMISS_AND_NOTIFY_UNEXPECTED_ALERTS "dismiss and notify"
#define NORMAL_PAGE_LOAD_STRATEGY "normal"
#define EAGER_PAGE_LOAD_STRATEGY "eager"
#define NONE_PAGE_LOAD_STRATEGY "none"

namespace webdriver {

class Element;
Expand Down
2 changes: 0 additions & 2 deletions cpp/iedriver/DocumentHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include "LocationInfo.h"

#define EELEMENTCLICKPOINTNOTSCROLLED 100

namespace webdriver {

// Forward declaration of classes.
Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "Script.h"
#include "StringUtilities.h"
#include "VariantUtilities.h"
#include "WebDriverConstants.h"

namespace webdriver {

Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/HtmlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "BrowserFactory.h"
#include "StringUtilities.h"
#include "WebDriverConstants.h"

#define HIDDEN_PARENT_WINDOW_CLASS "Internet Explorer_Hidden"

Expand Down
7 changes: 6 additions & 1 deletion cpp/iedriver/IECommandExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
#include "ProxyManager.h"
#include "StringUtilities.h"
#include "Script.h"
#include "WebDriverConstants.h"

#define MAX_HTML_DIALOG_RETRIES 5
#define WAIT_TIME_IN_MILLISECONDS 50
#define DEFAULT_FILE_UPLOAD_DIALOG_TIMEOUT_IN_MILLISECONDS 3000

namespace webdriver {

Expand Down Expand Up @@ -695,7 +700,7 @@ unsigned int WINAPI IECommandExecutor::ThreadProc(LPVOID lpParameter) {
// Return the HWND back through lpParameter, and signal that the
// window is ready for messages.
thread_context->hwnd = session_window_handle;
HANDLE event_handle = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_NAME);
HANDLE event_handle = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, WEBDRIVER_START_EVENT_NAME);
if (event_handle != NULL) {
::SetEvent(event_handle);
::CloseHandle(event_handle);
Expand Down
8 changes: 0 additions & 8 deletions cpp/iedriver/IECommandExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@
#include "IElementManager.h"
#include "messages.h"

#define WAIT_TIME_IN_MILLISECONDS 50
#define SCRIPT_WAIT_TIME_IN_MILLISECONDS 10
#define FIND_ELEMENT_WAIT_TIME_IN_MILLISECONDS 250
#define ASYNC_SCRIPT_EXECUTION_TIMEOUT_IN_MILLISECONDS 2000
#define DEFAULT_FILE_UPLOAD_DIALOG_TIMEOUT_IN_MILLISECONDS 3000
#define MAX_HTML_DIALOG_RETRIES 5
#define MAX_SAFE_INTEGER 9007199254740991L

namespace webdriver {

// Forward declaration of classes.
Expand Down
30 changes: 0 additions & 30 deletions cpp/iedriver/IECommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,6 @@

#include "CustomTypes.h"

#define BROWSER_NAME_CAPABILITY "browserName"
#define BROWSER_VERSION_CAPABILITY "browserVersion"
#define PLATFORM_NAME_CAPABILITY "platformName"
#define ACCEPT_INSECURE_CERTS_CAPABILITY "acceptInsecureCerts"
#define PAGE_LOAD_STRATEGY_CAPABILITY "pageLoadStrategy"
#define PROXY_CAPABILITY "proxy"
#define SET_WINDOW_RECT_CAPABILITY "setWindowRect"
#define TIMEOUTS_CAPABILITY "timeouts"
#define UNHANDLED_PROMPT_BEHAVIOR_CAPABILITY "unhandledPromptBehavior"
#define STRICT_FILE_INTERACTABILITY_CAPABILITY "strictFileInteractability"
#define IE_DRIVER_EXTENSIONS_CAPABILITY "se:ieOptions"

#define NATIVE_EVENTS_CAPABILITY "nativeEvents"
#define IGNORE_PROTECTED_MODE_CAPABILITY "ignoreProtectedModeSettings"
#define IGNORE_ZOOM_SETTING_CAPABILITY "ignoreZoomSetting"
#define INITIAL_BROWSER_URL_CAPABILITY "initialBrowserUrl"
#define ELEMENT_SCROLL_BEHAVIOR_CAPABILITY "elementScrollBehavior"
#define ENABLE_PERSISTENT_HOVER_CAPABILITY "enablePersistentHover"
#define REQUIRE_WINDOW_FOCUS_CAPABILITY "requireWindowFocus"
#define BROWSER_ATTACH_TIMEOUT_CAPABILITY "browserAttachTimeout"
#define BROWSER_COMMAND_LINE_SWITCHES_CAPABILITY "ie.browserCommandLineSwitches"
#define FORCE_CREATE_PROCESS_API_CAPABILITY "ie.forceCreateProcessApi"
#define USE_PER_PROCESS_PROXY_CAPABILITY "ie.usePerProcessProxy"
#define ENSURE_CLEAN_SESSION_CAPABILITY "ie.ensureCleanSession"
#define FORCE_SHELL_WINDOWS_API_CAPABILITY "ie.forceShellWindowsApi"
#define FILE_UPLOAD_DIALOG_TIMEOUT_CAPABILITY "ie.fileUploadDialogTimeout"
#define USE_LEGACY_FILE_UPLOAD_DIALOG_HANDLING_CAPABILITY "ie.useLegacyFileUploadDialogHandling"
#define ENABLE_FULL_PAGE_SCREENSHOT_CAPABILITY "ie.enableFullPageScreenshot"
#define IE_DRIVER_EXTENSIONS_CAPABILITY "se:ieOptions"

namespace webdriver {

// Forward declaration of classes to avoid
Expand Down
1 change: 1 addition & 0 deletions cpp/iedriver/IEDriver.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@
<ClInclude Include="targetver.h" />
<ClInclude Include="VariantUtilities.h" />
<ClInclude Include="WebDriver.h" />
<ClInclude Include="WebDriverConstants.h" />
<ClInclude Include="WindowUtilities.h" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions cpp/iedriver/IEDriver.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@
<ClInclude Include="cominterfaces.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="WebDriverConstants.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="IEDriver.def">
Expand Down

0 comments on commit 269c234

Please sign in to comment.