diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 19:56:28 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-12 19:56:28 +0000 |
commit | 9a08bcfbb43283785d18f1a7e148a38659549e03 (patch) | |
tree | 5cdf40890a47f888ab5d01c8e2cd2611627cbd3a | |
parent | e626d7f115a1319421d1e2d5da85b6f0bd66877f (diff) | |
download | chromium_src-9a08bcfbb43283785d18f1a7e148a38659549e03.zip chromium_src-9a08bcfbb43283785d18f1a7e148a38659549e03.tar.gz chromium_src-9a08bcfbb43283785d18f1a7e148a38659549e03.tar.bz2 |
Checkpoint for event automation porting.
Partially based on patch by Dan Kegel.
Review URL: http://codereview.chromium.org/164371
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23209 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 20 | ||||
-rw-r--r-- | chrome/browser/automation/ui_controls.h | 14 | ||||
-rw-r--r-- | chrome/browser/automation/ui_controls_linux.cc | 55 | ||||
-rw-r--r-- | chrome/browser/automation/ui_controls_win.cc (renamed from chrome/browser/automation/ui_controls.cc) | 0 | ||||
-rw-r--r-- | chrome/chrome.gyp | 75 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 2 | ||||
-rw-r--r-- | chrome/test/automated_ui_tests/automated_ui_tests.cc | 79 | ||||
-rw-r--r-- | chrome/test/automation/automation_constants.h | 24 |
8 files changed, 195 insertions, 74 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 00fdd13..a4f797c 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -50,10 +50,10 @@ #include "net/proxy/proxy_service.h" #include "net/proxy/proxy_config_service_fixed.h" #include "net/url_request/url_request_context.h" +#include "views/event.h" #if defined(OS_WIN) // TODO(port): Port these headers. -#include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/character_encoding.h" #include "chrome/browser/download/save_package.h" #include "chrome/browser/external_tab_container.h" @@ -62,6 +62,7 @@ #if defined(OS_WIN) || defined(OS_LINUX) // TODO(port): Port these to the mac. +#include "chrome/browser/automation/ui_controls.h" #include "chrome/browser/login_prompt.h" #endif @@ -974,7 +975,11 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) #if defined(OS_WIN) IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) +#endif // defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_LINUX) IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) +#endif +#if defined(OS_WIN) IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, WindowSimulateDrag) #endif // defined(OS_WIN) @@ -1440,6 +1445,15 @@ void AutomationProvider::GetWindowHWND(int handle, HWND* win32_handle) { } #endif // defined(OS_WIN) +#if defined(OS_LINUX) +// TODO(estade): use this implementation for all platforms? +void AutomationProvider::GetActiveWindow(int* handle) { + gfx::NativeWindow window = + BrowserList::GetLastActive()->window()->GetNativeHandle(); + *handle = window_tracker_->Add(window); +} +#endif + void AutomationProvider::ExecuteBrowserCommandAsync(int handle, int command, bool* success) { *success = false; @@ -1707,7 +1721,9 @@ void AutomationProvider::WindowSimulateDrag(int handle, Send(reply_message); } } +#endif // defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_LINUX) void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message, int handle, wchar_t key, @@ -1724,7 +1740,9 @@ void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message, ((flags & views::Event::EF_ALT_DOWN) == views::Event::EF_ALT_DOWN)); } +#endif +#if defined(OS_WIN) void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { *view_id = -1; if (window_tracker_->ContainsHandle(handle)) { diff --git a/chrome/browser/automation/ui_controls.h b/chrome/browser/automation/ui_controls.h index a39d1cc..509ee78 100644 --- a/chrome/browser/automation/ui_controls.h +++ b/chrome/browser/automation/ui_controls.h @@ -1,12 +1,15 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H__ -#define CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H__ +#ifndef CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_ +#define CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_ #include <string> + +#if defined(OS_WIN) #include <wtypes.h> +#endif namespace views { class View; @@ -31,8 +34,7 @@ bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift, bool SendKeyDown(wchar_t key); bool SendKeyUp(wchar_t key); -// Simulate a mouse move. (x,y) are absolute -// screen coordinates. +// Simulate a mouse move. (x,y) are absolute screen coordinates. bool SendMouseMove(long x, long y); void SendMouseMoveNotifyWhenDone(long x, long y, Task* task); @@ -64,4 +66,4 @@ void MoveMouseToCenterAndPress(views::View* view, } // ui_controls -#endif // CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H__ +#endif // CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_ diff --git a/chrome/browser/automation/ui_controls_linux.cc b/chrome/browser/automation/ui_controls_linux.cc new file mode 100644 index 0000000..26f8715 --- /dev/null +++ b/chrome/browser/automation/ui_controls_linux.cc @@ -0,0 +1,55 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/automation/ui_controls.h" + +#include "base/logging.h" + +namespace ui_controls { + +bool SendKeyPress(wchar_t key, bool control, bool shift, bool alt) { + NOTIMPLEMENTED(); + return false; +} + +bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift, + bool alt, Task* task) { + NOTIMPLEMENTED(); + return false; +} + +bool SendKeyDown(wchar_t key) { + NOTIMPLEMENTED(); + return false; +} + +bool SendKeyUp(wchar_t key) { + NOTIMPLEMENTED(); + return false; +} + +bool SendMouseMove(long x, long y) { + NOTIMPLEMENTED(); + return false; +} + +void SendMouseMoveNotifyWhenDone(long x, long y, Task* task) { + NOTIMPLEMENTED(); +} + +bool SendMouseClick(MouseButton type) { + NOTIMPLEMENTED(); + return false; + +} + +// TODO(estade): need to figure out a better type for this than View. +void MoveMouseToCenterAndPress(views::View* view, + MouseButton button, + int state, + Task* task) { + NOTIMPLEMENTED(); +} + +} // namespace ui_controls diff --git a/chrome/browser/automation/ui_controls.cc b/chrome/browser/automation/ui_controls_win.cc index e15f1d4..e15f1d4 100644 --- a/chrome/browser/automation/ui_controls.cc +++ b/chrome/browser/automation/ui_controls_win.cc diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 5328ea4..4411daef 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -671,7 +671,8 @@ 'browser/automation/automation_window_tracker.h', 'browser/automation/extension_port_container.cc', 'browser/automation/extension_port_container.h', - 'browser/automation/ui_controls.cc', + 'browser/automation/ui_controls_linux.cc', + 'browser/automation/ui_controls_win.cc', 'browser/automation/ui_controls.h', 'browser/back_forward_menu_model.cc', 'browser/back_forward_menu_model.h', @@ -2458,7 +2459,6 @@ # Exclude files that should be excluded for all non-Windows platforms. 'sources!': [ 'browser/autocomplete/autocomplete_accessibility.cc', - 'browser/automation/ui_controls.cc', 'browser/bookmarks/bookmark_menu_controller.cc', 'browser/bookmarks/bookmark_menu_controller.h', 'browser/browser_accessibility.cc', @@ -3506,6 +3506,45 @@ ], }], ], + }, + { + 'target_name': 'automated_ui_tests', + 'type': 'executable', + 'msvs_guid': 'D2250C20-3A94-4FB9-AF73-11BC5B73884B', + 'dependencies': [ + 'browser', + 'renderer', + 'test_support_common', + 'test_support_ui', + 'theme_resources', + '../base/base.gyp:base', + '../skia/skia.gyp:skia', + '../third_party/libxml/libxml.gyp:libxml', + '../testing/gtest.gyp:gtest', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'test/automated_ui_tests/automated_ui_tests.cc', + 'test/automated_ui_tests/automated_ui_tests.h', + + 'tools/build/win/precompiled_wtl.h', + 'tools/build/win/precompiled_wtl.cc', + ], + 'conditions': [ + ['OS=="win"', { + 'include_dirs': [ + 'third_party/wtl/include', + ], + 'configurations': { + 'Debug': { + 'msvs_precompiled_header': 'tools/build/win/precompiled_wtl.h', + 'msvs_precompiled_source': 'tools/build/win/precompiled_wtl.cc', + }, + }, + }], + ], }, { 'target_name': 'ui_tests', @@ -4925,38 +4964,6 @@ ], }, { - 'target_name': 'automated_ui_tests', - 'type': 'executable', - 'msvs_guid': 'D2250C20-3A94-4FB9-AF73-11BC5B73884B', - 'dependencies': [ - 'browser', - 'renderer', - 'test_support_common', - 'test_support_ui', - 'theme_resources', - '../base/base.gyp:base', - '../skia/skia.gyp:skia', - '../third_party/libxml/libxml.gyp:libxml', - '../testing/gtest.gyp:gtest', - ], - 'include_dirs': [ - '..', - 'third_party/wtl/include', - ], - 'sources': [ - 'test/automated_ui_tests/automated_ui_tests.cc', - 'test/automated_ui_tests/automated_ui_tests.h', - 'tools/build/win/precompiled_wtl.h', - 'tools/build/win/precompiled_wtl.cc', - ], - 'configurations': { - 'Debug': { - 'msvs_precompiled_header': 'tools/build/win/precompiled_wtl.h', - 'msvs_precompiled_source': 'tools/build/win/precompiled_wtl.cc', - }, - }, - }, - { 'target_name': 'automation', 'type': '<(library)', 'msvs_guid': '1556EF78-C7E6-43C8-951F-F6B43AC0DD12', diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 2906a95..53cf365 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -39,7 +39,9 @@ class TabContents; //-------------------------------------------------------------------------- +#if defined(OS_MACOSX) void AutomationProvider::GetActiveWindow(int* handle) { NOTIMPLEMENTED(); } +#endif void AutomationProvider::ActivateWindow(int handle) { NOTIMPLEMENTED(); } diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index 7f66c9e..c33546d 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -41,10 +41,19 @@ const wchar_t* const kDebugModeSwitch = L"debug"; const wchar_t* const kWaitSwitch = L"wait-after-action"; -const wchar_t* const kDefaultInputFilePath = L"C:\\automated_ui_tests.txt"; - -const wchar_t* const kDefaultOutputFilePath - = L"C:\\automated_ui_tests_error_report.txt"; +const FilePath::CharType* const kDefaultInputFilePath = +#if defined(OS_WIN) + L"C:\\automated_ui_tests.txt"; +#else + "/tmp/automated_ui_tests.txt"; +#endif + +const FilePath::CharType* const kDefaultOutputFilePath = +#if defined(OS_WIN) + L"C:\\automated_ui_tests_error_report.txt"; +#else + "/tmp/automated_ui_tests_error_report.txt"; +#endif const int kDebuggingTimeoutMsec = 5000; @@ -54,6 +63,26 @@ const int kTestDialogActionsToRun = 7; void SilentRuntimeReportHandler(const std::string& str) { } +FilePath GetInputFilePath() { + const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); + if (parsed_command_line.HasSwitch(kInputFilePathSwitch)) { + return FilePath::FromWStringHack( + parsed_command_line.GetSwitchValue(kInputFilePathSwitch)); + } else { + return FilePath(kDefaultInputFilePath); + } +} + +FilePath GetOutputFilePath() { + const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); + if (parsed_command_line.HasSwitch(kOutputFilePathSwitch)) { + return FilePath::FromWStringHack( + parsed_command_line.GetSwitchValue(kOutputFilePathSwitch)); + } else { + return FilePath(kDefaultOutputFilePath); + } +} + } // namespace // This subset of commands is used to test dialog boxes, which aren't likely @@ -93,7 +122,7 @@ AutomatedUITest::AutomatedUITest() if (str.empty()) { post_action_delay_ = 1; } else { - post_action_delay_ = static_cast<int>(StringToInt64(str)); + post_action_delay_ = static_cast<int>(StringToInt64(WideToUTF16(str))); } } if (base::SysInfo::HasEnvVar(env_vars::kHeadless)) @@ -114,7 +143,7 @@ void AutomatedUITest::RunReproduction() { std::wstring num_reproductions_string = parsed_command_line.GetSwitchValue(kReproRepeatSwitch); std::string test = WideToASCII(num_reproductions_string); - num_reproductions = StringToInt64(num_reproductions_string); + num_reproductions = StringToInt64(test); } std::vector<std::string> actions; SplitString(action_string, L',', &actions); @@ -282,12 +311,15 @@ bool AutomatedUITest::DoAction(const std::string & action) { did_complete_action = PressDownArrow(); } else if (LowerCaseEqualsASCII(action, "downloads")) { did_complete_action = ShowDownloads(); +// TODO(estade): port. +#if defined(OS_WIN) } else if (LowerCaseEqualsASCII(action, "dragtableft")) { did_complete_action = DragActiveTab(false); } else if (LowerCaseEqualsASCII(action, "dragtabout")) { did_complete_action = DragTabOut(); } else if (LowerCaseEqualsASCII(action, "dragtabright")) { did_complete_action = DragActiveTab(true); +#endif // defined(OS_WIN) } else if (LowerCaseEqualsASCII(action, "duplicatetab")) { did_complete_action = DuplicateTab(); } else if (LowerCaseEqualsASCII(action, "editsearchengines")) { @@ -390,7 +422,7 @@ bool AutomatedUITest::DoAction(const std::string & action) { xml_writer_.EndElement(); if (post_action_delay_) - ::Sleep(1000 * post_action_delay_); + PlatformThread::Sleep(1000 * post_action_delay_); return did_complete_action; } @@ -609,12 +641,7 @@ bool AutomatedUITest::SimulateKeyPressInActiveWindow(wchar_t key, int flags) { } bool AutomatedUITest::InitXMLReader() { - std::wstring input_path; - const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); - if (parsed_command_line.HasSwitch(kInputFilePathSwitch)) - input_path = parsed_command_line.GetSwitchValue(kInputFilePathSwitch); - else - input_path = kDefaultInputFilePath; + FilePath input_path = GetInputFilePath(); if (!file_util::ReadFileToString(input_path, &xml_init_file_)) return false; @@ -622,16 +649,10 @@ bool AutomatedUITest::InitXMLReader() { } bool AutomatedUITest::WriteReportToFile() { + FilePath path = GetOutputFilePath(); std::ofstream error_file; - std::wstring path; - const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); - if (parsed_command_line.HasSwitch(kOutputFilePathSwitch)) - path = parsed_command_line.GetSwitchValue(kOutputFilePathSwitch); - else - path = kDefaultOutputFilePath; - if (!path.empty()) - error_file.open(path.c_str(), std::ios::out); + error_file.open(path.value().c_str(), std::ios::out); // Closes all open elements and free the writer. This is required // in order to retrieve the contents of the buffer. @@ -642,16 +663,10 @@ bool AutomatedUITest::WriteReportToFile() { } void AutomatedUITest::AppendToOutputFile(const std::string &append_string) { + FilePath path = GetOutputFilePath(); std::ofstream error_file; - std::wstring path; - const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); - if (parsed_command_line.HasSwitch(kOutputFilePathSwitch)) - path = parsed_command_line.GetSwitchValue(kOutputFilePathSwitch); - else - path = kDefaultOutputFilePath; - if (!path.empty()) - error_file.open(path.c_str(), std::ios::out | std::ios_base::app); + error_file.open(path.value().c_str(), std::ios::out | std::ios_base::app); error_file << append_string << " "; error_file.close(); @@ -702,6 +717,8 @@ void AutomatedUITest::LogInfoMessage(const std::string &info) { } std::wstring AutomatedUITest::GetMostRecentCrashDump() { +// TODO(estade): port. +#if defined(OS_WIN) std::wstring crash_dump_path; int file_count = 0; FILETIME most_recent_file_time; @@ -739,6 +756,10 @@ std::wstring AutomatedUITest::GetMostRecentCrashDump() { file_util::AppendToPath(&crash_dump_path, most_recent_file_name); return crash_dump_path; } +#else + NOTIMPLEMENTED(); + return std::wstring(); +#endif } bool AutomatedUITest::DidCrash(bool update_total_crashes) { diff --git a/chrome/test/automation/automation_constants.h b/chrome/test/automation/automation_constants.h index b08836d..1972ea8 100644 --- a/chrome/test/automation/automation_constants.h +++ b/chrome/test/automation/automation_constants.h @@ -1,9 +1,9 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_TEST_AUTOMATION_AUTOMATION_CONSTANTS_H__ -#define CHROME_TEST_AUTOMATION_AUTOMATION_CONSTANTS_H__ +#ifndef CHROME_TEST_AUTOMATION_AUTOMATION_CONSTANTS_H_ +#define CHROME_TEST_AUTOMATION_AUTOMATION_CONSTANTS_H_ namespace automation { // Amount of time to wait before querying the browser. @@ -25,4 +25,20 @@ enum AutomationMsg_NavigationResponseValues { AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, }; -#endif // CHROME_TEST_AUTOMATION_AUTOMATION_CONSTANTS_H__ +#if !defined(OS_WIN) + +// WebKit defines a larger set of these in +// WebKit/WebCore/platform/KeyboardCodes.h but I don't think we want to include +// that from here, and besides we only care about a subset of those. +const int VK_TAB = 0x09; +const int VK_RETURN = 0x0D; +const int VK_ESCAPE = 0x1B; +const int VK_SPACE = 0x20; +const int VK_PRIOR = 0x21; +const int VK_NEXT = 0x22; +const int VK_UP = 0x26; +const int VK_DOWN = 0x28; + +#endif // !defined(OS_WIN) + +#endif // CHROME_TEST_AUTOMATION_AUTOMATION_CONSTANTS_H_ |