autotest: Wait for login to finish before logging out.

This makes login.attempt_logout() call
wait_for_initial_chrome_window() before asking the session
manager to stop the session.  I'm hoping that this will
avoid a bunch of Chrome and window manager crashes that
we've seen when the UI job is stopped soon after it's been
started.

BUG=chromium-os:17899,chromium-os:18269
TEST=ran suite_Smoke a few times without seeing any chrome crashes (i was seeing them consistently in login_CryptohomeMounted and login_CryptohomeUnmounted before)

Change-Id: I80d3d6aaa0db5b7a12f973d114270a7f23d324a1
Reviewed-on: http://gerrit.chromium.org/gerrit/5797
Reviewed-by: Dave Moore <davemoore@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-on: http://gerrit.chromium.org/gerrit/6022
Reviewed-by: Daniel Erat <derat@chromium.org>
diff --git a/client/cros/login.py b/client/cros/login.py
index 193363f..c1ab275 100644
--- a/client/cros/login.py
+++ b/client/cros/login.py
@@ -183,6 +183,13 @@
     if not logged_in():
         raise UnexpectedCondition('Already logged out')
 
+    # We've seen a steady stream of crashes within Chrome and chromeos-wm when
+    # the UI job is stopped while those processes are still getting initialized
+    # (a situation which doesn't seem to happen in production).  We wait for the
+    # window manager to report that the first Chrome window has shown up before
+    # tearing things down to reduce the likelihood of problems.
+    wait_for_initial_chrome_window()
+
     # Log what we're about to do to /var/log/messages. Used to log crashes later
     # in cleanup by cros_ui_test.UITest.
     utils.system('logger "%s"' % LOGOUT_ATTEMPT_MSG)