• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6from dbus.mainloop.glib import DBusGMainLoop
7
8try:
9    from gi.repository import GObject
10except ImportError:
11    import gobject as GObject
12
13from autotest_lib.client.bin import test
14from autotest_lib.client.common_lib.cros import chrome, session_manager
15from autotest_lib.client.cros import asan
16
17
18class login_LoginSuccess(test.test):
19    """Sign in using Telemetry and validate system state."""
20    version = 1
21
22    _SESSION_START_TIMEOUT = 10
23    _SESSION_STOP_TIMEOUT = 60
24    # TODO(afakhry): Remove this timeout increase for asan bots once we figure
25    # out why logging out is taking so long. See crbug.com/488291
26    if asan.running_on_asan():
27        _SESSION_STOP_TIMEOUT *= 2
28
29
30    def initialize(self):
31        super(login_LoginSuccess, self).initialize()
32
33        bus_loop = DBusGMainLoop(set_as_default=True)
34        self._session_manager = session_manager.connect(bus_loop)
35        self._listener = session_manager.SessionSignalListener(
36                GObject.MainLoop())
37
38
39    def run_once(self,
40                 stress_run=False,
41                 arc_mode=None,
42                 username=None,
43                 password=None,
44                 dont_override_profile=False):
45        """
46        Runs the test.
47
48        @param stress_run: True if we are doing a stress run and want to
49                           double the timeout.
50        @param username: Username to use instead of the default telemetry one.
51        @param password: Password to use instead of the default telemetry one.
52        @param arc_mode: This value is passed to Chrome and determines how
53                         the ARC/Android instance should start. Possible values
54                         are defined in common_lib/cros/arc_common.py.
55        @dont_override_profile: Don't delete cryptohome before login.
56
57        """
58        if stress_run:
59            self._SESSION_STOP_TIMEOUT *= 2
60        self._listener.listen_for_session_state_change('started')
61        with chrome.Chrome(arc_mode=arc_mode,
62                           username=username,
63                           password=password,
64                           dont_override_profile=dont_override_profile):
65            self._listener.wait_for_signals(desc='Session started.',
66                                            timeout=self._SESSION_START_TIMEOUT)
67            # To enable use as a 'helper test'.
68            self.job.set_state('client_success', True)
69
70            # Start listening to stop signal before logging out.
71            self._listener.listen_for_session_state_change('stopped')
72
73        self._listener.wait_for_signals(desc='Session stopped.',
74                                        timeout=self._SESSION_STOP_TIMEOUT)
75