1# Copyright (c) 2012 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
5from autotest_lib.client.bin import utils
6from autotest_lib.client.common_lib.cros import arc, chrome
7
8
9class power_UiResume(arc.ArcTest):
10    """
11    Suspend the system while simulating user behavior.
12
13    If ARC is present, open ARC before suspending. If ARC is not present, log
14    into Chrome before suspending. To suspend, call autotest power_Resume. This
15    reduces duplicate code, while cover all 3 cases: with ARC, with Chrome but
16    without ARC, and without Chrome.
17
18    """
19    version = 3
20
21    def initialize(self):
22        """
23        Entry point. Initialize ARC if it is enabled on the DUT, otherwise log
24        in Chrome browser.
25
26        """
27        self._arc_available = utils.is_arc_available()
28        if self._arc_available:
29            super(power_UiResume, self).initialize()
30        else:
31            self._chrome = chrome.Chrome()
32
33
34    def run_once(self, max_devs_returned=10, seconds=0,
35                 ignore_kernel_warns=False):
36        """
37        Run client side autotest power_Resume, to reduce duplicate code.
38
39        """
40        self.job.run_test(
41                'power_Resume',
42                max_devs_returned=max_devs_returned,
43                seconds=seconds,
44                ignore_kernel_warns=ignore_kernel_warns,
45                measure_arc=self._arc_available)
46
47
48    def cleanup(self):
49        """
50        Clean up ARC if it is enabled on the DUT, otherwise close the Chrome
51        browser.
52        """
53        if self._arc_available:
54            super(power_UiResume, self).cleanup()
55        else:
56            self._chrome.close()
57