• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2010 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 logging, os, time
6from autotest_lib.client.bin import test, utils
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.cros import constants, cros_ui
9from autotest_lib.client.cros.graphics import graphics_utils
10
11class desktopui_GmailLatency(test.test):
12    version = 1
13
14    def run_once(self):
15        url = 'http://azlaba29.mtv.corp.google.com:9380/auto/google3/java/'\
16                'com/google/caribou/ui/pinto/modules/auto/tests/'\
17                'latencytest_auto.html'
18        js_expr = 'domAutomationController.send(!!window.G_testRunner'\
19                '&& window.G_testRunner.isFinished())'
20
21        # timeout is in ms, so allow a 5 minute timeout
22        # as of jan-11 it normally takes about 2 minutes on x86-mario
23        timeout = 5 * 60 * 1000
24
25        os.chdir(self.bindir)
26
27        # Select correct binary.
28        cpuType = utils.get_cpu_arch()
29        url_fetch_test = 'url_fetch_test'
30        if cpuType == "arm":
31            url_fetch_test += '.arm'
32
33        # Stop chrome from restarting and kill login manager.
34        try:
35            orig_pid = utils.system_output('pgrep %s' %
36                constants.SESSION_MANAGER)
37            open(constants.DISABLE_BROWSER_RESTART_MAGIC_FILE, 'w').close()
38        except IOError, e:
39            logging.debug(e)
40            raise error.TestError('Failed to disable browser restarting.')
41
42        # We could kill with signal 9 so that the session manager doesn't exit.
43        # But this seems to leave the screen blank while the test is running.
44        # So do it this way (which means clean_exit is always False)
45        utils.nuke_process_by_name(name=constants.BROWSER)
46
47        clean_exit = False
48        try:
49            time.sleep(1)
50            new_pid = utils.system_output('pgrep %s' %
51                constants.SESSION_MANAGER)
52            if orig_pid != new_pid:
53                # This is expected behaviour of the session manager.
54                pass
55
56            # Copy over chrome, chrome.pak, locales, chromeos needed for test.
57            utils.system('cp -r %s/* .' % '/opt/google/chrome')
58
59            # Setup parameters
60            params = ('--url="%s" --wait_js_expr="%s" --wait_js_timeout=%d' %
61                        (url, js_expr, timeout))
62            utils.system('./%s %s' % (url_fetch_test, params))
63
64        except error.CmdError, e:
65            logging.debug(e)
66            raise error.TestFail('Gmail Latency test was unsuccessful in %s'
67                                 % os.getcwd())
68
69        finally:
70            # Allow chrome to be restarted again.
71            os.unlink(constants.DISABLE_BROWSER_RESTART_MAGIC_FILE)
72
73            # Reset the UI but only if we need to (avoid double reset).
74            if not clean_exit:
75                cros_ui.nuke()
76