summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/automation/ui_controls.h16
-rw-r--r--chrome/browser/automation/ui_controls_linux.cc47
-rw-r--r--chrome/browser/automation/ui_controls_win.cc3
-rw-r--r--chrome/browser/browser.cc38
-rw-r--r--chrome/browser/browser.h3
-rw-r--r--chrome/browser/browser_focus_uitest.cc24
-rw-r--r--chrome/browser/views/bookmark_bar_view_test.cc21
-rw-r--r--chrome/test/automated_ui_tests/automated_ui_tests.cc17
-rw-r--r--chrome/test/automation/automation_constants.h16
9 files changed, 93 insertions, 92 deletions
diff --git a/chrome/browser/automation/ui_controls.h b/chrome/browser/automation/ui_controls.h
index b8781e2..3460ec3 100644
--- a/chrome/browser/automation/ui_controls.h
+++ b/chrome/browser/automation/ui_controls.h
@@ -26,12 +26,24 @@ namespace ui_controls {
// Many of the functions in this class include a variant that takes a Task.
// The version that takes a Task waits until the generated event is processed.
-// Once the generated event is processed the Task is Run (and deleted).
+// Once the generated event is processed the Task is Run (and deleted). Note
+// that this is a somewhat fragile process in that any event of the correct
+// type (key down, mouse click, etc.) will trigger the Task to be run. Hence
+// a usage such as
+//
+// SendKeyPress(...);
+// SendKeyPressNotifyWhenDone(..., task);
+//
+// might trigger |task| early.
+//
+// Note: Windows does not currently do anything with the |window| argument for
+// these functions, so passing NULL is ok.
// Send a key press with/without modifier keys.
bool SendKeyPress(gfx::NativeWindow window, wchar_t key, bool control,
bool shift, bool alt);
-bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift,
+bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
+ bool control, bool shift,
bool alt, Task* task);
// Send a key down event. Use VK_CONTROL for ctrl key,
diff --git a/chrome/browser/automation/ui_controls_linux.cc b/chrome/browser/automation/ui_controls_linux.cc
index e369ec7..53ba6fd 100644
--- a/chrome/browser/automation/ui_controls_linux.cc
+++ b/chrome/browser/automation/ui_controls_linux.cc
@@ -8,26 +8,45 @@
#include <gdk/gdkkeysyms.h>
#include "base/logging.h"
+#include "base/message_loop.h"
#include "chrome/test/automation/automation_constants.h"
namespace {
-int GdkKeycodeForWindowsKeycode(wchar_t windows_keyval) {
- switch (windows_keyval) {
- case VK_SPACE:
- return GDK_space;
- default:
- NOTREACHED() << "Unsupported keyval: " << windows_keyval;
- return 0;
+class EventWaiter : public MessageLoopForUI::Observer {
+ public:
+ EventWaiter(Task* task, GdkEventType type) : task_(task), type_(type) {
+ MessageLoopForUI::current()->AddObserver(this);
+ }
+
+ virtual ~EventWaiter() {
+ MessageLoopForUI::current()->RemoveObserver(this);
}
-}
-} // namespace
+ // MessageLoop::Observer implementation:
+ virtual void WillProcessEvent(GdkEvent* event) {
+ // No-op.
+ }
+
+ virtual void DidProcessEvent(GdkEvent* event) {
+ if (event->any.type == type_) {
+ task_->Run();
+ delete this;
+ }
+ }
+
+ private:
+ Task* task_;
+ GdkEventType type_;
+};
+
+}
namespace ui_controls {
bool SendKeyPress(gfx::NativeWindow window,
wchar_t key, bool control, bool shift, bool alt) {
+ // TODO(estade): send a release as well?
GdkEvent* event = gdk_event_new(GDK_KEY_PRESS);
event->key.type = GDK_KEY_PRESS;
@@ -41,7 +60,7 @@ bool SendKeyPress(gfx::NativeWindow window,
event->key.state = (control ? GDK_CONTROL_MASK : 0) |
(shift ? GDK_SHIFT_MASK : 0) |
(alt ? GDK_MOD1_MASK : 0);
- event->key.keyval = GdkKeycodeForWindowsKeycode(key);
+ event->key.keyval = key;
// TODO(estade): fill in the string?
GdkKeymapKey* keys;
@@ -60,10 +79,12 @@ bool SendKeyPress(gfx::NativeWindow window,
return true;
}
-bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift,
+bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
+ bool control, bool shift,
bool alt, Task* task) {
- NOTIMPLEMENTED();
- return false;
+ // This object will delete itself after running |task|.
+ new EventWaiter(task, GDK_KEY_PRESS);
+ return SendKeyPress(window, key, control, shift, alt);
}
// TODO(estade): this appears to be unused on Windows. Can we remove it?
diff --git a/chrome/browser/automation/ui_controls_win.cc b/chrome/browser/automation/ui_controls_win.cc
index c2eecce..8e971fa 100644
--- a/chrome/browser/automation/ui_controls_win.cc
+++ b/chrome/browser/automation/ui_controls_win.cc
@@ -300,7 +300,8 @@ bool SendKeyPress(gfx::NativeWindow window, wchar_t key, bool control,
return SendKeyPressImpl(key, control, shift, alt, NULL);
}
-bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift,
+bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
+ bool control, bool shift,
bool alt, Task* task) {
return SendKeyPressImpl(key, control, shift, alt, task);
}
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 905bf11..d72c24a 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -8,6 +8,7 @@
#include "app/l10n_util.h"
#include "base/command_line.h"
#include "base/idle_timer.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "base/thread.h"
@@ -1019,44 +1020,20 @@ void Browser::OverrideEncoding(int encoding_id) {
void Browser::Cut() {
UserMetrics::RecordAction(L"Cut", profile_);
- ui_controls::SendKeyPress(window()->GetNativeHandle(), L'X', true, false,
- false);
+ ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_X, true,
+ false, false);
}
void Browser::Copy() {
UserMetrics::RecordAction(L"Copy", profile_);
- ui_controls::SendKeyPress(window()->GetNativeHandle(), L'C', true, false,
- false);
-}
-
-void Browser::CopyCurrentPageURL() {
- UserMetrics::RecordAction(L"CopyURLToClipBoard", profile_);
- std::string url = GetSelectedTabContents()->GetURL().spec();
-
- if (!::OpenClipboard(NULL)) {
- NOTREACHED();
- return;
- }
-
- if (::EmptyClipboard()) {
- HGLOBAL text = ::GlobalAlloc(GMEM_MOVEABLE, url.size() + 1);
- LPSTR ptr = static_cast<LPSTR>(::GlobalLock(text));
- memcpy(ptr, url.c_str(), url.size());
- ptr[url.size()] = '\0';
- ::GlobalUnlock(text);
-
- ::SetClipboardData(CF_TEXT, text);
- }
-
- if (!::CloseClipboard()) {
- NOTREACHED();
- }
+ ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_C, true,
+ false, false);
}
void Browser::Paste() {
UserMetrics::RecordAction(L"Paste", profile_);
- ui_controls::SendKeyPress(window()->GetNativeHandle(), L'V', true, false,
- false);
+ ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_V, true,
+ false, false);
}
#endif // #if defined(OS_WIN)
@@ -1389,7 +1366,6 @@ void Browser::ExecuteCommandWithDisposition(
// Clipboard commands
case IDC_CUT: Cut(); break;
case IDC_COPY: Copy(); break;
- case IDC_COPY_URL: CopyCurrentPageURL(); break;
case IDC_PASTE: Paste(); break;
#endif
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index fe309e0..b2addca 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -341,11 +341,10 @@ class Browser : public TabStripModelDelegate,
void ToggleEncodingAutoDetect();
void OverrideEncoding(int encoding_id);
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
// Clipboard commands
void Cut();
void Copy();
- void CopyCurrentPageURL();
void Paste();
#endif
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index 819d27d..1c1c012 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/keyboard_codes.h"
#include "base/message_loop.h"
#include "base/ref_counted.h"
#include "chrome/browser/automation/ui_controls.h"
@@ -390,7 +391,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversal) {
&actual));
ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
- ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, false, false,
+ ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false,
+ false, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
// Ideally, we wouldn't sleep here and instead would use the event
@@ -413,7 +415,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversal) {
// Now let's press shift-tab to move the focus in reverse.
for (int j = 0; j < 7; ++j) {
- ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, true, false,
+ ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false,
+ true, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
::Sleep(kActionDelayMs);
@@ -490,7 +493,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
std::string actual = interstitial_page->GetFocusedElement();
ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
- ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, false, false,
+ ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false,
+ false, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
// Ideally, we wouldn't sleep here and instead would use the event
@@ -513,7 +517,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
// Now let's press shift-tab to move the focus in reverse.
for (int j = 0; j < 7; ++j) {
- ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, true, false,
+ ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false,
+ true, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
::Sleep(kActionDelayMs);
@@ -591,8 +596,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
LocationBarView* location_bar = browser_view->GetLocationBarView();
// Press Ctrl+F, which will make the Find box open and request focus.
- static const int VK_F = 0x46;
- ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false,
+ ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true,
+ false, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
@@ -620,7 +625,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
EXPECT_EQ(location_bar, focus_manager->GetFocusedView());
// Now press Ctrl+F again and focus should move to the Find box.
- ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false,
+ ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true,
+ false, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
focused_view = focus_manager->GetFocusedView();
@@ -638,8 +644,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
focus_manager->GetFocusedView());
// Now press Ctrl+F again and focus should move to the Find box.
- ui_controls::SendKeyPressNotifyWhenDone(VK_F, true, false, false,
- new MessageLoop::QuitTask());
+ ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true, false,
+ false, new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
// See remark above on why we wait.
diff --git a/chrome/browser/views/bookmark_bar_view_test.cc b/chrome/browser/views/bookmark_bar_view_test.cc
index b334549..2ed558f 100644
--- a/chrome/browser/views/bookmark_bar_view_test.cc
+++ b/chrome/browser/views/bookmark_bar_view_test.cc
@@ -744,7 +744,7 @@ class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase {
// Send a down event, which should select the first item.
ui_controls::SendKeyPressNotifyWhenDone(
- VK_DOWN, false, false, false,
+ NULL, VK_DOWN, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step3));
}
@@ -757,7 +757,7 @@ class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase {
// Send a key down event, which should select the next item.
ui_controls::SendKeyPressNotifyWhenDone(
- VK_DOWN, false, false, false,
+ NULL, VK_DOWN, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step4));
}
@@ -770,7 +770,7 @@ class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase {
// Send a right arrow to force the menu to open.
ui_controls::SendKeyPressNotifyWhenDone(
- VK_RIGHT, false, false, false,
+ NULL, VK_RIGHT, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step5));
}
@@ -786,7 +786,7 @@ class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase {
// Send a left arrow to close the submenu.
ui_controls::SendKeyPressNotifyWhenDone(
- VK_LEFT, false, false, false,
+ NULL, VK_LEFT, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step6));
}
@@ -801,7 +801,7 @@ class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase {
// Send a down arrow to wrap back to f1a
ui_controls::SendKeyPressNotifyWhenDone(
- VK_DOWN, false, false, false,
+ NULL, VK_DOWN, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step7));
}
@@ -814,7 +814,7 @@ class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase {
// Send enter, which should select the item.
ui_controls::SendKeyPressNotifyWhenDone(
- VK_RETURN, false, false, false,
+ NULL, VK_RETURN, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest10::Step8));
}
@@ -862,7 +862,8 @@ class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase {
void Step3() {
// Send escape so that the context menu hides.
- ui_controls::SendKeyPressNotifyWhenDone(VK_ESCAPE, false, false, false,
+ ui_controls::SendKeyPressNotifyWhenDone(
+ NULL, VK_ESCAPE, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest11::Step4));
}
@@ -949,8 +950,7 @@ class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase {
void Step4() {
// Press tab to give focus to the cancel button.
- ui_controls::SendKeyPressNotifyWhenDone(VK_TAB, false, false, false,
- NULL);
+ ui_controls::SendKeyPress(NULL, VK_TAB, false, false, false);
// For some reason return isn't processed correctly unless we delay.
MessageLoop::current()->PostDelayedTask(FROM_HERE,
@@ -959,7 +959,8 @@ class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase {
void Step5() {
// And press enter so that the cancel button is selected.
- ui_controls::SendKeyPressNotifyWhenDone(VK_RETURN, false, false, false,
+ ui_controls::SendKeyPressNotifyWhenDone(
+ NULL, VK_RETURN, false, false, false,
CreateEventTask(this, &BookmarkBarViewTest12::Step6));
}
diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc
index c33546d..c29e2aa 100644
--- a/chrome/test/automated_ui_tests/automated_ui_tests.cc
+++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc
@@ -6,6 +6,7 @@
#include "base/command_line.h"
#include "base/file_util.h"
+#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/rand_util.h"
@@ -488,35 +489,35 @@ bool AutomatedUITest::Options() {
}
bool AutomatedUITest::PressDownArrow() {
- return SimulateKeyPressInActiveWindow(VK_DOWN, 0);
+ return SimulateKeyPressInActiveWindow(base::VKEY_DOWN, 0);
}
bool AutomatedUITest::PressEnterKey() {
- return SimulateKeyPressInActiveWindow(VK_RETURN, 0);
+ return SimulateKeyPressInActiveWindow(base::VKEY_RETURN, 0);
}
bool AutomatedUITest::PressEscapeKey() {
- return SimulateKeyPressInActiveWindow(VK_ESCAPE, 0);
+ return SimulateKeyPressInActiveWindow(base::VKEY_ESCAPE, 0);
}
bool AutomatedUITest::PressPageDown() {
- return SimulateKeyPressInActiveWindow(VK_PRIOR, 0);
+ return SimulateKeyPressInActiveWindow(base::VKEY_PRIOR, 0);
}
bool AutomatedUITest::PressPageUp() {
- return SimulateKeyPressInActiveWindow(VK_NEXT, 0);
+ return SimulateKeyPressInActiveWindow(base::VKEY_NEXT, 0);
}
bool AutomatedUITest::PressSpaceBar() {
- return SimulateKeyPressInActiveWindow(VK_SPACE, 0);
+ return SimulateKeyPressInActiveWindow(base::VKEY_SPACE, 0);
}
bool AutomatedUITest::PressTabKey() {
- return SimulateKeyPressInActiveWindow(VK_TAB, 0);
+ return SimulateKeyPressInActiveWindow(base::VKEY_TAB, 0);
}
bool AutomatedUITest::PressUpArrow() {
- return SimulateKeyPressInActiveWindow(VK_UP, 0);
+ return SimulateKeyPressInActiveWindow(base::VKEY_UP, 0);
}
bool AutomatedUITest::SelectNextTab() {
diff --git a/chrome/test/automation/automation_constants.h b/chrome/test/automation/automation_constants.h
index 1972ea8..6d0a034 100644
--- a/chrome/test/automation/automation_constants.h
+++ b/chrome/test/automation/automation_constants.h
@@ -25,20 +25,4 @@ enum AutomationMsg_NavigationResponseValues {
AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
};
-#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_