Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / video_unittest.py
1 # Copyright 2014 The Chromium 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 import logging
6 import os
7 import unittest
8
9 from telemetry import benchmark
10 from telemetry.core import bitmap
11 from telemetry.core import platform
12 from telemetry.core import util
13 from telemetry.core import video
14
15
16 class VideoTest(unittest.TestCase) :
17
18   @benchmark.Disabled
19   def testFramesFromMp4(self):
20     host_platform = platform.GetHostPlatform()
21
22     try:
23       host_platform.InstallApplication('avconv')
24     finally:
25       if not host_platform.CanLaunchApplication('avconv'):
26         logging.warning('Test not supported on this platform')
27         return  # pylint: disable=W0150
28
29     vid = os.path.join(util.GetUnittestDataDir(), 'vid.mp4')
30     expected_timestamps = [
31       0,
32       763,
33       783,
34       940,
35       1715,
36       1732,
37       1842,
38       1926,
39       ]
40
41     video_obj = video.Video(vid)
42
43     # Calling _FramesFromMp4 should return all frames.
44     # pylint: disable=W0212
45     for i, timestamp_bitmap in enumerate(video_obj._FramesFromMp4(vid)):
46       timestamp, bmp = timestamp_bitmap
47       self.assertEquals(timestamp, expected_timestamps[i])
48       expected_bitmap = bitmap.Bitmap.FromPngFile(os.path.join(
49           util.GetUnittestDataDir(), 'frame%d.png' % i))
50       self.assertTrue(expected_bitmap.IsEqual(bmp))