Home | History | Annotate | Download | only in login_LoginSuccess
      1 # Copyright (c) 2013 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
      6 from dbus.mainloop.glib import DBusGMainLoop
      7 
      8 from autotest_lib.client.bin import test
      9 from autotest_lib.client.common_lib.cros import chrome, session_manager
     10 from autotest_lib.client.cros import asan
     11 
     12 
     13 class login_LoginSuccess(test.test):
     14     """Sign in using Telemetry and validate system state."""
     15     version = 1
     16 
     17     _SESSION_START_TIMEOUT = 10
     18     _SESSION_STOP_TIMEOUT = 60
     19     # TODO(afakhry): Remove this timeout increase for asan bots once we figure
     20     # out why logging out is taking so long. See crbug.com/488291
     21     if asan.running_on_asan():
     22       _SESSION_STOP_TIMEOUT *= 2
     23 
     24 
     25     def initialize(self):
     26         super(login_LoginSuccess, self).initialize()
     27 
     28         bus_loop = DBusGMainLoop(set_as_default=True)
     29         self._session_manager = session_manager.connect(bus_loop)
     30         self._listener = session_manager.SessionSignalListener(
     31                 gobject.MainLoop())
     32 
     33 
     34     def run_once(self, stress_run=False, arc_mode=None):
     35         """
     36         Runs the test.
     37 
     38         @param stress_run: True if we are doing a stress run and want to
     39                            double the timeout.
     40         @param arc_mode: This value is passed to Chrome and determines how
     41                          the ARC/Android instance should start. Possible values
     42                          are defined in common_lib/cros/arc_common.py.
     43 
     44         """
     45         if stress_run:
     46             self._SESSION_STOP_TIMEOUT *= 2
     47         self._listener.listen_for_session_state_change('started')
     48         with chrome.Chrome(arc_mode=arc_mode):
     49             self._listener.wait_for_signals(desc='Session started.',
     50                                             timeout=self._SESSION_START_TIMEOUT)
     51             # To enable use as a 'helper test'.
     52             self.job.set_state('client_success', True)
     53 
     54             # Start listening to stop signal before logging out.
     55             self._listener.listen_for_session_state_change('stopped')
     56 
     57         self._listener.wait_for_signals(desc='Session stopped.',
     58                                         timeout=self._SESSION_STOP_TIMEOUT)
     59