Esempio n. 1
0
    def prepare_playback(self, file_path, fullscreen=True):
        """Copies the html file to /tmp and loads the webpage.

        @param file_path: The path to the file.
        @param fullscreen: Plays the video in fullscreen.

        """
        # Copies the html file to /tmp to make it accessible.
        utils.get_file(
                os.path.join(self.bindir, 'video.html'),
                '/tmp/playback_video.html')

        html_path = 'file:///tmp/playback_video.html'

        tab = self._resource._browser.tabs.New()
        tab.Navigate(html_path)
        self._player = native_html5_player.NativeHtml5Player(
                tab=tab,
                full_url=html_path,
                video_id='video',
                video_src_path=file_path)
        self._player.load_video()

        if fullscreen:
            self._display_facade.set_fullscreen(True)
    def run_once(self, video_file):
        """Tests whether Chrome reloads video after reloading the tab.

        @param video_file: fullpath to video to play.
        """
        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                init_network_controller=True) as cr:
            shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            tab = cr.browser.tabs[0]
            html_fullpath = os.path.join(self.bindir, 'video.html')
            url = cr.browser.platform.http_server.UrlOf(html_fullpath)
            player = native_html5_player.NativeHtml5Player(
                tab,
                full_url=url,
                video_id='video',
                video_src_path=video_file,
                event_timeout=30)
            player.load_video()
            player.play()
            player.verify_video_can_play(5)
            player.reload_page()
            player.load_video()
            player.play()
            player.verify_video_can_play(5)
    def run_once(self, video_file, arc_mode=False):
        """
        Tests whether the requested video is playable

        @param video_file: Sample video file to be played in Chrome.

        """
        blacklist = [
            # (board, arc_mode) # None means don't care
            ('x86-mario', None),
            ('x86-zgb', None),
            # The result on elm and oak is flaky in arc mode.
            # TODO(wuchengli): remove them once crbug.com/679864 is fixed.
            ('elm', True),
            ('oak', True)
        ]

        dut_board = utils.get_current_board()
        for (blacklist_board, blacklist_arc_mode) in blacklist:
            if blacklist_board == dut_board:
                if blacklist_arc_mode is None or blacklist_arc_mode == arc_mode:
                    logging.info("Skipping test run on this board.")
                    return
                break

        if arc_mode:
            arc_mode_str = arc_common.ARC_MODE_ENABLED
        else:
            arc_mode_str = arc_common.ARC_MODE_DISABLED
        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                arc_mode=arc_mode_str,
                init_network_controller=True) as cr:
            shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
            video_path = os.path.join(constants.CROS_VIDEO_DIR, 'files',
                                      video_file)
            shutil.copy2(video_path, self.bindir)
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            tab = cr.browser.tabs.New()
            html_fullpath = os.path.join(self.bindir, 'video.html')
            url = cr.browser.platform.http_server.UrlOf(html_fullpath)

            player = native_html5_player.NativeHtml5Player(
                tab,
                full_url=url,
                video_id='video',
                video_src_path=video_file,
                event_timeout=120)
            player.load_video()
            player.play()
            player.verify_video_can_play(constants.PLAYBACK_TEST_TIME_S)
Esempio n. 4
0
    def run_once(self, codec, is_mse, video_file, arc_mode=None):
        """
        Tests whether VDA works by verifying histogram for the loaded video.

        @param is_mse: bool, True if the content uses MSE, False otherwise.
        @param video_file: Sample video file to be loaded in Chrome.

        """
        if self.is_skipping_test(codec):
            raise error.TestNAError('Skipping test run on this board.')

        with chrome.Chrome(arc_mode=arc_mode,
                           init_network_controller=True) as cr:
            # This will execute for MSE video by accesing shaka player
            if is_mse:
                tab1 = cr.browser.tabs.New()
                tab1.Navigate(video_file)
                tab1.WaitForDocumentReadyStateToBeComplete()
                # Running the test longer to check errors and longer playback
                # for MSE videos.
                time.sleep(30)
            else:
                #This execute for normal video for downloading html file
                shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
                video_path = os.path.join(constants.CROS_VIDEO_DIR, 'files',
                                          video_file)
                shutil.copy2(video_path, self.bindir)

                cr.browser.platform.SetHTTPServerDirectories(self.bindir)
                tab = cr.browser.tabs.New()
                html_fullpath = os.path.join(self.bindir, 'video.html')
                url = cr.browser.platform.http_server.UrlOf(html_fullpath)

                player = native_html5_player.NativeHtml5Player(
                    tab,
                    full_url=url,
                    video_id='video',
                    video_src_path=video_file,
                    event_timeout=120)
                player.load_video()
                player.play()

            # Waits for histogram updated for the test video.
            histogram_verifier.verify(cr, constants.MEDIA_GVD_INIT_STATUS,
                                      constants.MEDIA_GVD_BUCKET)
Esempio n. 5
0
    def run_once(self, video_file, video_len, capability):
        """Verify VDA and playback for the video_file.

        @param video_file: test video file.
        @param video_len : test video file length.
        """
        device_capability.DeviceCapability().ensure_capability(capability)

        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                init_network_controller=True) as cr:
            init_status_differ = histogram_verifier.HistogramDiffer(
                cr, constants.MEDIA_GVD_INIT_STATUS)
            shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            tab1 = cr.browser.tabs[0]
            html_fullpath = os.path.join(self.bindir, 'video.html')
            url = cr.browser.platform.http_server.UrlOf(html_fullpath)
            logging.info("full url is %s", url)
            player = native_html5_player.NativeHtml5Player(
                tab1,
                full_url=url,
                video_id='video',
                video_src_path=video_file,
                event_timeout=120)
            player.load_video()
            player.play()

            # Verify the video playback.
            for i in range(1, video_len / 2):
                if (player.paused() or player.ended()):
                    raise error.TestError('Video either stopped or ended.')
                time.sleep(1)

            # Verify that video ends successfully.
            utils.poll_for_condition(
                lambda: player.ended(),
                timeout=video_len,
                exception=error.TestError('Video did not end successfully'),
                sleep_interval=1)

            # Make sure decode is hardware accelerated.
            histogram_verifier.expect_sole_bucket(init_status_differ,
                                                  constants.MEDIA_GVD_BUCKET,
                                                  'OK (0)')
    def run_once(self, video):
        """Tests whether Chrome handles corrupted videos gracefully.

        @param video: Sample corrupted video file to be played in Chrome.
        """
        with chrome.Chrome() as cr:
            shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            tab = cr.browser.tabs[0]
            html_fullpath = os.path.join(self.bindir, 'video.html')
            url = cr.browser.platform.http_server.UrlOf(html_fullpath)
            player = native_html5_player.NativeHtml5Player(
                tab,
                full_url=url,
                video_id='video',
                video_src_path=video,
                event_timeout=120)
            #This is a corrupted video, so it cann't load for checking canplay.
            player.load_video(wait_for_canplay=False)
            # Expect corruption being detected after loading corrupted video.
            player.wait_for_error()
    def run_once(self, video_file, video_len):
        """Verify VDA and playback for the video_file.

        @param video_file: test video file.
        @param video_len : test video file length.
        """

        with chrome.Chrome(init_network_controller=True) as cr:
            shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            tab1 = cr.browser.tabs[0]
            html_fullpath = os.path.join(self.bindir, 'video.html')
            url = cr.browser.platform.http_server.UrlOf(html_fullpath)
            logging.info("full url is %s", url)
            player = native_html5_player.NativeHtml5Player(
                tab1,
                full_url=url,
                video_id='video',
                video_src_path=video_file,
                event_timeout=120)
            player.load_video()
            player.play()
            # Waits for histogram updated for the test video.
            histogram_verifier.verify(cr, constants.MEDIA_GVD_INIT_STATUS,
                                      constants.MEDIA_GVD_BUCKET)

            # Verify the video playback.
            for i in range(1, video_len / 2):
                if (player.paused() or player.ended()):
                    raise error.TestError('Video either stopped or ended.')
                time.sleep(1)

            # Verify that video ends successfully.
            utils.poll_for_condition(
                lambda: player.ended(),
                timeout=video_len,
                exception=error.TestError('Video did not end successfully'),
                sleep_interval=1)
Esempio n. 8
0
    def run_once(self,
                 source_path,
                 codec,
                 resolution,
                 host,
                 args,
                 collect_only=False):

        board = utils.get_current_board()

        file_utils.make_leaf_dir(constants.TEST_DIR)

        with chrome.Chrome(
                extension_paths=[cros_constants.MULTIMEDIA_TEST_EXTENSION],
                autotest_ext=True) as cr:

            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            html_fullpath = os.path.join(self.bindir, 'video.html')
            player = native_html5_player.NativeHtml5Player(
                tab=cr.browser.tabs[0],
                full_url=cr.browser.platform.http_server.UrlOf(html_fullpath),
                video_id='video',
                video_src_path=source_path,
                event_timeout=120)

            chameleon_board = chameleon.create_chameleon_board(
                host.hostname, args)
            display_facade = local_facade_factory.LocalFacadeFactory(
                cr).create_display_facade()

            finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)

            capturer = chameleon_video_capturer.ChameleonVideoCapturer(
                finder.find_port(interface='hdmi'), display_facade)

            with capturer:
                player.load_video()

                player.verify_video_can_play()

                display_facade.move_to_display(
                    display_facade.get_first_external_display_index())
                display_facade.set_fullscreen(True)
                # HACK: Unset and reset fullscreen. There is a bug in Chrome
                # that fails to move the window to a correct position.
                # Resetting fullscren helps, check http://crbug.com/574284
                display_facade.set_fullscreen(False)
                display_facade.set_fullscreen(True)
                time.sleep(5)

                box = (0, 0, constants.DESIRED_WIDTH, constants.DESIRED_HEIGHT)

                #TODO: mussa, Revisit once crbug/580736 is fixed
                for n in xrange(constants.NUM_CAPTURE_TRIES):
                    logging.debug('Trying to capture frames. TRY #%d', n + 1)
                    raw_test_checksums = capturer.capture_only(
                        player, max_frame_count=constants.FCOUNT, box=box)

                    raw_test_checksums = [
                        tuple(checksum) for checksum in raw_test_checksums
                    ]

                    overreach_counts = self.overreach_frame_counts(
                        raw_test_checksums, constants.MAX_FRAME_REPEAT_COUNT)

                    if not overreach_counts:  # no checksums exceeded threshold
                        break

                    player.pause()
                    player.seek_to(datetime.timedelta(seconds=0))

                else:
                    msg = ('Framecount overreach detected even after %d '
                           'tries. Checksums: %s' %
                           (constants.NUM_CAPTURE_TRIES, overreach_counts))
                    raise error.TestFail(msg)

                # produces unique checksums mapped to their occur. indices
                test_checksum_indices = frame_checksum_utils.checksum_indices(
                    raw_test_checksums)

                test_checksums = test_checksum_indices.keys()

                test_indices = test_checksum_indices.values()

                golden_checksums_filepath = os.path.join(
                    constants.TEST_DIR, constants.GOLDEN_CHECKSUMS_FILENAME)

                if collect_only:
                    capturer.write_images(test_indices, constants.TEST_DIR,
                                          constants.IMAGE_FORMAT)

                    logging.debug("Write golden checksum file to %s",
                                  golden_checksums_filepath)

                    with open(golden_checksums_filepath, "w+") as f:
                        for checksum in test_checksums:
                            f.write(' '.join([str(i)
                                              for i in checksum]) + '\n')
                    return

                golden_checksums_remote_filepath = os.path.join(
                    constants.GOLDEN_CHECKSUM_REMOTE_BASE_DIR, board,
                    codec + '_' + resolution,
                    constants.GOLDEN_CHECKSUMS_FILENAME)

                file_utils.download_file(golden_checksums_remote_filepath,
                                         golden_checksums_filepath)

                golden_checksums = self.read_checksum_file(
                    golden_checksums_filepath)

                golden_checksum_count = len(golden_checksums)
                test_checksum_count = len(test_checksums)

                eps = constants.MAX_DIFF_TOTAL_FCOUNT
                if golden_checksum_count - test_checksum_count > eps:
                    msg = ('Expecting about %d checksums, received %d. '
                           'Allowed delta is %d') % (golden_checksum_count,
                                                     test_checksum_count, eps)
                    raise error.TestFail(msg)

                # Some frames might be missing during either golden frame
                # collection or during a test run. Using LCS ensures we
                # ignore a few missing frames while comparing test vs golden

                lcs_len = sequence_utils.lcs_length(golden_checksums,
                                                    test_checksums)

                missing_frames_count = len(golden_checksums) - lcs_len
                unknown_frames_count = len(test_checksums) - lcs_len

                msg = ('# of matching frames : %d. # of missing frames : %d. '
                       '# of unknown test frames : %d. Max allowed # of '
                       'missing frames : %d. # of golden frames : %d. # of '
                       'test_checksums : %d' %
                       (lcs_len, missing_frames_count,
                        unknown_frames_count, constants.MAX_NONMATCHING_FCOUNT,
                        len(golden_checksums), len(test_checksums)))
                logging.debug(msg)

                if (missing_frames_count + unknown_frames_count >
                        constants.MAX_NONMATCHING_FCOUNT):
                    unknown_frames = set(test_checksums) - set(
                        golden_checksums)

                    store_indices = [
                        test_checksum_indices[c] for c in unknown_frames
                    ]

                    paths = capturer.write_images(store_indices,
                                                  constants.TEST_DIR,
                                                  constants.IMAGE_FORMAT)

                    path_publish = publisher.ImageDiffPublisher(
                        self.resultsdir)
                    path_publish.publish_paths(paths, self.tagged_testname)

                    raise error.TestFail("Too many non-matching frames")
Esempio n. 9
0
    def run_once(self, codec, is_mse, video_file, arc_mode=None):
        """
        Tests whether VDA works by verifying histogram for the loaded video.

        @param is_mse: bool, True if the content uses MSE, False otherwise.
        @param video_file: Sample video file to be loaded in Chrome.

        """
        if self.is_skipping_test(codec):
            raise error.TestNAError('Skipping test run on this board.')

        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                arc_mode=arc_mode,
                init_network_controller=True) as cr:
            # This will execute for MSE video by accesing shaka player
            if is_mse:
                 tab1 = cr.browser.tabs.New()
                 tab1.Navigate(video_file)
                 tab1.WaitForDocumentReadyStateToBeComplete()
                 # Running the test longer to check errors and longer playback
                 # for MSE videos.
                 time.sleep(30)
            else:
                 #This execute for normal video for downloading html file
                 shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
                 video_path = os.path.join(constants.CROS_VIDEO_DIR,
                                           'files', video_file)
                 shutil.copy2(video_path, self.bindir)

                 cr.browser.platform.SetHTTPServerDirectories(self.bindir)
                 tab = cr.browser.tabs.New()
                 html_fullpath = os.path.join(self.bindir, 'video.html')
                 url = cr.browser.platform.http_server.UrlOf(html_fullpath)

                 player = native_html5_player.NativeHtml5Player(
                         tab,
                         full_url = url,
                         video_id = 'video',
                         video_src_path = video_file,
                         event_timeout = 120)
                 player.load_video()
                 player.play()
                 # Waits until the video ends or an error happens.
                 player.wait_ended_or_error()

            # Waits for histogram updated for the test video.
            histogram_verifier.verify(
                 cr,
                 constants.MEDIA_GVD_INIT_STATUS,
                 constants.MEDIA_GVD_BUCKET)

            # Verify no GPU error happens.
            if histogram_verifier.is_histogram_present(
                    cr,
                    constants.MEDIA_GVD_ERROR):
                logging.info(histogram_verifier.get_histogram(
                             cr, constants.MEDIA_GVD_ERROR))
                raise error.TestError('GPU Video Decoder Error.')

            # Verify the video ends successully for normal videos.
            if not is_mse and player.check_error():
                raise error.TestError('player did not end successully '\
                                      '(HTML5 Player Error %s: %s)'
                                      % player.get_error_info())