summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/automation/automation_provider.cc57
-rw-r--r--chrome/browser/automation/automation_provider_gtk.cc23
-rw-r--r--chrome/browser/automation/ui_controls.h26
-rw-r--r--chrome/browser/automation/ui_controls_linux.cc59
-rw-r--r--chrome/browser/automation/ui_controls_win.cc15
-rw-r--r--chrome/browser/blocked_popup_container_interactive_uitest.cc22
-rw-r--r--chrome/browser/browser_focus_uitest.cc201
-rw-r--r--chrome/common/gtk_util.cc32
8 files changed, 237 insertions, 198 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 7f364cb..6a22a23 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -836,7 +836,7 @@ class AutomationInterstitialPage : public InterstitialPage {
#if !defined(OS_MACOSX)
class ClickTask : public Task {
public:
- ClickTask(gfx::Point point, int flags) : point_(point), flags_(flags) {}
+ explicit ClickTask(int flags) : flags_(flags) {}
virtual ~ClickTask() {}
virtual void Run() {
@@ -854,11 +854,10 @@ class ClickTask : public Task {
NOTREACHED();
}
- ui_controls::SendMouseClick(point_, button);
+ ui_controls::SendMouseClick(button);
}
private:
- gfx::Point point_;
int flags_;
DISALLOW_COPY_AND_ASSIGN(ClickTask);
@@ -1513,14 +1512,60 @@ void AutomationProvider::ExecuteBrowserCommand(
Send(reply_message);
}
-#if !defined(OS_MACOSX)
+// This task just adds another task to the event queue. This is useful if
+// you want to ensure that any tasks added to the event queue after this one
+// have already been processed by the time |task| is run.
+class InvokeTaskLaterTask : public Task {
+ public:
+ explicit InvokeTaskLaterTask(Task* task) : task_(task) {}
+ virtual ~InvokeTaskLaterTask() {}
+
+ virtual void Run() {
+ MessageLoop::current()->PostTask(FROM_HERE, task_);
+ }
+
+ private:
+ Task* task_;
+
+ DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask);
+};
+
+#if defined(OS_WIN)
+// TODO(port): Replace POINT and other windowsisms.
+
+// This task sends a WindowDragResponse message with the appropriate
+// routing ID to the automation proxy. This is implemented as a task so that
+// we know that the mouse events (and any tasks that they spawn on the message
+// loop) have been processed by the time this is sent.
+class WindowDragResponseTask : public Task {
+ public:
+ WindowDragResponseTask(AutomationProvider* provider,
+ IPC::Message* reply_message)
+ : provider_(provider), reply_message_(reply_message) {}
+ virtual ~WindowDragResponseTask() {}
+
+ virtual void Run() {
+ DCHECK(reply_message_ != NULL);
+ AutomationMsg_WindowDrag::WriteReplyParams(reply_message_, true);
+ provider_->Send(reply_message_);
+ }
+
+ private:
+ AutomationProvider* provider_;
+ IPC::Message* reply_message_;
+
+ DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask);
+};
+#endif // defined(OS_WIN)
+
+#if defined(OS_WIN) || defined(OS_LINUX)
void AutomationProvider::WindowSimulateClick(const IPC::Message& message,
int handle,
const gfx::Point& click,
int flags) {
if (window_tracker_->ContainsHandle(handle)) {
ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(),
- new ClickTask(click, flags));
+ new ClickTask(flags));
}
}
@@ -1541,7 +1586,7 @@ void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message,
((flags & views::Event::EF_ALT_DOWN) ==
views::Event::EF_ALT_DOWN));
}
-#endif // !defined(OS_MACOSX)
+#endif // defined(OS_WIN) || defined(OS_LINUX)
void AutomationProvider::IsWindowActive(int handle, bool* success,
bool* is_active) {
diff --git a/chrome/browser/automation/automation_provider_gtk.cc b/chrome/browser/automation/automation_provider_gtk.cc
index 31a5c99..9e91b52 100644
--- a/chrome/browser/automation/automation_provider_gtk.cc
+++ b/chrome/browser/automation/automation_provider_gtk.cc
@@ -4,13 +4,16 @@
#include "chrome/browser/automation/automation_provider.h"
+#include "base/gfx/point.h"
+#include "base/gfx/rect.h"
#include "chrome/browser/gtk/view_id_util.h"
+#include "chrome/common/gtk_util.h"
void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds,
bool* success) {
*success = false;
- if (window_tracker_->ContainsHandle(handle)) {
- GtkWindow* window = window_tracker_->GetResource(handle);
+ GtkWindow* window = window_tracker_->GetResource(handle);
+ if (window) {
gtk_window_move(window, bounds.x(), bounds.height());
gtk_window_resize(window, bounds.width(), bounds.height());
*success = true;
@@ -20,8 +23,8 @@ void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds,
void AutomationProvider::SetWindowVisible(int handle, bool visible,
bool* result) {
*result = false;
- if (window_tracker_->ContainsHandle(handle)) {
- GtkWindow* window = window_tracker_->GetResource(handle);
+ GtkWindow* window = window_tracker_->GetResource(handle);
+ if (window) {
if (visible) {
gtk_window_present(window);
} else {
@@ -37,8 +40,8 @@ void AutomationProvider::WindowGetViewBounds(int handle, int view_id,
gfx::Rect* bounds) {
*success = false;
- if (window_tracker_->ContainsHandle(handle)) {
- gfx::NativeWindow window = window_tracker_->GetResource(handle);
+ GtkWindow* window = window_tracker_->GetResource(handle);
+ if (window) {
GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window),
static_cast<ViewID>(view_id));
if (!widget)
@@ -48,11 +51,9 @@ void AutomationProvider::WindowGetViewBounds(int handle, int view_id,
widget->allocation.width, widget->allocation.height);
gint x, y;
if (screen_coordinates) {
- gdk_window_get_origin(widget->window, &x, &y);
- if (GTK_WIDGET_NO_WINDOW(widget)) {
- x += widget->allocation.x;
- y += widget->allocation.y;
- }
+ gfx::Point point = gtk_util::GetWidgetScreenPosition(widget);
+ x = point.x();
+ y = point.y();
} else {
gtk_widget_translate_coordinates(widget, GTK_WIDGET(window),
0, 0, &x, &y);
diff --git a/chrome/browser/automation/ui_controls.h b/chrome/browser/automation/ui_controls.h
index 0df639f..5f3d9e3 100644
--- a/chrome/browser/automation/ui_controls.h
+++ b/chrome/browser/automation/ui_controls.h
@@ -62,21 +62,25 @@ enum MouseButtonState {
DOWN = 2
};
-// Sends a mouse down and or up message.
+// Sends a mouse down and/or up message. The click will be sent to wherever
+// the cursor currently is, so be sure to move the cursor before calling this
+// (and be sure the cursor has arrived!).
bool SendMouseEvents(MouseButton type, int state);
-void SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task);
-
-// Simulate a single mouse click with given button type.
-// The click will be sent to whichever window is under the cursor, so make sure
-// the cursor is where you want it before calling this.
-bool SendMouseClick(const gfx::Point& point, MouseButton type);
+bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task);
+// Same as SendMouseEvents with UP | DOWN.
+bool SendMouseClick(MouseButton type);
// A combination of SendMouseMove to the middle of the view followed by
// SendMouseEvents.
-void MoveMouseToCenterAndPress(views::View* view,
- MouseButton button,
- int state,
- Task* task);
+void MoveMouseToCenterAndPress(
+#if defined(OS_WIN)
+ views::View* view,
+#elif defined(OS_LINUX)
+ GtkWidget* widget,
+#endif
+ MouseButton button,
+ int state,
+ Task* task);
} // ui_controls
diff --git a/chrome/browser/automation/ui_controls_linux.cc b/chrome/browser/automation/ui_controls_linux.cc
index c79dc68..bcaf6c5 100644
--- a/chrome/browser/automation/ui_controls_linux.cc
+++ b/chrome/browser/automation/ui_controls_linux.cc
@@ -7,8 +7,10 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#include "base/gfx/rect.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "chrome/common/gtk_util.h"
#include "chrome/test/automation/automation_constants.h"
namespace {
@@ -46,6 +48,24 @@ class EventWaiter : public MessageLoopForUI::Observer {
GdkEventType type_;
};
+class ClickTask : public Task {
+ public:
+ ClickTask(ui_controls::MouseButton button, int state, Task* followup)
+ : button_(button), state_(state), followup_(followup) {
+ }
+
+ virtual ~ClickTask() {}
+
+ virtual void Run() {
+ ui_controls::SendMouseEventsNotifyWhenDone(button_, state_, followup_);
+ }
+
+ private:
+ ui_controls::MouseButton button_;
+ int state_;
+ Task* followup_;
+};
+
} // namespace
namespace ui_controls {
@@ -109,20 +129,21 @@ bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task) {
return rv;
}
-bool SendMouseClick(const gfx::Point& point, MouseButton type) {
+bool SendMouseEvents(MouseButton type, int state) {
GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
- event->button.window = gdk_window_at_pointer(NULL, NULL);
- g_object_ref(event->button.window);
event->button.send_event = false;
event->button.time = EventTimeNow();
- event->motion.x_root = point.x();
- event->motion.y_root = point.x();
+ gint x, y;
+ event->button.window = gdk_window_at_pointer(&x, &y);
+ g_object_ref(event->button.window);
+ event->motion.x = x;
+ event->motion.y = y;
gint origin_x, origin_y;
gdk_window_get_origin(event->button.window, &origin_x, &origin_y);
- event->button.x = point.x() - origin_x;
- event->button.y = point.y() - origin_y;
+ event->button.x_root = x + origin_x;
+ event->button.y_root = y + origin_y;
event->button.axes = NULL;
// TODO(estade): as above, we may want to pack this with the actual state.
@@ -131,13 +152,15 @@ bool SendMouseClick(const gfx::Point& point, MouseButton type) {
event->button.device = gdk_device_get_core_pointer();
event->button.type = GDK_BUTTON_PRESS;
- gdk_event_put(event);
+ if (state & DOWN)
+ gdk_event_put(event);
// Also send a release event.
GdkEvent* release_event = gdk_event_copy(event);
release_event->button.type = GDK_BUTTON_RELEASE;
release_event->button.time++;
- gdk_event_put(release_event);
+ if (state & UP)
+ gdk_event_put(release_event);
gdk_event_free(event);
gdk_event_free(release_event);
@@ -145,12 +168,24 @@ bool SendMouseClick(const gfx::Point& point, MouseButton type) {
return false;
}
-// TODO(estade): need to figure out a better type for this than View.
-void MoveMouseToCenterAndPress(views::View* view,
+bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
+ bool rv = SendMouseEvents(type, state);
+ MessageLoop::current()->PostTask(FROM_HERE, task);
+ return rv;
+}
+
+bool SendMouseClick(MouseButton type) {
+ return SendMouseEvents(type, UP | DOWN);
+}
+
+void MoveMouseToCenterAndPress(GtkWidget* widget,
MouseButton button,
int state,
Task* task) {
- NOTIMPLEMENTED();
+ gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget);
+ SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2,
+ bounds.y() + bounds.height() / 2,
+ new ClickTask(button, state, task));
}
} // namespace ui_controls
diff --git a/chrome/browser/automation/ui_controls_win.cc b/chrome/browser/automation/ui_controls_win.cc
index d1b59ee..78b1acb 100644
--- a/chrome/browser/automation/ui_controls_win.cc
+++ b/chrome/browser/automation/ui_controls_win.cc
@@ -219,6 +219,15 @@ bool SendKeyPressImpl(wchar_t key, bool control, bool shift, bool alt,
}
bool SendMouseMoveImpl(long x, long y, Task* task) {
+ // First check if the mouse is already there.
+ POINT current_pos;
+ ::GetCursorPos(&current_pos);
+ if (x == current_pos.x && y == current_pos.y) {
+ if (task)
+ MessageLoop::current()->PostTask(FROM_HERE, task);
+ return true;
+ }
+
INPUT input = { 0 };
int screen_width = ::GetSystemMetrics(SM_CXSCREEN) - 1;
@@ -318,11 +327,11 @@ bool SendMouseEvents(MouseButton type, int state) {
return SendMouseEventsImpl(type, state, NULL);
}
-void SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
- SendMouseEventsImpl(type, state, task);
+bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
+ return SendMouseEventsImpl(type, state, task);
}
-bool SendMouseClick(const gfx::Point& point, MouseButton type) {
+bool SendMouseClick(MouseButton type) {
return SendMouseEventsImpl(type, UP | DOWN, NULL);
}
diff --git a/chrome/browser/blocked_popup_container_interactive_uitest.cc b/chrome/browser/blocked_popup_container_interactive_uitest.cc
index 44dabb3..874fd72 100644
--- a/chrome/browser/blocked_popup_container_interactive_uitest.cc
+++ b/chrome/browser/blocked_popup_container_interactive_uitest.cc
@@ -61,7 +61,7 @@ class BlockedPopupContainerInteractiveTest : public UITest {
scoped_refptr<TabProxy> tab_;
};
-TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_TestOpenAndResizeTo) {
+TEST_F(BlockedPopupContainerInteractiveTest, TestOpenAndResizeTo) {
NavigateMainTabTo(L"constrained_window_onload_resizeto.html");
SimulateClickInCenterOf(window_);
@@ -100,12 +100,17 @@ TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_TestOpenAndResizeTo) {
ASSERT_TRUE(popup_window->GetViewBoundsWithTimeout(
VIEW_ID_TAB_CONTAINER, &rect, false, 1000, &is_timeout));
ASSERT_FALSE(is_timeout);
- EXPECT_LT(rect.width(), 200);
EXPECT_LT(rect.height(), 200);
+#if defined(OS_LINUX)
+ // On Linux we may run in an environment where there is no window frame. In
+ // this case our width might be exactly 200. The height will still be less
+ // because we have to show the location bar.
+ EXPECT_LE(rect.width(), 200);
+#else
+ EXPECT_LT(rect.width(), 200);
+#endif
}
-// TODO(estade): port.
-#if !defined(OS_LINUX)
// Helper function used to get the number of blocked popups out of the window
// title.
bool ParseCountOutOfTitle(const std::wstring& title, int* output) {
@@ -128,7 +133,7 @@ bool ParseCountOutOfTitle(const std::wstring& title, int* output) {
// Tests that in the window.open() equivalent of a fork bomb, we stop building
// windows.
-TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_DontSpawnEndlessPopups) {
+TEST_F(BlockedPopupContainerInteractiveTest, DontSpawnEndlessPopups) {
NavigateMainTabTo(L"infinite_popups.html");
SimulateClickInCenterOf(window_);
@@ -171,7 +176,7 @@ TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_DontSpawnEndlessPopups) {
// Make sure that we refuse to close windows when a constrained popup is
// displayed.
-TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_WindowOpenWindowClosePopup) {
+TEST_F(BlockedPopupContainerInteractiveTest, WindowOpenWindowClosePopup) {
NavigateMainTabTo(L"openclose_main.html");
SimulateClickInCenterOf(window_);
@@ -207,7 +212,7 @@ TEST_F(BlockedPopupContainerInteractiveTest, BlockAlertFromBlockedPopup) {
ASSERT_EQ(1, popup_count);
}
-TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_ShowAlertFromNormalPopup) {
+TEST_F(BlockedPopupContainerInteractiveTest, ShowAlertFromNormalPopup) {
NavigateMainTabTo(L"show_alert.html");
SimulateClickInCenterOf(window_);
@@ -228,7 +233,7 @@ TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_ShowAlertFromNormalPopup)
// Make sure that window focus works while creating a popup window so that we
// don't
-TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_DontBreakOnBlur) {
+TEST_F(BlockedPopupContainerInteractiveTest, DontBreakOnBlur) {
NavigateMainTabTo(L"window_blur_test.html");
SimulateClickInCenterOf(window_);
@@ -238,4 +243,3 @@ TEST_F(BlockedPopupContainerInteractiveTest, DISABLED_DontBreakOnBlur) {
// We popup shouldn't be closed by the onblur handler.
ASSERT_FALSE(automation()->WaitForWindowCountToBecome(1, 1500));
}
-#endif
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index ed3c6d1..ede9eba 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -31,6 +31,14 @@
#include "chrome/browser/gtk/view_id_util.h"
#endif
+#if defined(OS_LINUX)
+// For some reason we hit an external DNS lookup in this test in Linux but not
+// on Windows. TODO(estade): investigate.
+#define MAYBE_FocusTraversalOnInterstitial DISABLED_FocusTraversalOnInterstitial
+#else
+#define MAYBE_FocusTraversalOnInterstitial FocusTraversalOnInterstitial
+#endif
+
namespace {
// The delay waited in some cases where we don't have a notifications for an
@@ -58,17 +66,38 @@ class BrowserFocusTest : public InProcessBrowserTest {
views::FocusManager* focus_manager =
views::FocusManager::GetFocusManagerForNativeView(window);
ASSERT_TRUE(focus_manager);
- EXPECT_EQ(reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid),
- focus_manager->GetFocusedView()) << "For view id " << vid;
+ EXPECT_EQ(vid, focus_manager->GetFocusedView()->GetID()) <<
+ "For view id " << vid;
#elif defined(OS_LINUX)
GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid);
ASSERT_TRUE(widget);
- EXPECT_TRUE(WidgetInFocusChain(GTK_WIDGET(window), widget));
+ EXPECT_TRUE(WidgetInFocusChain(GTK_WIDGET(window), widget)) <<
+ "For view id " << vid;
#else
NOTIMPLEMENTED();
#endif
}
+ void ClickOnView(ViewID vid) {
+ BrowserWindow* browser_window = browser()->window();
+ ASSERT_TRUE(browser_window);
+#if defined(OS_WIN)
+ views::View* view =
+ reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid);
+#elif defined(OS_LINUX)
+ gfx::NativeWindow window = browser_window->GetNativeHandle();
+ ASSERT_TRUE(window);
+ GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid);
+#endif
+ ASSERT_TRUE(view);
+ ui_controls::MoveMouseToCenterAndPress(
+ view,
+ ui_controls::LEFT,
+ ui_controls::DOWN | ui_controls::UP,
+ new MessageLoop::QuitTask());
+ ui_test_utils::RunMessageLoop();
+ }
+
static void HideNativeWindow(gfx::NativeWindow window) {
#if defined(OS_WIN)
// TODO(jcampan): retrieve the WidgetWin and show/hide on it instead of
@@ -173,31 +202,24 @@ class TestInterstitialPage : public InterstitialPage {
} // namespace
-// TODO(estade): port.
-#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) {
- browser()->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::LINK,
- true, -1, false, NULL);
+#if defined(OS_LINUX)
+ // It seems we have to wait a little bit for the widgets to spin up before
+ // we can start clicking on them.
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ new MessageLoop::QuitTask(),
+ kActionDelayMs);
+ ui_test_utils::RunMessageLoop();
+#endif
+
CheckViewHasFocus(VIEW_ID_LOCATION_BAR);
- BrowserView* browser_view = static_cast<BrowserView*>(browser()->window());
- ui_controls::MoveMouseToCenterAndPress(
- browser_view->GetTabContentsContainerView(),
- ui_controls::LEFT,
- ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ClickOnView(VIEW_ID_TAB_CONTAINER);
CheckViewHasFocus(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW);
- ui_controls::MoveMouseToCenterAndPress(
- browser_view->GetLocationBarView(),
- ui_controls::LEFT,
- ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ ClickOnView(VIEW_ID_LOCATION_BAR);
CheckViewHasFocus(VIEW_ID_LOCATION_BAR);
}
-#endif
IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BrowsersRememberFocus) {
HTTPTestServer* server = StartHTTPServer();
@@ -456,23 +478,16 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversal) {
}
}
-#if defined(OS_WIN)
// Focus traversal while an interstitial is showing.
-IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
+IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
HTTPTestServer* server = StartHTTPServer();
// First we navigate to our test page.
GURL url = server->TestServerPageW(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
- HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
- BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(hwnd);
-
// Focus should be on the page.
- EXPECT_EQ(browser_view->GetTabContentsContainerView(),
- focus_manager->GetFocusedView());
+ CheckViewHasFocus(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW);
// Let's show an interstitial.
TestInterstitialPage* interstitial_page =
@@ -485,13 +500,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
1000);
ui_test_utils::RunMessageLoop();
- // Click on the location bar.
- LocationBarView* location_bar = browser_view->GetLocationBarView();
- ui_controls::MoveMouseToCenterAndPress(location_bar,
- ui_controls::LEFT,
- ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ browser()->FocusLocationBar();
const char* kExpElementIDs[] = {
"", // Initially no element in the page should be focused
@@ -500,10 +509,12 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
"gmapLink"
};
+ gfx::NativeWindow window = browser()->window()->GetNativeHandle();
+
// Test forward focus traversal.
for (int i = 0; i < 2; ++i) {
// Location bar should be focused.
- EXPECT_EQ(location_bar, focus_manager->GetFocusedView());
+ CheckViewHasFocus(VIEW_ID_LOCATION_BAR);
// Now let's press tab to move the focus.
for (int j = 0; j < 7; ++j) {
@@ -511,14 +522,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
std::string actual = interstitial_page->GetFocusedElement();
ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
- ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false,
+ ui_controls::SendKeyPressNotifyWhenDone(window, 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
// processed ack notification from the renderer. I am reluctant to create
// a new notification/callback for that purpose just for this test.
- ::Sleep(kActionDelayMs);
+ PlatformThread::Sleep(kActionDelayMs);
}
// At this point the renderer has sent us a message asking to advance the
@@ -531,15 +542,15 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
// Now let's try reverse focus traversal.
for (int i = 0; i < 2; ++i) {
// Location bar should be focused.
- EXPECT_EQ(location_bar, focus_manager->GetFocusedView());
+ CheckViewHasFocus(VIEW_ID_LOCATION_BAR);
// Now let's press shift-tab to move the focus in reverse.
for (int j = 0; j < 7; ++j) {
- ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false,
+ ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_TAB, false,
true, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
- ::Sleep(kActionDelayMs);
+ PlatformThread::Sleep(kActionDelayMs);
// Let's make sure the focus is on the expected element in the page.
std::string actual = interstitial_page->GetFocusedElement();
@@ -562,14 +573,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) {
GURL url = server->TestServerPageW(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
- HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
- BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(hwnd);
-
// Page should have focus.
- EXPECT_EQ(browser_view->GetTabContentsContainerView(),
- focus_manager->GetFocusedView());
+ CheckViewHasFocus(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW);
EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()->
HasFocus());
@@ -585,18 +590,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) {
ui_test_utils::RunMessageLoop();
// The interstitial should have focus now.
- EXPECT_EQ(browser_view->GetTabContentsContainerView(),
- focus_manager->GetFocusedView());
+ CheckViewHasFocus(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW);
EXPECT_TRUE(interstitial_page->HasFocus());
// Hide the interstitial.
interstitial_page->DontProceed();
// Focus should be back on the original page.
- EXPECT_EQ(browser_view->GetTabContentsContainerView(),
- focus_manager->GetFocusedView());
- EXPECT_TRUE(browser()->GetSelectedTabContents()->render_view_host()->view()->
- HasFocus());
+ CheckViewHasFocus(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW);
}
// Make sure Find box can request focus, even when it is already open.
@@ -607,14 +608,10 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
GURL url = server->TestServerPageW(kTypicalPage);
ui_test_utils::NavigateToURL(browser(), url);
- HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
- BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(hwnd);
- LocationBarView* location_bar = browser_view->GetLocationBarView();
+ gfx::NativeWindow window = browser()->window()->GetNativeHandle();
// Press Ctrl+F, which will make the Find box open and request focus.
- ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true,
+ ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true,
false, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
@@ -624,62 +621,40 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
// could create a RenderViewHostDelegate wrapper and hook-it up by either:
// - creating a factory used to create the delegate
// - making the test a private and overwriting the delegate member directly.
- ::Sleep(kActionDelayMs);
- MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs);
ui_test_utils::RunMessageLoop();
- views::View* focused_view = focus_manager->GetFocusedView();
- ASSERT_TRUE(focused_view != NULL);
- EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID());
-
- // Click on the location bar.
- ui_controls::MoveMouseToCenterAndPress(location_bar,
- ui_controls::LEFT,
- ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
+ CheckViewHasFocus(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
- // Make sure the location bar is focused.
- EXPECT_EQ(location_bar, focus_manager->GetFocusedView());
+ browser()->FocusLocationBar();
+ CheckViewHasFocus(VIEW_ID_LOCATION_BAR);
// Now press Ctrl+F again and focus should move to the Find box.
- ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true,
+ ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true,
false, false,
new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
- focused_view = focus_manager->GetFocusedView();
- ASSERT_TRUE(focused_view != NULL);
- EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID());
+ CheckViewHasFocus(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
// Set focus to the page.
- ui_controls::MoveMouseToCenterAndPress(
- browser_view->GetTabContentsContainerView(),
- ui_controls::LEFT,
- ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
- ui_test_utils::RunMessageLoop();
- EXPECT_EQ(browser_view->GetTabContentsContainerView(),
- focus_manager->GetFocusedView());
+ ClickOnView(VIEW_ID_TAB_CONTAINER);
+ CheckViewHasFocus(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW);
// Now press Ctrl+F again and focus should move to the Find box.
- ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true, false,
+ ui_controls::SendKeyPressNotifyWhenDone(window, base::VKEY_F, true, false,
false, new MessageLoop::QuitTask());
ui_test_utils::RunMessageLoop();
// See remark above on why we wait.
- ::Sleep(kActionDelayMs);
- MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, new MessageLoop::QuitTask(), kActionDelayMs);
ui_test_utils::RunMessageLoop();
-
- focused_view = focus_manager->GetFocusedView();
- ASSERT_TRUE(focused_view != NULL);
- EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID());
+ CheckViewHasFocus(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD);
}
-#endif // defined(OS_WIN)
// Makes sure the focus is in the right location when opening the different
// types of tabs.
-// TODO(estade): undisable this.
IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) {
// Open the history tab, focus should be on the tab contents.
browser()->ShowHistoryTab();
@@ -699,56 +674,38 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) {
CheckViewHasFocus(VIEW_ID_LOCATION_BAR);
}
-#if defined(OS_WIN)
// Tests that focus goes where expected when using reload.
IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) {
HTTPTestServer* server = StartHTTPServer();
- HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
- BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
- ASSERT_TRUE(browser_view);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(hwnd);
- ASSERT_TRUE(focus_manager);
-
// Open the new tab, reload.
browser()->NewTab();
browser()->Reload();
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
// Focus should stay on the location bar.
- EXPECT_EQ(browser_view->GetLocationBarView(),
- focus_manager->GetFocusedView());
+ CheckViewHasFocus(VIEW_ID_LOCATION_BAR);
// Open a regular page, focus the location bar, reload.
ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage));
- browser_view->GetLocationBarView()->FocusLocation();
- EXPECT_EQ(browser_view->GetLocationBarView(),
- focus_manager->GetFocusedView());
+ browser()->FocusLocationBar();
+ CheckViewHasFocus(VIEW_ID_LOCATION_BAR);
browser()->Reload();
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
// Focus should now be on the tab contents.
- EXPECT_EQ(browser_view->GetTabContentsContainerView(),
- focus_manager->GetFocusedView());
+ browser()->ShowDownloadsTab();
+ CheckViewHasFocus(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW);
}
// Tests that focus goes where expected when using reload on a crashed tab.
IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReloadCrashedTab) {
HTTPTestServer* server = StartHTTPServer();
- HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
- BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
- ASSERT_TRUE(browser_view);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(hwnd);
- ASSERT_TRUE(focus_manager);
-
// Open a regular page, crash, reload.
ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage));
ui_test_utils::CrashTab(browser()->GetSelectedTabContents());
browser()->Reload();
ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
// Focus should now be on the tab contents.
- EXPECT_EQ(browser_view->GetTabContentsContainerView(),
- focus_manager->GetFocusedView());
+ browser()->ShowDownloadsTab();
+ CheckViewHasFocus(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW);
}
-#endif // defined(OS_WIN)
diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc
index a491763..67595e9 100644
--- a/chrome/common/gtk_util.cc
+++ b/chrome/common/gtk_util.cc
@@ -148,33 +148,17 @@ void ForceFontSizePixels(GtkWidget* widget, double size_pixels) {
}
gfx::Point GetWidgetScreenPosition(GtkWidget* widget) {
- int x = 0, y = 0;
-
- if (GTK_IS_WINDOW(widget)) {
- gdk_window_get_origin(widget->window, &x, &y);
- return gfx::Point(x, y);
- } else {
- x = widget->allocation.x;
- y = widget->allocation.y;
+ if (!widget->window) {
+ NOTREACHED() << "Must only be called on realized widgets.";
+ return gfx::Point(0, 0);
}
- GtkWidget* parent = gtk_widget_get_parent(widget);
- while (parent) {
- if (GTK_IS_WINDOW(parent)) {
- int window_x, window_y;
- // Returns the origin of the window, excluding the frame if one is exists.
- gdk_window_get_origin(parent->window, &window_x, &window_y);
- x += window_x;
- y += window_y;
- return gfx::Point(x, y);
- }
-
- if (!GTK_WIDGET_NO_WINDOW(parent)) {
- x += parent->allocation.x;
- y += parent->allocation.y;
- }
+ gint x, y;
+ gdk_window_get_origin(widget->window, &x, &y);
- parent = gtk_widget_get_parent(parent);
+ if (!GTK_IS_WINDOW(widget)) {
+ x += widget->allocation.x;
+ y += widget->allocation.y;
}
return gfx::Point(x, y);