Focus is returned from modal dialogs to parent window in WebUI after user is logged in.

BUG=None
TEST=LoginControllerTest.FocusTransientParentWebUILoggedIn

Change-Id: I6bf1a6ab999a1a174b5a8f33e860cc548f747de0
Reviewed-on: http://gerrit.chromium.org/gerrit/7537
Reviewed-by: Ivan Korotkov <ivankr@chromium.org>
Tested-by: Ivan Korotkov <ivankr@chromium.org>
diff --git a/login/login_controller.cc b/login/login_controller.cc
index 90dbfa0..689bbcb 100644
--- a/login/login_controller.cc
+++ b/login/login_controller.cc
@@ -383,7 +383,7 @@
     non_login_xids_.erase(*non_login_it);
     registrar_.UnregisterForWindowEvents(win->xid());
 
-    if (win->IsFocused() && !wm_->logged_in()) {
+    if (win->IsFocused() && (!wm_->logged_in() || webui_window_)) {
       // If the window was transient, pass the focus to its owner (as long
       // as it's not the background window, which we never want to receive
       // the focus); otherwise just focus the previously-focused login
diff --git a/login/login_controller_test.cc b/login/login_controller_test.cc
index d4d5f8e..7d54cc9 100644
--- a/login/login_controller_test.cc
+++ b/login/login_controller_test.cc
@@ -578,6 +578,29 @@
   EXPECT_EQ(entries_[0].controls_xid, GetActiveWindowProperty());
 }
 
+// Test that focus behaviour is preserved after the user has logged in when we
+// are performing a WebUI based login.
+TEST_F(LoginControllerTest, FocusTransientParentWebUILoggedIn) {
+  CreateWebUILoginWindow();
+  SetLoggedInState(true);
+
+  // When we open a transient dialog, it should get the focus.
+  const XWindow transient_xid = CreateSimpleWindow();
+  MockXConnection::WindowInfo* transient_info =
+      xconn_->GetWindowInfoOrDie(transient_xid);
+  transient_info->transient_for = webui_window_xid_;
+  SendInitialEventsForWindow(transient_xid);
+  EXPECT_EQ(transient_xid, xconn_->focused_xid());
+  EXPECT_EQ(transient_xid, GetActiveWindowProperty());
+
+  // If we unmap that dialog, the focus should go back to the WebUI window.
+  XEvent event;
+  xconn_->InitUnmapEvent(&event, transient_xid);
+  wm_->HandleEvent(&event);
+  EXPECT_EQ(webui_window_xid_, xconn_->focused_xid());
+  EXPECT_EQ(webui_window_xid_, GetActiveWindowProperty());
+}
+
 TEST_F(LoginControllerTest, Modality) {
   CreateLoginWindows(2, true, true, false);
   const XWindow controls_xid = entries_[0].controls_xid;