• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 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 time
7
8from autotest_lib.server import test
9from autotest_lib.client.bin import utils
10from autotest_lib.client.common_lib import error
11from autotest_lib.client.cros.chameleon import chameleon_port_finder
12from autotest_lib.client.cros.chameleon import chameleon_screen_test
13from autotest_lib.server.cros.multimedia import remote_facade_factory
14
15
16class display_CheckModesAfterSignOutSignIn(test.test):
17    """ To Check the modes after sign out/sign in"""
18    version = 1
19    KEY_DELAY = 1
20
21    def logout(self):
22        """Log out the User"""
23        logging.info("Signing out")
24
25        # Pressing the keys twice to logout
26        self.input_facade.press_keys(['KEY_LEFTCTRL', 'KEY_RIGHTSHIFT',
27                                      'KEY_Q'])
28        time.sleep(self.KEY_DELAY)
29        self.input_facade.press_keys(['KEY_LEFTCTRL', 'KEY_RIGHTSHIFT',
30                                      'KEY_Q'])
31
32    def is_logged_out(self):
33        """Will check whether user logged out"""
34        logging.debug("checking /home/chronos/user/Downloads/ to know "
35                      "whether user logged out or not!")
36        return self.host.path_exists('/home/chronos/user/Downloads/') is False
37
38    def check_mode(self, test_mirrored_mode=True):
39        """Checks the display mode is as expected
40
41        @param test_mirrored: True if mirror mode
42        @raise error.TestFail if the display mode is not preserved.
43        """
44        logging.info("Is Mirrored mode enabled?: %s",
45                     self.display_facade.is_mirrored_enabled())
46        if self.display_facade.is_mirrored_enabled() != test_mirrored_mode:
47            raise error.TestFail('Display mode %s is not preserved!' %
48                                 ('mirrored' if test_mirrored_mode
49                                     else 'extended'))
50
51    def check_external_display(self, test_mirrored):
52        """Display status check
53
54        @param test_mirrored: True if mirror mode
55        """
56
57        # Check connector
58        if self.screen_test.check_external_display_connected(
59                self.connector_used, self.errors) is None:
60
61            # Check mode is same as beginning of the test
62            self.check_mode(test_mirrored)
63
64            # Check test image
65            resolution = self.chameleon_port.get_resolution()
66            self.screen_test.test_screen_with_image(
67                    resolution, test_mirrored, self.errors)
68
69    def run_test_on_port(self, chameleon_port, test_mirrored):
70        """Run the test on the given Chameleon port.
71
72        @param chameleon_port: a ChameleonPorts object.
73        @param test_mirrored: True if mirror mode
74        @raise error.TestFail if any display errors
75        """
76        self.chameleon_port = chameleon_port
77        self.screen_test = chameleon_screen_test.ChameleonScreenTest(
78                self.host, chameleon_port, self.display_facade, self.outputdir)
79
80        # Get connector type used (HDMI,DP,...)
81        self.connector_used = self.display_facade.get_external_connector_name()
82
83        # Set main display mode for the test
84        logging.info("Setting Mirrored display mode")
85        self.display_facade.set_mirrored(test_mirrored)
86        self.logout()
87        utils.poll_for_condition(
88                self.is_logged_out,
89                exception=error.TestFail('User is not logged out'),
90                sleep_interval=1)
91        logging.info("Restarting the chrome again!")
92        self.browser_facade.start_default_chrome(restart=True)
93        logging.info("Checking the external display mode and image!")
94        self.check_external_display(test_mirrored)
95        if self.errors:
96            raise error.TestFail('; '.join(set(self.errors)))
97
98    def run_once(self, host, test_mirrored=True):
99        """Checks the mode is preserved after logout
100
101        @param host: DUT object
102        @param test_mirrored: True if mirror mode
103        """
104        self.host = host
105        self.errors = list()
106        chameleon_board = host.chameleon
107        factory = remote_facade_factory.RemoteFacadeFactory(
108                self.host, results_dir=self.resultsdir)
109        self.display_facade = factory.create_display_facade()
110        self.browser_facade = factory.create_browser_facade()
111        self.input_facade = factory.create_input_facade()
112        chameleon_board.setup_and_reset(self.outputdir)
113        finder = chameleon_port_finder.ChameleonVideoInputFinder(
114                chameleon_board, self.display_facade)
115
116        # Iterates all connected video ports and ensures every of them plugged
117        for chameleon_port in finder.iterate_all_ports():
118            self.run_test_on_port(chameleon_port, test_mirrored)
119