Commit 98d6f1e4 authored by tapted's avatar tapted Committed by Commit bot

Introduce ui_test_utils::FocusView and de-flake OmniboxViewTest.BeginningShownAfterBlur

Currently interactive UI tests typically call `ClickOnView` to transfer
focus. On Mac, the behaviour of a click changes when an application
loses focus, and re-activating the application in a test is not
reliable. The test application shouldn't be losing focus in
interactive_ui_tests, but tracing suggests this is ocurring anyway.

This CL introduces ui_test_utils::FocusView which is a more robust way
to transfer focus in a test.

OmniboxViewTest.BeginningShownAfterBlur is changed to use
ui_test_utils::FocusView and re-enabled.

BUG=406012

Review URL: https://codereview.chromium.org/534993002

Cr-Commit-Position: refs/heads/master@{#293516}
parent 802d4aee
...@@ -1676,13 +1676,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EditSearchEngines) { ...@@ -1676,13 +1676,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EditSearchEngines) {
EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen()); EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen());
} }
#if defined(OS_MACOSX) IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BeginningShownAfterBlur) {
// http://crbug.com/406012
#define MAYBE_BeginningShownAfterBlur DISABLED_BeginningShownAfterBlur
#else
#define MAYBE_BeginningShownAfterBlur BeginningShownAfterBlur
#endif
IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_BeginningShownAfterBlur) {
OmniboxView* omnibox_view = NULL; OmniboxView* omnibox_view = NULL;
ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
...@@ -1690,18 +1684,18 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_BeginningShownAfterBlur) { ...@@ -1690,18 +1684,18 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_BeginningShownAfterBlur) {
omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("data:text/plain,test"), omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("data:text/plain,test"),
5U, false, false); 5U, false, false);
omnibox_view->OnAfterPossibleChange(); omnibox_view->OnAfterPossibleChange();
ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
size_t start, end; size_t start, end;
omnibox_view->GetSelectionBounds(&start, &end); omnibox_view->GetSelectionBounds(&start, &end);
ASSERT_EQ(5U, start); EXPECT_EQ(5U, start);
ASSERT_EQ(5U, end); EXPECT_EQ(5U, end);
ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); ui_test_utils::FocusView(browser(), VIEW_ID_TAB_CONTAINER);
ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
omnibox_view->GetSelectionBounds(&start, &end); omnibox_view->GetSelectionBounds(&start, &end);
ASSERT_EQ(0U, start); EXPECT_EQ(0U, start);
ASSERT_EQ(0U, end); EXPECT_EQ(0U, end);
} }
IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CtrlArrowAfterArrowSuggestions) { IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CtrlArrowAfterArrowSuggestions) {
......
...@@ -31,6 +31,9 @@ bool IsViewFocused(const Browser* browser, ViewID vid); ...@@ -31,6 +31,9 @@ bool IsViewFocused(const Browser* browser, ViewID vid);
// Simulates a mouse click on a View in the browser. // Simulates a mouse click on a View in the browser.
void ClickOnView(const Browser* browser, ViewID vid); void ClickOnView(const Browser* browser, ViewID vid);
// Makes focus shift to the given View without clicking it.
void FocusView(const Browser* browser, ViewID vid);
// A collection of utilities that are used from interactive_ui_tests. These are // A collection of utilities that are used from interactive_ui_tests. These are
// separated from ui_test_utils.h to ensure that browser_tests don't use them, // separated from ui_test_utils.h to ensure that browser_tests don't use them,
// since they depend on focus which isn't possible for sharded test. // since they depend on focus which isn't possible for sharded test.
......
...@@ -78,6 +78,14 @@ void ClickOnView(const Browser* browser, ViewID vid) { ...@@ -78,6 +78,14 @@ void ClickOnView(const Browser* browser, ViewID vid) {
content::RunMessageLoop(); content::RunMessageLoop();
} }
void FocusView(const Browser* browser, ViewID vid) {
NSWindow* window = browser->window()->GetNativeWindow();
DCHECK(window);
NSView* view = view_id_util::GetView(window, vid);
DCHECK(view);
[window makeFirstResponder:view];
}
void HideNativeWindow(gfx::NativeWindow window) { void HideNativeWindow(gfx::NativeWindow window) {
[window orderOut:nil]; [window orderOut:nil];
} }
......
...@@ -43,6 +43,13 @@ void ClickOnView(const Browser* browser, ViewID vid) { ...@@ -43,6 +43,13 @@ void ClickOnView(const Browser* browser, ViewID vid) {
content::RunMessageLoop(); content::RunMessageLoop();
} }
void FocusView(const Browser* browser, ViewID vid) {
views::View* view =
BrowserView::GetBrowserViewForBrowser(browser)->GetViewByID(vid);
DCHECK(view);
view->RequestFocus();
}
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
void MoveMouseToCenterAndPress(views::View* view, void MoveMouseToCenterAndPress(views::View* view,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment