Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: chrome/test/functional/media_test_matrix.py

Issue 6673078: Initial checkin of media test matrix class, which will be used for media perf test later. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Capitalize method names. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import csv
8 import random
9
10 VIDEO_TEST_MATRIX_HOME = 'http://tskir-html5.kir.corp.google.com/testmatrix/'
Nirnimesh 2011/03/17 02:32:00 Do not reference internal URLs in public scripts.
imasaki1 2011/03/17 23:29:18 Done.
11 NOT_AVAILABLE_STRING = 'not available'
12
13
14 class MediaTestMatrix:
15 """This class reads video matrix file and present them in different
16 format.
dennis_jeffrey 2011/03/17 17:13:36 The first line of this class docstring should be a
imasaki1 2011/03/17 23:29:18 Done.
17 """
18 # Video extensions such as "webm".
19 exts = []
20 # video specifications or video descriptions.
dennis_jeffrey 2011/03/17 17:13:36 Capitalize "v" in "video"
imasaki1 2011/03/17 23:29:18 Done.
21 specs = {}
22 # Video titles such as "bear".
23 video_titles = []
dennis_jeffrey 2011/03/17 17:13:36 Are the above lists meant to be public attributes?
imasaki1 2011/03/17 23:29:18 I made them private instance variables.
24
25 def ReadData(self, csv_file):
26 """Reads CSV file and stores in list specs and extensions instance
27 variables.
dennis_jeffrey 2011/03/17 17:13:36 This should be a 1-line summary of this method.
imasaki1 2011/03/17 23:29:18 Done.
28
29 CSV file should have the following format:
30 "ext","title1","title2",....
31 "0.webm","description1","descrption2","not available"(when it is available)
32
33 This CSV file based on javaScripts file in videotestmatrix
34 http://tskir-html5.kir.corp.google.com/testmatrix/index.html
dennis_jeffrey 2011/03/17 17:13:36 As Nirnimesh said, we should not reference interna
imasaki1 2011/03/17 23:29:18 Removed.
35
36 video files are stored less than and equal to 15th row
37 audio files are stored more then 15th row
dennis_jeffrey 2011/03/17 17:13:36 Capitalize the start of each sentence and put peri
imasaki1 2011/03/17 23:29:18 Done.
38 Args:
39 csv_file : CSV file name contains video matrix information described
40 above
dennis_jeffrey 2011/03/17 17:13:36 Put period at the end of this sentence.
imasaki1 2011/03/17 23:29:18 Done.
41 """
42 reader = csv.reader(open(csv_file, 'rb'))
43 counter = 0
44 for row in reader:
dennis_jeffrey 2011/03/17 17:13:36 I think you can do: for counter, row in enumerate
imasaki1 2011/03/17 23:29:18 Done.
45 if counter == 0:
46 # First row is for header (video titles).
47 for title in row[1:]:
48 self.video_titles.append(title)
49 self.specs[title] = []
50 else:
51 self.exts.append(row[0])
52 for i in range(len(row)-1):
53 self.specs[self.video_titles[i]].append(row[i + 1])
dennis_jeffrey 2011/03/17 17:13:36 It might be good to do some kind of error checking
imasaki1 2011/03/17 23:29:18 Done.
54 counter += 1
55
56 def GenerateMediaInfo(self, sub_type, name):
57 """Generate media information from matrix generated by CSV file.
58
59 Args:
60 sub_type: index of the extensions (rows in the CSV file)
61 name: the name of the video file (column name in the CSV file)
dennis_jeffrey 2011/03/17 17:13:36 Put periods at the end of each sentence in the abo
imasaki1 2011/03/17 23:29:18 Done.
62 Returns:
dennis_jeffrey 2011/03/17 17:13:36 Put a blank line before this line.
imasaki1 2011/03/17 23:29:18 Done.
63 a tuple of (info, URL, link, tag, is_video, nickname)
dennis_jeffrey 2011/03/17 17:13:36 "URL" --> "url" (or else, in line 65 below, chang
imasaki1 2011/03/17 23:29:18 Done.
64 info: description of the video (an entry in the matrix)
65 url: URL of the video or audio
66 link: href tag for video or audio
67 is_video: True if the file is video; False otherwise
68 tag: a tag string can be used to display video or audio
69 nickname: nickname of the video for presentation
dennis_jeffrey 2011/03/17 17:13:36 Put periods at the end of each sentence.
imasaki1 2011/03/17 23:29:18 Done.
70 """
71 if name is "none":
72 return
73 cur_video = name
74 # all videos are placed up to the rows (below 15th row)
dennis_jeffrey 2011/03/17 17:13:36 Capitalize the start of each sentence and put peri
imasaki1 2011/03/17 23:29:18 Done.
75 is_video = (sub_type <= self.__GetMaxValue(True))
dennis_jeffrey 2011/03/17 17:13:36 I don't think the parens around the right-hand sid
imasaki1 2011/03/17 23:29:18 Done.
76 file = cur_video + "/" + cur_video + self.exts[sub_type]
dennis_jeffrey 2011/03/17 17:13:36 When generating a path string, it's safer to use "
imasaki1 2011/03/17 23:29:18 Done.
77 # specs were generated from CSV file
78 info = self.specs[cur_video][sub_type]
79 url = VIDEO_TEST_MATRIX_HOME + file
80 link = ''.join(["<b><a href='", VIDEO_TEST_MATRIX_HOME,
81 file, "'>", file, '</a>&nbsp;&nbsp;', info, '</b>'])
dennis_jeffrey 2011/03/17 17:13:36 Is there a reason you're creating the string this
imasaki1 2011/03/17 23:29:18 Done.
82 tag = ''
83 if is_video:
84 tag = ''.join(["<video id='v' controls autoplay ",
85 "playbackRate=1 loop valign=top src='", file, "'>"])
86 else:
87 tag = ''.join(["<audio id='v' controls autoplay ",
88 "playbackRate=1 loop valign=top src='", file, "'>"])
dennis_jeffrey 2011/03/17 17:13:36 Lines 83-88: the only difference between these two
imasaki1 2011/03/17 23:29:18 Done.
89 nickname = cur_video + self.exts[sub_type]
90 return (info, url, link, tag, is_video, nickname)
91
92 def __GetMaxValue(self, video_only):
93 """Get maximum index value of exts for video or audio
94
95 Args:
96 video_only: True if the max value is for video
97 Returns:
dennis_jeffrey 2011/03/17 17:13:36 Put blank line before this line.
imasaki1 2011/03/17 23:29:18 Done.
98 the max index value of exts for video or audio
99 """
100 if video_only:
101 return 15
dennis_jeffrey 2011/03/17 17:13:36 The 15 should probably be defined as a named const
imasaki1 2011/03/17 23:29:18 Done.
102 else:
103 # max index is the size of the directory
104 return len(self.exts)-1
dennis_jeffrey 2011/03/17 17:13:36 A shorter way to implement this function: return
imasaki1 2011/03/17 23:29:18 Done.
105
106 def GenerateRandomMediaInfo(self, video_only):
107 """Generate random video info can be used for playing this media.
dennis_jeffrey 2011/03/17 17:13:36 "info can" --> "info that can"?
imasaki1 2011/03/17 23:29:18 Done.
108
109 Args:
110 video_only: True if generate random video only
111 Returns:
112 a list of a tuples (info, url, link, tag, is_video, nickname)
113 info: description of the video (an entry in the matrix)
114 url: URL of the video/audio
115 link: href tag for video or audio
116 tag: a tag string can be used to display video or audio
117 is_video: True if the file is video; False otherwise
118 nickname: nickname of the video for presentation
119 """
120 # Try 10 times to find avaialble video/audio.
121 for i in range(10):
dennis_jeffrey 2011/03/17 17:13:36 Maybe the value 10 should be an input to this func
imasaki1 2011/03/17 23:29:18 Done.
122 sub_type = random.randint(0, self.GetMaxValue(video_only))
123 name = self.video_titles[random.randint(0, len(self.video_titles)-1)]
124 (info, url, link, tag, is_video) = self.GenerateMediaInfo(sub_type, name)
125 if "not available" not in info:
dennis_jeffrey 2011/03/17 17:13:36 Use "NOT_AVAILABLE_STRING".
imasaki1 2011/03/17 23:29:18 Done.
126 return (info, url, link, tag, is_video, nickname)
127 # Gives up after that (very small chance)
128 return None
129
130 def GenerateAllMediaInfos(self, video_only):
131 """Generate all video infos that can be used for playing this media.
132
133 Args:
134 video_only: True if generate random video only (not audio)
135 Returns:
136 a list of a tuples (info, url, link, tag, is_video, nickname)
137 info: description of the video (an entry in the matrix)
138 url: URL of the video/audio
139 is_video: True if the file is video; False otherwise
140 nickname: nickname of the video for presentation (such as bear.webm)
141 """
142 video_infos = []
143
144 for i in range(0, len(self.video_titles)-1):
145 name = self.video_titles[i]
146 for sub_type in range(self._GetMaxValue(video_only)):
147 (info, url, link, tag,
148 is_video, nickname) = self.GenerateMediaInfo(sub_type, name)
149 if NOT_AVAILABLE_STRING not in info:
150 video_infos.append([info, url, link, tag, is_video, nickname])
151 return video_infos
152
153 def GenerateAllMediaInfosInCompactForm(self, video_only):
154 """Generate all video info can be used for playing this media
155 (in compact form).
dennis_jeffrey 2011/03/17 17:13:36 Summary line should fit on one line.
imasaki1 2011/03/17 23:29:18 Done.
156
157 Args:
158 video_only: True if generate random video only
159 Returns:
160 a list of a tuples (url, nickname, tag)
161 url: URL of the video/audio
162 nickname: nickname of the video/audio for presentation
163 (such as bear.webm)
164 tag: HTML5 tag for the video/audio
165 """
166 video_infos = []
167 for i in range(0, len(self.video_titles)-1):
168 name = self.video_titles[i]
169 for sub_type in range(self.__GetMaxValue(video_only)):
170 (info, url, link, tag,
171 is_video, nickname) = self.GenerateMediaInfo(sub_type, name)
172 if is_video:
173 tag = 'video'
174 else:
175 tag = 'audio'
dennis_jeffrey 2011/03/17 17:13:36 Lines 172-175: tag = ['audio', 'video'][is_video]
imasaki1 2011/03/17 23:29:18 Done.
176 if NOT_AVAILABLE_STRING not in info:
177 video_infos.append([url, nickname, tag])
178 return video_infos
179
180 @staticmethod
181 def LookForMediaInfoByNickName(compact_list, target):
182 """Look for video by its nickname in the compact_list.
183
184 Args:
185 compact_list: list generated by bgenerateAllMediaInfosInCompactForm
dennis_jeffrey 2011/03/17 17:13:36 "bgenerateAllMediaInfosInCompactForm" --> "Generat
imasaki1 2011/03/17 23:29:18 Done.
186 target: taget nickname
Nirnimesh 2011/03/17 02:32:00 need a blank line before Returns: Repeat for all
imasaki1 2011/03/17 23:29:18 Done.
187 Returns:
188 A tuple (info, url, link, tag, is_video, nickname) where nickname
189 is target
190 url: URL of the video/audio
191 tag: HTML5 tag for the video/audio
192 nickname: nickname of the video/audio for presentation
193 (such as bear.webm)
194 """
195 for l in compact_list:
196 [url, nickname, tag] = l
Nirnimesh 2011/03/17 02:32:00 You can use: for url, nickname, tag in compact_li
imasaki1 2011/03/17 23:29:18 Done.
197 if(target == nickname):
Nirnimesh 2011/03/17 02:32:00 remove parens
imasaki1 2011/03/17 23:29:18 Done.
198 return l
dennis_jeffrey 2011/03/17 17:13:36 This should only be indented 2 spaces underneath t
imasaki1 2011/03/17 23:29:18 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698