Home | History | Annotate | Download | only in display_SwitchMode
      1 # Copyright 2014 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 
      5 """This is test switching the external display mode."""
      6 
      7 import logging, time
      8 
      9 from autotest_lib.client.common_lib import error
     10 from autotest_lib.client.cros.chameleon import chameleon_port_finder
     11 from autotest_lib.client.cros.chameleon import chameleon_screen_test
     12 from autotest_lib.server import test
     13 from autotest_lib.server.cros.multimedia import remote_facade_factory
     14 
     15 
     16 class display_SwitchMode(test.test):
     17     """External Display switch between extended and mirrored modes.
     18 
     19     This test switches the external display mode between extended
     20     and mirrored modes, and checks resolution and static test image.
     21     """
     22     version = 1
     23     WAIT_AFTER_SWITCH = 5
     24 
     25     def check_external_display(self, test_mirrored):
     26         """Display status check
     27 
     28         @param test_mirrored: is mirrored mode active
     29 
     30         """
     31         resolution = self.display_facade.get_external_resolution()
     32         # Check connector
     33         if self.screen_test.check_external_display_connected(
     34                 self.connector_used, self.errors) is None:
     35             # Check test image
     36             self.screen_test.test_screen_with_image(
     37                     resolution, test_mirrored, self.errors)
     38         if self.errors:
     39             raise error.TestFail('; '.join(set(self.errors)))
     40 
     41 
     42     def set_mode_and_check(self, test_mirrored, no_check):
     43         """Sets display mode and checks status
     44 
     45         @param test_mirrored: is mirrored mode active
     46         @param no_check: True to skip the screen check.
     47         """
     48         logging.info('Set mirrored: %s', test_mirrored)
     49         self.display_facade.set_mirrored(test_mirrored)
     50         if not no_check:
     51             time.sleep(self.WAIT_AFTER_SWITCH)
     52             self.check_external_display(test_mirrored)
     53 
     54 
     55     def run_once(self, host, repeat, no_check=False):
     56         if not host.get_board_type() == 'CHROMEBOOK':
     57             raise error.TestNAError('DUT is not Chromebook. Test Skipped')
     58 
     59         factory = remote_facade_factory.RemoteFacadeFactory(host)
     60         self.display_facade = factory.create_display_facade()
     61         chameleon_board = host.chameleon
     62 
     63         chameleon_board.setup_and_reset(self.outputdir)
     64         finder = chameleon_port_finder.ChameleonVideoInputFinder(
     65                 chameleon_board, self.display_facade)
     66 
     67         self.errors = []
     68         for chameleon_port in finder.iterate_all_ports():
     69             self.chameleon_port = chameleon_port
     70             self.screen_test = chameleon_screen_test.ChameleonScreenTest(
     71                     chameleon_port, self.display_facade, self.outputdir)
     72 
     73             logging.debug('See the display on Chameleon: port %d (%s)',
     74                          self.chameleon_port.get_connector_id(),
     75                          self.chameleon_port.get_connector_type())
     76             # Keep the original connector name, for later comparison.
     77             self.connector_used = (
     78                     self.display_facade.get_external_connector_name())
     79 
     80             for i in xrange(repeat):
     81                 logging.info("Iteration %d", (i + 1))
     82                 self.set_mode_and_check(True, no_check)
     83                 self.set_mode_and_check(False, no_check)
     84