From 965fa3ea6e550061db692c2a3af76ea9715f5541 Mon Sep 17 00:00:00 2001 From: "weitaosu@chromium.org" Date: Thu, 26 Sep 2013 03:27:11 +0000 Subject: [PATCH] Simulate a mouse click. BUG=134210 Review URL: https://codereview.chromium.org/24096025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225305 0039d316-1c4b-4281-b951-d872f2087c98 --- remoting/test/me2me_browsertest.cc | 10 ++++++++++ remoting/test/remote_desktop_browsertest.cc | 28 ++++++++++++++++++++++++++++ remoting/test/remote_desktop_browsertest.h | 7 +++++++ 3 files changed, 45 insertions(+) diff --git a/remoting/test/me2me_browsertest.cc b/remoting/test/me2me_browsertest.cc index 0c0e2caa1178..63feb65ec51f 100644 --- a/remoting/test/me2me_browsertest.cc +++ b/remoting/test/me2me_browsertest.cc @@ -10,6 +10,7 @@ namespace remoting { class Me2MeBrowserTest : public RemoteDesktopBrowserTest { protected: void TestKeyboardInput(); + void TestMouseInput(); }; IN_PROC_BROWSER_TEST_F(Me2MeBrowserTest, @@ -43,4 +44,13 @@ void Me2MeBrowserTest::TestKeyboardInput() { ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); } +void Me2MeBrowserTest::TestMouseInput() { + SimulateMouseLeftClickAt(10, 50); + // TODO: Verify programatically the mouse events are received by the host. + // This will be tricky as it depends on the host OS, window manager, desktop + // layout, and screen resolution. Until then we need to visually verify that + // "Dash Home" is clicked on a Unity window manager. + ASSERT_TRUE(TimeoutWaiter(base::TimeDelta::FromSeconds(5)).Wait()); +} + } // namespace remoting diff --git a/remoting/test/remote_desktop_browsertest.cc b/remoting/test/remote_desktop_browsertest.cc index 553b57dc58b6..e1dc25a49996 100644 --- a/remoting/test/remote_desktop_browsertest.cc +++ b/remoting/test/remote_desktop_browsertest.cc @@ -281,6 +281,34 @@ void RemoteDesktopBrowserTest::SimulateStringInput(const std::string& input) { SimulateCharInput(input[i]); } +void RemoteDesktopBrowserTest::SimulateMouseLeftClickAt(int x, int y) { + SimulateMouseClickAt(0, WebKit::WebMouseEvent::ButtonLeft, x, y); +} + +void RemoteDesktopBrowserTest::SimulateMouseClickAt( + int modifiers, WebKit::WebMouseEvent::Button button, int x, int y) { + ExecuteScript( + "var clientPluginElement = " + "document.getElementById('session-client-plugin');" + "var clientPluginRect = clientPluginElement.getBoundingClientRect();"); + + int top = ExecuteScriptAndExtractInt("clientPluginRect.top"); + int left = ExecuteScriptAndExtractInt("clientPluginRect.left"); + int width = ExecuteScriptAndExtractInt("clientPluginRect.width"); + int height = ExecuteScriptAndExtractInt("clientPluginRect.height"); + + ASSERT_GT(x, 0); + ASSERT_LT(x, width); + ASSERT_GT(y, 0); + ASSERT_LT(y, height); + + content::SimulateMouseClickAt( + browser()->tab_strip_model()->GetActiveWebContents(), + modifiers, + button, + gfx::Point(left + x, top + y)); +} + void RemoteDesktopBrowserTest::Install() { // TODO(weitaosu): add support for unpacked extension (the v2 app needs it). if (!NoInstall()) { diff --git a/remoting/test/remote_desktop_browsertest.h b/remoting/test/remote_desktop_browsertest.h index b7df98dea9b7..855bcb14002f 100644 --- a/remoting/test/remote_desktop_browsertest.h +++ b/remoting/test/remote_desktop_browsertest.h @@ -94,6 +94,13 @@ class RemoteDesktopBrowserTest : public ExtensionBrowserTest { // Simulate typing a string void SimulateStringInput(const std::string& input); + // Helper to simulate a left button mouse click. + void SimulateMouseLeftClickAt(int x, int y); + + // Helper to simulate a mouse click. + void SimulateMouseClickAt( + int modifiers, WebKit::WebMouseEvent::Button button, int x, int y); + // The following helpers each perform a composite task. // Install the chromoting extension -- 2.11.4.GIT