Clean up visible test handling (including GTK tests).

This will be used for backgrounding (e.g., for runin).

BUG=None
TEST=Manual

Change-Id: Id5e7988f73285fc62407e2d36f15619421983250
Reviewed-on: https://gerrit.chromium.org/gerrit/26801
Tested-by: Jon Salz <jsalz@chromium.org>
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Jon Salz <jsalz@chromium.org>
Commit-Ready: Jon Salz <jsalz@chromium.org>
diff --git a/py/test/ui.py b/py/test/ui.py
index a3c4ef7..61d7f14 100755
--- a/py/test/ui.py
+++ b/py/test/ui.py
@@ -501,9 +501,11 @@
 
   def handle_event(event):
     if (event.type == Event.Type.STATE_CHANGE and
-      test_path and event.path == test_path and
-      event.state.visible):
-      show_window()
+      test_path and event.path == test_path):
+      if event.state.visible:
+        show_window()
+      else:
+        window.hide()
 
   event_client = EventClient(
       callback=handle_event, event_loop=EventClient.EVENT_LOOP_GOBJECT_IO)