Home | History | Annotate | Download | only in desktopui_ExitOnSupervisedUserCrash
      1 # Copyright 2014 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import gobject, logging
      6 from dbus.exceptions import DBusException
      7 from dbus.mainloop.glib import DBusGMainLoop
      8 
      9 from autotest_lib.client.bin import test, utils
     10 from autotest_lib.client.common_lib import error
     11 from autotest_lib.client.common_lib.cros import chrome, session_manager
     12 from autotest_lib.client.cros import constants
     13 
     14 
     15 class desktopui_ExitOnSupervisedUserCrash(test.test):
     16     """Sign in, indicate that a supervised user is being created, then crash."""
     17     version = 1
     18 
     19     _SESSION_STOP_TIMEOUT = 60
     20 
     21 
     22     def initialize(self):
     23         super(desktopui_ExitOnSupervisedUserCrash, self).initialize()
     24 
     25 
     26     def run_once(self, arc_mode=None):
     27         listener = session_manager.SessionSignalListener(gobject.MainLoop())
     28         with chrome.Chrome(arc_mode=arc_mode):
     29             sm = session_manager.connect(DBusGMainLoop(set_as_default=True))
     30             # Tell session_manager that we're going all the way through
     31             # creating a supervised user.
     32             sm.HandleSupervisedUserCreationStarting()
     33             sm.HandleSupervisedUserCreationFinished()
     34             # Crashing the browser should not end the session, as creating the
     35             # user is finished.
     36             utils.nuke_process_by_name(constants.BROWSER)
     37 
     38             # We should still be able to talk to the session_manager,
     39             # and it should indicate that we're still inside a user session.
     40             try:
     41                 state = sm.RetrieveSessionState()
     42             except DBusException as e:
     43                 raise error.TestError('Failed to retrieve session state: ', e)
     44             if state != 'started':
     45                 raise error.TestFail('Session should not have ended: ', state)
     46 
     47             # Start listening to stop signal before the session gets killed.
     48             listener.listen_for_session_state_change('stopped')
     49 
     50             # Tell session_manager that a supervised user is being set up,
     51             # and kill it in the middle. Session should die.
     52             sm.HandleSupervisedUserCreationStarting()
     53             nuke_browser_error = None
     54             try:
     55                 utils.nuke_process_by_name(constants.BROWSER)
     56             except error.AutoservPidAlreadyDeadError as e:
     57                 nuke_browser_error = e
     58                 logging.warning('Browser may have crashed untimely: ', e)
     59 
     60             try:
     61                 listener.wait_for_signals(desc='Session stopped.',
     62                                           timeout=self._SESSION_STOP_TIMEOUT)
     63             except utils.TimeoutError as actual_problem:
     64                 if nuke_browser_error is not None:
     65                     actual_problem = nuke_browser_error
     66                 raise error.TestFail(actual_problem)
     67