Chromium Code Reviews| Index: chrome/browser/ui/search/instant_extended_browsertest.cc |
| diff --git a/chrome/browser/ui/search/instant_extended_browsertest.cc b/chrome/browser/ui/search/instant_extended_browsertest.cc |
| index 981ce6a0f8bb5ae7dca867f80b7098ae1311a202..90d3e322bb477e6ed8783958d09fd2492e68d30c 100644 |
| --- a/chrome/browser/ui/search/instant_extended_browsertest.cc |
| +++ b/chrome/browser/ui/search/instant_extended_browsertest.cc |
| @@ -118,6 +118,16 @@ class InstantExtendedTest : public InProcessBrowserTest, |
| &on_change_calls_); |
| } |
| + // A convenience function to explicitly blur the omnibox and focus |contents|. |
| + // TODO(msw|jered|sreeram): Fix test focus issues; see http://crbug.com/226189 |
| + void BlurOmniboxAndFocusContents(content::WebContents* contents) { |
| + omnibox()->model()->OnWillKillFocus(contents->GetView()->GetNativeView()); |
| + omnibox()->model()->OnKillFocus(); |
| + contents->GetView()->Focus(); |
| + EXPECT_FALSE(omnibox()->model()->has_focus()); |
| + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| + } |
| + |
| int on_most_visited_change_calls_; |
| int most_visited_items_count_; |
| int first_most_visited_item_id_; |
| @@ -171,12 +181,9 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { |
| IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { |
| ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| - // Explicitly unfocus the omnibox. |
| - EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
|
Jered
2013/04/05 16:27:07
The new code does not do this. Is it unnecessary?
msw
2013/04/05 16:39:02
I suspect not if the test didn't break, but I rest
|
| - ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| - |
| - EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| - EXPECT_FALSE(omnibox()->model()->has_focus()); |
| + // Blur the omnibox and focus the active web contents. |
| + BlurOmniboxAndFocusContents( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| // Delete any existing overlay. |
| instant()->overlay_.reset(); |
| @@ -202,9 +209,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { |
| EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
| // Unfocusing and refocusing the omnibox should also preserve the overlay. |
| - ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| - EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| - |
| + BlurOmniboxAndFocusContents( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| FocusOmnibox(); |
| EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
| @@ -367,15 +373,13 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| browser()->window()->GetLocationBar()->AcceptInput(); |
| observer.Wait(); |
| - // With a committed results page, do a search by unfocusing the omnibox and |
| - // focusing the contents. |
| + // With a committed results page, do a search by bluring the omnibox and |
|
Jered
2013/04/05 16:27:07
bluring -> blurring
msw
2013/04/05 16:39:02
Done.
|
| + // focusing the contents. Call handleOnChange before focusing the contents. |
| SetOmniboxText("hello"); |
| - // Calling handleOnChange manually to make sure it is called before the |
| - // Focus() call below. |
| EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), |
| "suggestion = 'hello kitty';" |
| "handleOnChange();")); |
| - instant()->instant_tab()->contents()->GetView()->Focus(); |
| + BlurOmniboxAndFocusContents(instant()->instant_tab()->contents()); |
| // Search term extraction should kick in with the autocompleted text. |
| EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText()); |
| @@ -412,7 +416,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';" |
| "behavior = 2;" |
| "handleOnChange();")); |
| - instant()->overlay()->contents()->GetView()->Focus(); |
| + BlurOmniboxAndFocusContents(instant()->overlay()->contents()); |
| EXPECT_EQ(ASCIIToUTF16("exams are great"), omnibox()->GetText()); |
| // TODO(jered): Remove this after fixing OnBlur(). |
| @@ -645,10 +649,9 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) { |
| ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| FocusOmniboxAndWaitForInstantExtendedSupport(); |
| - // Explicitly unfocus the omnibox. |
| - EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
|
Jered
2013/04/05 16:27:07
Same question here.
msw
2013/04/05 16:39:02
Done.
|
| - ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| - EXPECT_FALSE(omnibox()->model()->has_focus()); |
| + // Explicitly blur the omnibox. |
| + BlurOmniboxAndFocusContents( |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| // Open new tab. Preloaded NTP contents should have been used. |
| ui_test_utils::NavigateToURLWithDisposition( |