• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5import dbus
6from dbus.mainloop.glib import DBusGMainLoop
7
8from autotest_lib.client.bin import test
9from autotest_lib.client.common_lib.cros import session_manager
10from autotest_lib.client.common_lib import error
11from autotest_lib.client.cros import cros_ui, cryptohome
12
13
14class login_SameSessionTwice(test.test):
15    """Ensure that the session_manager won't start the same session twice.
16    """
17    version = 1
18
19
20    def initialize(self):
21        super(login_SameSessionTwice, self).initialize()
22        cros_ui.restart()
23
24
25    def run_once(self):
26        bus_loop = DBusGMainLoop(set_as_default=True)
27        sm = session_manager.connect(bus_loop)
28
29        user = 'first_user@nowhere.com'
30        cryptohome.ensure_clean_cryptohome_for(user)
31
32        sm.StartSession(user, '')
33        try:
34            sm.StartSession(user, '')
35        except dbus.DBusException as d:
36            # If I knew how to get our custom dbus errors mapped into real
37            # exceptions in PyDBus, I'd use that here :-/
38            if 'already started a session' not in d.message:
39                raise error.TestFail(d)
40        else:
41            raise error.TestFail('Started second session for ' + user)
42
43
44    def cleanup(self):
45        # Bounce UI, without waiting for the browser to come back. Best effort.
46        cros_ui.stop(allow_fail=True)
47        cros_ui.start(allow_fail=True, wait_for_login_prompt=False)
48