Rehabilitate BrowserFocusTest.TabInitialFocus

BUG=50763
TEST=interactive_ui_tests --gtest_filter=BrowserFocusTest.TabInitialFocus

Review URL: http://codereview.chromium.org/3561013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61735 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index 4558c90..ea679674 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -705,27 +705,33 @@
 
 // Makes sure the focus is in the right location when opening the different
 // types of tabs.
-// Flaky, http://crbug.com/50763.
-IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_TabInitialFocus) {
+IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) {
   ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
 
   // Open the history tab, focus should be on the tab contents.
   browser()->ShowHistoryTab();
-  ui_test_utils::RunAllPendingInMessageLoop();
-  ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
+  ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
+      &browser()->GetSelectedTabContents()->controller()));
+  EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
 
   // Open the new tab, focus should be on the location bar.
   browser()->NewTab();
-  ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
+  ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
+      &browser()->GetSelectedTabContents()->controller()));
+  EXPECT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
 
   // Open the download tab, focus should be on the tab contents.
   browser()->ShowDownloadsTab();
-  ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
+  ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
+      &browser()->GetSelectedTabContents()->controller()));
+  EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
 
   // Open about:blank, focus should be on the location bar.
   browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL),
                                    PageTransition::LINK);
-  ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
+  ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
+      &browser()->GetSelectedTabContents()->controller()));
+  EXPECT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
 }
 
 // Tests that focus goes where expected when using reload.