1# Copyright 2016 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
6import os
7
8from PIL import Image
9
10from autotest_lib.client.bin import test, utils
11from autotest_lib.client.common_lib import error
12from autotest_lib.client.common_lib.cros import chrome
13
14
15_SCREENSHOT_PATH = '/tmp/screenshot.png'
16
17
18class desktopui_MashLogin(test.test):
19    """Verifies chrome --mash starts up and logs in correctly."""
20    version = 1
21
22
23    def __screen_visual_sanity_test(self):
24        """Capture the screen and sanity check it (more than 5 colors)."""
25        try:
26            utils.run('screenshot "%s"' % _SCREENSHOT_PATH)
27            image = Image.open(_SCREENSHOT_PATH)
28        except Exception as e:
29            logging.warning('Unable to capture screenshot. %s', e)
30            return
31
32        # If colors in |image| is less than _MAX_COLORS, PIL.Image.getcolors
33        # returns a list of colors. If colors is more than _MAX_COLORS, it
34        # returns None. Expect None because the login screen should contain
35        # more than _MAX_COLORS.
36        _MAX_COLORS = 5
37        if image.getcolors(maxcolors=_MAX_COLORS) is not None:
38            image.save(os.path.join(self.resultsdir,
39                                    'bad_mash_login_screenshot.png'))
40            raise error.TestFail('Mash login screen does not look right.')
41
42
43    def run_once(self):
44        """Entry point of this test."""
45
46        # Flaky on nyan_* boards. http://crbug.com/717275
47        boards_to_skip = ['nyan_big', 'nyan_kitty', 'nyan_blaze']
48        if utils.get_current_board() in boards_to_skip:
49          logging.warning('Skipping test run on this board.')
50          return
51
52        # GPU info collection via devtools SystemInfo.getInfo does not work
53        # under mash due to differences in how the GPU process is configured
54        # with mus hosting viz. http://crbug.com/669965
55        mash_browser_args = ['--enable-features=Mash',
56                             '--disable-features=SingleProcessMash',
57                             '--gpu-no-complete-info-collection']
58
59        logging.info('Testing Chrome with Mash startup.')
60        with chrome.Chrome(auto_login=False, extra_browser_args=mash_browser_args):
61            logging.info('Chrome with Mash started and loaded OOBE.')
62            self.__screen_visual_sanity_test()
63
64        logging.info('Testing Chrome with Mash login.')
65        with chrome.Chrome(extra_browser_args=mash_browser_args):
66            logging.info('Chrome login with Mash succeeded.')
67