Enable interactive_ui_tests

 * changed DCHECK in tree_node_model to make it easy to find how it failed.
 * Fixed compilation error in find_bar_host_interactive_uitest.cc on linux/views.
 * Disabled BrowserKeyEventsTest.AccessKeys for Chromeos
   Added/Changed ui_test_utils::RunAllPendingInMessageLoop where necessary.
 * Disabled tab_dragging_tests. I included the source so that we can catch
   compilation error even if tests do not run. Changed the comment from // -> /*
   as GCC complains the use of "\" (and potentially dangerous)
 * Added SleepInMessageLoop to allow event loop to execute the tasks/events
   while waiting.
 * For RunAllPendingInMessageLoop change, please see
   http://codereview.chromium.org/1591004

BUG=39736
TEST=interactive_ui_tests should pass with following cls
http://codereview.chromium.org/1594003
http://codereview.chromium.org/1545011.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43701 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index 47bace1..77008e8 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -4,6 +4,7 @@
 
 #include "build/build_config.h"
 
+#include "base/format_macros.h"
 #include "base/message_loop.h"
 #include "base/ref_counted.h"
 #include "chrome/browser/automation/ui_controls.h"
@@ -401,7 +402,9 @@
   focused_browser->window()->Activate();
 
   // Wait for the focus to be stolen by the other browser.
-  PlatformThread::Sleep(2000);
+  MessageLoop::current()->PostDelayedTask(
+      FROM_HERE, new MessageLoop::QuitTask(), 2000);
+  ui_test_utils::RunMessageLoop();
 
   // Make sure the first browser is still active.
   EXPECT_TRUE(focused_browser->window()->IsActive());
@@ -452,11 +455,13 @@
 
   // Test forward focus traversal.
   for (int i = 0; i < 3; ++i) {
+    SCOPED_TRACE(StringPrintf("outer loop: %d", i));
     // Location bar should be focused.
     ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
 
     // Now let's press tab to move the focus.
     for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) {
+      SCOPED_TRACE(StringPrintf("inner loop %" PRIuS, j));
       // Let's make sure the focus is on the expected element in the page.
       std::string actual;
       ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
@@ -481,16 +486,18 @@
     // At this point the renderer has sent us a message asking to advance the
     // focus (as the end of the focus loop was reached in the renderer).
     // We need to run the message loop to process it.
-    MessageLoop::current()->RunAllPending();
+    ui_test_utils::RunAllPendingInMessageLoop();
   }
 
   // Now let's try reverse focus traversal.
   for (int i = 0; i < 3; ++i) {
+    SCOPED_TRACE(StringPrintf("outer loop: %d", i));
     // Location bar should be focused.
     ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
 
     // Now let's press shift-tab to move the focus in reverse.
     for (size_t j = 0; j < 7; ++j) {
+      SCOPED_TRACE(StringPrintf("inner loop: %" PRIuS, j));
       ASSERT_TRUE(ui_controls::SendKeyPress(window, base::VKEY_TAB,
                                             false, true, false));
 
@@ -515,7 +522,7 @@
     // At this point the renderer has sent us a message asking to advance the
     // focus (as the end of the focus loop was reached in the renderer).
     // We need to run the message loop to process it.
-    MessageLoop::current()->RunAllPending();
+    ui_test_utils::RunAllPendingInMessageLoop();
   }
 }
 
@@ -577,7 +584,7 @@
     // At this point the renderer has sent us a message asking to advance the
     // focus (as the end of the focus loop was reached in the renderer).
     // We need to run the message loop to process it.
-    MessageLoop::current()->RunAllPending();
+    ui_test_utils::RunAllPendingInMessageLoop();
   }
 
   // Now let's try reverse focus traversal.
@@ -605,7 +612,7 @@
     // At this point the renderer has sent us a message asking to advance the
     // focus (as the end of the focus loop was reached in the renderer).
     // We need to run the message loop to process it.
-    MessageLoop::current()->RunAllPending();
+    ui_test_utils::RunAllPendingInMessageLoop();
   }
 }
 
@@ -702,6 +709,9 @@
 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) {
   // 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));
 
   // Open the new tab, focus should be on the location bar.
@@ -724,6 +734,9 @@
 
   // Open the new tab, reload.
   browser()->NewTab();
+
+  ui_test_utils::RunAllPendingInMessageLoop();
+
   browser()->Reload();
   ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
   // Focus should stay on the location bar.
diff --git a/chrome/browser/browser_keyevents_browsertest.cc b/chrome/browser/browser_keyevents_browsertest.cc
index cf23cba..e7c9ba0 100644
--- a/chrome/browser/browser_keyevents_browsertest.cc
+++ b/chrome/browser/browser_keyevents_browsertest.cc
@@ -134,8 +134,8 @@
   void SendKey(base::KeyboardCode key, bool control, bool shift, bool alt) {
     gfx::NativeWindow window = NULL;
     ASSERT_NO_FATAL_FAILURE(GetNativeWindow(&window));
-    ui_controls::SendKeyPressNotifyWhenDone(window, key, control, shift, alt,
-                                            new MessageLoop::QuitTask());
+    EXPECT_TRUE(ui_controls::SendKeyPressNotifyWhenDone(
+        window, key, control, shift, alt, new MessageLoop::QuitTask()));
     ui_test_utils::RunMessageLoop();
   }
 
@@ -447,7 +447,14 @@
   EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlEnter));
 }
 
-IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) {
+#if defined(OS_CHROMEOS)
+// See http://crbug.com/40037 for details.
+#define MAYBE_AccessKeys DISABLED_AccessKeys
+#else
+#define MAYBE_AccessKeys AccessKeys
+#endif
+
+IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_AccessKeys) {
   static const KeyEventTestData kTestAltA = {
     base::VKEY_A, false, false, true,
     false, false, false, false, 4,
@@ -487,6 +494,7 @@
   GURL url = server->TestServerPageW(kTestingPage);
   ui_test_utils::NavigateToURL(browser(), url);
 
+  ui_test_utils::RunAllPendingInMessageLoop();
   ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
   ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
 
diff --git a/chrome/browser/views/find_bar_host_interactive_uitest.cc b/chrome/browser/views/find_bar_host_interactive_uitest.cc
index 0b66cc9..e0819e6 100644
--- a/chrome/browser/views/find_bar_host_interactive_uitest.cc
+++ b/chrome/browser/views/find_bar_host_interactive_uitest.cc
@@ -53,9 +53,17 @@
 
   int GetFocusedViewID() {
 #if defined(TOOLKIT_VIEWS)
+#if defined(OS_LINUX)
+    // See http://crbug.com/26873 .
+    views::FocusManager* focus_manager =
+        views::FocusManager::GetFocusManagerForNativeView(
+            GTK_WIDGET(browser()->window()->GetNativeHandle()));
+#else
     views::FocusManager* focus_manager =
         views::FocusManager::GetFocusManagerForNativeView(
             browser()->window()->GetNativeHandle());
+#endif
+
     if (!focus_manager) {
       NOTREACHED();
       return -1;
@@ -135,7 +143,7 @@
   browser()->Find();
   EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, GetFocusedViewID());
   ui_test_utils::FindInPage(browser()->GetSelectedTabContents(),
-                            L"a", true, false, NULL);
+                            ASCIIToUTF16("a"), true, false, NULL);
   browser()->GetFindBarController()->EndFindSession(
       FindBarController::kKeepSelection);
   EXPECT_EQ(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW, GetFocusedViewID());
diff --git a/chrome/browser/views/tabs/tab_dragging_test.cc b/chrome/browser/views/tabs/tab_dragging_test.cc
index 0fb56cef..f7f3d0b 100644
--- a/chrome/browser/views/tabs/tab_dragging_test.cc
+++ b/chrome/browser/views/tabs/tab_dragging_test.cc
@@ -18,6 +18,19 @@
 #include "net/base/net_util.h"
 #include "views/event.h"
 
+#if defined(OS_CHROMEOS)
+// Disabled, see http://crbug.com/40043.
+#define MAYBE_Tab2OutOfTabStrip DISABLED_Tab2OutOfTabStrip
+#define MAYBE_Tab1Tab3Escape DISABLED_Tab1Tab3Escape
+
+#else
+#define MAYBE_Tab2OutOfTabStrip Tab2OutOfTabStrip
+
+// Flaky, see http://crbug.com/21092.
+#define MAYBE_Tab1Tab3Escape FLAKY_Tab1Tab3Escape
+
+#endif
+
 
 class TabDraggingTest : public UITest {
 protected:
@@ -92,16 +105,18 @@
   EXPECT_LT(0, urlbar_bounds.width());
   EXPECT_LT(0, urlbar_bounds.height());
 
-  // TEST: Move Tab_1 to the position of Tab_2
-  //   ____________   ____________   ____________
-  //  /            \ /            \ /            \
-  // |    Tab_1     |     Tab_2    |    Tab_3     |
-  //  ---- ---- ---- ---- ---- ---- ---- ---- ----
-  //         x---- ---->
-  //              ____________
-  //             /     X      \
-  //            |    Tab_1     |
-  //             ---- ---- ----
+  /*
+    TEST: Move Tab_1 to the position of Tab_2
+     ____________   ____________   ____________
+    /            \ /            \ /            \
+   |    Tab_1     |     Tab_2    |    Tab_3     |
+    ---- ---- ---- ---- ---- ---- ---- ---- ----
+           x---- ---->
+                ____________
+               /     X      \
+              |    Tab_1     |
+               ---- ---- ----
+  */
 
   gfx::Point start(bounds1.x() + bounds1.width() / 2,
                    bounds1.y() + bounds1.height() / 2);
@@ -190,16 +205,18 @@
   EXPECT_LT(0, urlbar_bounds.width());
   EXPECT_LT(0, urlbar_bounds.height());
 
-  // TEST: Move Tab_1 to the middle position of Tab_3
-  //   ____________   ____________   ____________
-  //  /            \ /            \ /            \
-  // |    Tab_1     |     Tab_2    |    Tab_3     |
-  //  ---- ---- ---- ---- ---- ---- ---- ---- ----
-  //         x---- ---- ---- ---- ---- ---->
-  //                                  ____________
-  //                                 /     X      \
-  //                                |    Tab_1     |
-  //                                 ---- ---- ----
+  /*
+   TEST: Move Tab_1 to the middle position of Tab_3
+     ____________   ____________   ____________
+    /            \ /            \ /            \
+   |    Tab_1     |     Tab_2    |    Tab_3     |
+    ---- ---- ---- ---- ---- ---- ---- ---- ----
+           x---- ---- ---- ---- ---- ---->
+                                    ____________
+                                   /     X      \
+                                  |    Tab_1     |
+                                   ---- ---- ----
+  */
 
   gfx::Point start(bounds1.x() + bounds1.width() / 2,
                    bounds1.y() + bounds1.height() / 2);
@@ -233,8 +250,7 @@
 
 // Drag Tab_1 into the position of Tab_3, and press ESCAPE before releasing the
 // left mouse button.
-// Flaky, see http://crbug.com/21092.
-TEST_F(TabDraggingTest, FLAKY_Tab1Tab3Escape) {
+TEST_F(TabDraggingTest, MAYBE_Tab1Tab3Escape) {
   scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
   ASSERT_TRUE(browser.get());
   scoped_refptr<WindowProxy> window(browser->GetWindow());
@@ -297,16 +313,18 @@
   EXPECT_LT(0, urlbar_bounds.width());
   EXPECT_LT(0, urlbar_bounds.height());
 
-  // TEST: Move Tab_1 to the middle position of Tab_3
-  //   ____________   ____________   ____________
-  //  /            \ /            \ /            \
-  // |    Tab_1     |     Tab_2    |    Tab_3     |
-  //  ---- ---- ---- ---- ---- ---- ---- ---- ----
-  //         x---- ---- ---- ---- ---- ----> + ESCAPE
-  //                                  ____________
-  //                                 /     X      \
-  //                                |    Tab_1     |
-  //                                 ---- ---- ----
+  /*
+   TEST: Move Tab_1 to the middle position of Tab_3
+     ____________   ____________   ____________
+    /            \ /            \ /            \
+   |    Tab_1     |     Tab_2    |    Tab_3     |
+    ---- ---- ---- ---- ---- ---- ---- ---- ----
+           x---- ---- ---- ---- ---- ----> + ESCAPE
+                                    ____________
+                                   /     X      \
+                                  |    Tab_1     |
+                                   ---- ---- ----
+  */
 
   gfx::Point start(bounds1.x() + bounds1.width() / 2,
                    bounds1.y() + bounds1.height() / 2);
@@ -343,7 +361,7 @@
 }
 
 // Drag Tab_2 out of the Tab strip. A new window should open with this tab.
-TEST_F(TabDraggingTest, Tab2OutOfTabStrip) {
+TEST_F(TabDraggingTest, MAYBE_Tab2OutOfTabStrip) {
   scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
   ASSERT_TRUE(browser.get());
   scoped_refptr<WindowProxy> window(browser->GetWindow());
@@ -411,24 +429,26 @@
   EXPECT_LT(0, urlbar_bounds.width());
   EXPECT_LT(0, urlbar_bounds.height());
 
-  // TEST: Move Tab_2 down, out of the tab strip.
-  // This should result in the following:
-  //  1- Tab_3 shift left in place of Tab_2 in Window 1
-  //  2- Tab_1 to remain in its place
-  //  3- Tab_2 openes in a new window
-  //
-  //   ____________   ____________   ____________
-  //  /            \ /            \ /            \
-  // |    Tab_1     |     Tab_2    |    Tab_3     |
-  //  ---- ---- ---- ---- ---- ---- ---- ---- ----
-  //                       x
-  //                       |
-  //                       |  (Drag this below, out of tab strip)
-  //                       V
-  //                  ____________
-  //                 /     X      \
-  //                |    Tab_2     |   (New Window)
-  //                ---- ---- ---- ---- ---- ---- ----
+  /*
+   TEST: Move Tab_2 down, out of the tab strip.
+   This should result in the following:
+    1- Tab_3 shift left in place of Tab_2 in Window 1
+    2- Tab_1 to remain in its place
+    3- Tab_2 openes in a new window
+
+     ____________   ____________   ____________
+    /            \ /            \ /            \
+    |    Tab_1     |     Tab_2    |    Tab_3     |
+    ---- ---- ---- ---- ---- ---- ---- ---- ----
+                         x
+                         |
+                         |  (Drag this below, out of tab strip)
+                         V
+                    ____________
+                   /     X      \
+                  |    Tab_2     |   (New Window)
+                  ---- ---- ---- ---- ---- ---- ----
+  */
 
   gfx::Point start(bounds2.x() + bounds2.width() / 2,
                    bounds2.y() + bounds2.height() / 2);