def run_once(self):
        """
        Runs the test.
        """
        dbus_loop = DBusGMainLoop(set_as_default=True)
        listener = session_manager.SessionSignalListener(gobject.MainLoop())
        listener.listen_for_session_state_change('started')

        logging.info('Logging in...')
        with chrome.Chrome(init_network_controller=True) as cr:
            # Check that Chrome asks session_manager to start a session.
            listener.wait_for_signals(
                desc=('SessionStateChanged "started" D-Bus signal from '
                      'session_manager'),
                timeout=self._SESSION_START_TIMEOUT_SEC)
            logging.info('Successfully logged in as "%s"', cr.username)

            # Check that the user's encrypted home directory was mounted.
            if not cryptohome.is_vault_mounted(user=cr.username,
                                               allow_fail=False):
                raise error.TestFail(
                    'Didn\'t find mounted cryptohome for "%s"' % cr.username)

            # Check that Chrome is able to load a web page.
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            url = cr.browser.platform.http_server.UrlOf(
                os.path.join(self.bindir, self._TEST_FILENAME))
            logging.info('Loading %s...', url)

            try:
                tab = cr.browser.tabs.New()
                tab.Navigate(url)
                tab.WaitForDocumentReadyStateToBeComplete()
                content = tab.EvaluateJavaScript(
                    'document.documentElement.innerText')
                if content != self._TEST_CONTENT:
                    raise error.TestFail(
                        'Expected page content "%s" but got "%s"' %
                        (self._TEST_CONTENT, content))
                logging.info('Saw expected content')
            except Exception as e:
                prefix = 'screenshot-%s' % time.strftime('%Y%m%d-%H%M%S')
                logging.info('Got exception; saving screenshot to %s/%s',
                             self._SCREENSHOT_DIR, prefix)
                if not os.path.exists(self._SCREENSHOT_DIR):
                    os.makedirs(self._SCREENSHOT_DIR)
                graphics_utils.take_screenshot(self._SCREENSHOT_DIR, prefix)

                if isinstance(e, error.TestFail):
                    raise e
                else:
                    raise error.TestFail(str(e))
Beispiel #2
0
    def take_graphics_utils_screenshot(self, screenshot_name):
        """
        Takes a screenshot of what is currently displayed.

        Uses the low level graphics_utils API.

        @param screenshot_name: Name of the screenshot.
        """
        try:
            full_filename = screenshot_name + '_graphics_utils'
            graphics_utils.take_screenshot(self.debugdir, full_filename)
        except StandardError as e:
            logging.warn('Screenshot using graphics_utils failed', exc_info = e)
        def can_take_screenshot():
            """Check that taking a screenshot can succeed.

            There are cases when trying to take a screenshot on the device
            fails. e.g. the display has gone to sleep, we have logged out and
            the UI has not come back up yet etc.
            """
            try:
                graphics_utils.take_screenshot(self.resultsdir,
                                               'temp screenshot', '.png')
                return True
            except:
                return False
    def test_something_on_screen(self):
        """Check if something is drawn on screen: i.e. not a black screen.

        @raises TestFail if we cannot determine there was something on screen.
        """
        def can_take_screenshot():
            """Check that taking a screenshot can succeed.

            There are cases when trying to take a screenshot on the device
            fails. e.g. the display has gone to sleep, we have logged out and
            the UI has not come back up yet etc.
            """
            try:
                graphics_utils.take_screenshot(self.resultsdir,
                                               'temp screenshot', '.png')
                return True
            except:
                return False

        utils.poll_for_condition(
            can_take_screenshot,
            sleep_interval=1,
            desc='Failed to take a screenshot. There may be an issue with this '
            'ChromeOS image.')

        w, h = graphics_utils.get_internal_resolution()
        megapixels = (w * h) / 1000000
        filesize_threshold = 25 * megapixels
        screenshot1 = graphics_utils.take_screenshot(self.resultsdir,
                                                     'oobe or signin', '.png')

        with chrome.Chrome() as cr:
            tab = cr.browser.tabs[0]
            tab.Navigate('chrome://settings')
            tab.WaitForDocumentReadyStateToBeComplete()

            screenshot2 = graphics_utils.take_screenshot(
                self.resultsdir, 'settings page', '.png')

        for screenshot in [screenshot1, screenshot2]:
            file_size_kb = os.path.getsize(screenshot) / 1000

            # Use compressed file size to tell if anything is on screen.
            if file_size_kb > filesize_threshold:
                return

        raise error.TestFail(
            'Screenshot filesize is very small. This indicates that '
            'there is nothing on screen. This ChromeOS image could be '
            'unusable. Check the screenshot in the results folder.')
    def _take_current_vt_screenshot(self, current_vt):
        """
        Captures a screenshot of the current VT screen in BMP format.

        @param current_vt: desired vt for screenshot.

        @returns the path of the screenshot file.

        """
        extension = 'bmp'

        # In VT1, X is running so use that screenshot function.
        if current_vt == 1:
            return graphics_utils.take_screenshot(self.resultsdir,
                                                  'graphics_VTSwitch_VT1',
                                                  extension)

        # Otherwise, take a screenshot using screenshot.py.
        prefix = 'graphics_VTSwitch_VT2'
        next_index = len(
            glob.glob(
                os.path.join(self.resultsdir,
                             '%s-*.%s' % (prefix, extension))))
        filename = '%s-%d.%s' % (prefix, next_index, extension)
        output_path = os.path.join(self.resultsdir, filename)
        return self._take_screenshot(output_path)
Beispiel #6
0
 def cleanup(self):
     """Autotest cleanup function"""
     if self._GSC:
         keyvals = self._GSC.get_memory_difference_keyvals()
         for key, val in keyvals.iteritems():
             self.output_perf_value(description=key,
                                    value=val,
                                    units='bytes',
                                    higher_is_better=False)
         self.write_perf_keyval(keyvals)
     super(bluetooth_TurnOnOffUI, self).cleanup()
     # If test fails then script will collect the screen shot to know at
     # which instance failure occurred.
     if not self.success:
         graphics_utils.take_screenshot(os.path.join(self.debugdir),
                                        "chrome")
    def _take_screenshot(self, suffix):
        """
        Captures a screenshot of the current VT screen in PNG format.

        @param suffixcurrent_vt: desired vt for screenshot.

        @returns the path of the screenshot file.

        """
        return graphics_utils.take_screenshot(self.resultsdir,
                                              suffix + '_tablet_mode')
    def _take_current_vt_screenshot(self, current_vt):
        """
        Captures a screenshot of the current VT screen in PNG format.

        @param current_vt: desired vt for screenshot.

        @returns the path of the screenshot file.

        """
        return graphics_utils.take_screenshot(
            self.resultsdir, 'graphics_VTSwitch_VT%d' % current_vt)
    def take_screenshot(self, screenshot_name):
        """
        Takes a screenshot of what is currently displayed in png format.

        The screenshot is stored in /tmp. Uses the low level graphics_utils API.

        @param screenshot_name: Name of the screenshot file.
        @returns The path to the screenshot or None.
        """
        try:
            return graphics_utils.take_screenshot('/tmp', screenshot_name)
        except Exception as e:
            logging.warning('Taking screenshot failed', exc_info=e)
            return None
    def _take_current_vt_screenshot(self):
        """
        Captures a screenshot of the current VT screen in BMP format.
        Returns the path of the screenshot file.
        """
        current_vt = int(utils.system_output('fgconsole'))
        extension = 'bmp'

        # In VT1, X is running so use that screenshot function.
        if current_vt == 1:
            return graphics_utils.take_screenshot(self.resultsdir,
                                                  'graphics_VTSwitch_VT1',
                                                  extension)

        # Otherwise, grab the framebuffer using DRM.
        prefix = 'graphics_VTSwitch_VT2'
        next_index = len(
            glob.glob(
                os.path.join(self.resultsdir,
                             '%s-*.%s' % (prefix, extension))))
        filename = '%s-%d.%s' % (prefix, next_index, extension)
        output_path = os.path.join(self.resultsdir, filename)
        return self._take_drm_screenshot(output_path)
 def _take_screenshot(self, name):
     try:
         graphics_utils.take_screenshot(self.resultsdir, name)
     except:
         logging.info('Failed to take screenshot')