OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """FPS (frames per second) performance test for <video>. | |
7 | |
8 Calculates decoded fps and dropped fps while playing HTML5 media element. The | |
9 test compares results of playing a media file on different video resolutions. | |
10 """ | |
11 | |
12 import logging | |
13 import os | |
14 | |
15 import pyauto_media | |
16 import pyauto | |
17 import pyauto_utils | |
18 | |
19 # HTML test path; relative to src/chrome/test/data. | |
20 _TEST_HTML_PATH = os.path.join('media', 'html', 'media_fps_perf.html') | |
21 | |
22 # Path under data path for test files. | |
23 _TEST_MEDIA_PATH = os.path.join('pyauto_private', 'media', 'crowd') | |
24 | |
25 # The media files used for testing. The map is from the media file type to short | |
26 # file names. A perf graph is generated for each file type. | |
27 _TEST_VIDEOS = { | |
28 'webm': ['crowd2160', 'crowd1080', 'crowd720', 'crowd480', 'crowd360'] | |
29 } | |
30 | |
31 | |
32 def ToMbit(value): | |
33 """Converts a value of byte per sec units into Mbps units.""" | |
34 return float(value * 8) / (1024 * 1024) | |
35 | |
36 | |
37 class MediaFPSPerfTest(pyauto.PyUITest): | |
38 """PyAuto test container. See file doc string for more information.""" | |
39 | |
40 def testMediaFPSPerformance(self): | |
41 """Launches HTML test which plays each video and records statistics. | |
42 | |
43 For each video, the test plays till ended event is fired. It records decoded | |
44 fps, dropped fps, and total dropped frames. | |
45 """ | |
46 self.NavigateToURL(self.GetFileURLForDataPath(_TEST_HTML_PATH)) | |
47 | |
48 for ext, files in _TEST_VIDEOS.iteritems(): | |
49 for name in files: | |
50 file_url = self.GetFileURLForDataPath( | |
51 os.path.join(_TEST_MEDIA_PATH, '%s.%s' % (name, ext))) | |
52 logging.debug('Running fps perf test for %s.', file_url) | |
53 self.assertTrue(self.ExecuteJavascript("startTest('%s');" % file_url)) | |
54 decoded_fps = [float(value) for value in | |
55 self.GetDOMValue("decodedFPS.join(',')").split(',')] | |
56 dropped_frames = self.GetDOMValue('droppedFrames') | |
57 dropped_fps = [float(value) for value in | |
58 self.GetDOMValue("droppedFPS.join(',')").split(',')] | |
59 | |
60 pyauto_utils.PrintPerfResult('FPS_' + ext, name, decoded_fps, 'fps') | |
61 pyauto_utils.PrintPerfResult('Dropped_FPS_' + ext, name, dropped_fps, | |
62 'fps') | |
63 pyauto_utils.PrintPerfResult('Dropped_Frames_' + ext, name, | |
64 dropped_frames, 'frames') | |
65 | |
66 | |
67 if __name__ == '__main__': | |
68 pyauto_media.Main() | |
OLD | NEW |