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

Unified 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: Updates based on CR comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/functional/media_test_matrix.py
diff --git a/chrome/test/functional/media_test_matrix.py b/chrome/test/functional/media_test_matrix.py
new file mode 100644
index 0000000000000000000000000000000000000000..5018c2822de99a60e01486d38f4c98dd6c8e1c52
--- /dev/null
+++ b/chrome/test/functional/media_test_matrix.py
@@ -0,0 +1,223 @@
+#!/usr/bin/python
+
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import csv
+import os
+import random
+
+NOT_AVAILABLE_STRING = 'not available'
+MAX_VIDEO_INDEX = 15
+
+
+class MediaTestMatrix:
+ """This class reads video test matrix file and stores them.
+
+ Video test matrix contains different video titles as column and different
+ video codec (such as "webm" as columns. The matrix entry contains video
+ specification such as "320x240 50 fps VP8 / no audio 1 MBit/s PSNR 36.70"
+ or "not available". It also provides methods to generate information based
+ on the client's needs. For example, "video" tag or "audio" tag is returned
+ based on what kinds of media it is. This matrix is for managing different
+ kinds of media files in media testing.
+ """
+ # Video extensions such as "webm".
+ __exts = []
+ # Video specification dictionary or video descriptions.
+ # The key is extentions.
+ __specs = {}
+ # Video titles such as "bear".
+ __video_titles = []
+
+ def ReadData(self, csv_file):
+ """Reads CSV file and stores in list specs and extensions.
+
+ CSV file should have the following format:
+ "ext","title1","title2",....
+ "0.webm", "description1","descrption2", "not available" (when it is not
+ available).
+
+ Video files are stored less than and equal to 15th row.
+ Audio files are stored more then 15th row.
dennis_jeffrey 2011/03/18 17:47:50 "more then" --> "more than"
imasaki1 2011/03/18 21:54:25 Removed since we use video/audio tag.
+ Args:
dennis_jeffrey 2011/03/18 17:47:50 Put a blank line right before the "Args:" line.
imasaki1 2011/03/18 21:54:25 Done.
+ csv_file : CSV file name contains video matrix information described
+ above.
dennis_jeffrey 2011/03/18 17:47:50 Since this function raises csv.Error in line 68 be
imasaki1 2011/03/18 21:54:25 Done.
+ """
+ # Clean up all data.
+ self.__exts = []
+ self.__specs = {}
+ self.__video_titles = []
+ file = open(csv_file, 'rb')
+ reader = csv.reader(file)
+ for counter, row in enumerate(reader):
+ if counter == 0:
+ # First row is comment
+ pass
+ if counter == 1:
dennis_jeffrey 2011/03/18 17:47:50 "if" --> "elif"
imasaki1 2011/03/18 21:54:25 Done.
+ # Second row is for header (video titles).
+ for title in row[1:]:
+ self.__video_titles.append(title)
+ self.__specs[title] = []
+ else:
+ # Error checking is done here based on the number of titles
+ if len(self.__video_titles) != len(row) - 1:
+ print "Row %d should have %d columns but have %d columns" % (counter,
dennis_jeffrey 2011/03/18 17:47:50 "but have" --> "but has"
imasaki1 2011/03/18 21:54:25 Done.
+ len(self.__video_titles), len(row))
+ raise csv.Error
+ # First column should contain extension.
+ self.__exts.append(row[0])
+ for i in range(len(row)-1):
+ self.__specs[self.__video_titles[i]].append(row[i + 1])
+ file.close()
+
+ def __GenerateMediaInfo(self, sub_type, name, media_test_matrix_home_url):
+ """Generate media information from matrix generated by CSV file.
+
+ Args:
+ sub_type: index of the extensions (rows in the CSV file).
+ name: the name of the video file (column name in the CSV file).
+ media_test_matrix_home_url: url of the matrix home that used
+ to generate link.
+
+ Returns:
+ a tuple of (info, url, link, tag, is_video, nickname).
+ info: description of the video (an entry in the matrix).
+ url: URL of the video or audio.
+ link: href tag for video or audio.
+ is_video: True if the file is video; False otherwise.
+ tag: a tag string can be used to display video or audio.
dennis_jeffrey 2011/03/18 17:47:50 Put the line for "tag" above the line for "is_vide
imasaki1 2011/03/18 21:54:25 Done.
+ nickname: nickname of the video for presentation.
+ """
+ if name is "none":
dennis_jeffrey 2011/03/18 17:47:50 Use single quotes instead of double quotes here.
imasaki1 2011/03/18 21:54:25 Done.
+ return
+ cur_video = name
+ # All videos are placed up to the rows (below 15th row).
dennis_jeffrey 2011/03/18 17:47:50 # All videos are placed up to row MAX_VIDEO_INDEX.
imasaki1 2011/03/18 21:54:25 Removed since we are not using MAX_VIDEO_INDEX any
+ is_video = sub_type <= self.__GetMaxValue(True)
+ file = os.path.join(cur_video, cur_video + self.__exts[sub_type])
+ # Specs were generated from CSV file in readFile().
+ info = self.__specs[cur_video][sub_type]
+ url = media_test_matrix_home_url + file
+ link = '<b><a href="%s">%s</a>&nbsp;&nbsp;%s</b>' % (url, file, info)
+ type = ['audio', 'video'][is_video]
+ tag_attr = "id='v' controls autoplay playbackRate=1 loop valign=top"
dennis_jeffrey 2011/03/18 17:47:50 Please use single quotes to surround the outer str
imasaki1 2011/03/18 21:54:25 Done.
+ tag = "<%s %s src='%s'>" % (type, tag_attr, file)
dennis_jeffrey 2011/03/18 17:47:50 Same comment as line 104 above.
imasaki1 2011/03/18 21:54:25 Done.
+ nickname = cur_video + self.__exts[sub_type]
+ return (info, url, link, tag, is_video, nickname)
+
+ def __GetMaxValue(self, video_only):
+ """Get maximum index value of exts for video or audio.
+
+ Args:
+ video_only: True if the max value is for video.
+
+ Returns:
+ the max index value of exts for video or audio.
+ """
+ return [len(self.__exts) - 1, MAX_VIDEO_INDEX][video_only]
+
+ def GenerateRandomMediaInfo(self, number_of_tries=10, video_only=False,
+ video_matrix_home_url=''):
+ """Generate random video info that can be used for playing this media.
+
+ Args:
+ video_only: True if generate random video only.
+ media_test_matrix_home_url: url of the matrix home that used
+ to generate link.
+
+ Returns:
+ a list of a tuples (info, url, link, tag, is_video, nickname).
+ info: description of the video (an entry in the matrix).
+ url: URL of the video/audio.
+ link: href tag for video or audio.
+ tag: a tag string can be used to display video or audio.
+ is_video: True if the file is video; False otherwise.
+ nickname: nickname of the video for presentation.
+ """
+ # Try number_of_tries times to find avaialble video/audio.
dennis_jeffrey 2011/03/18 17:47:50 "avaialble" --> "available"
imasaki1 2011/03/18 21:54:25 Done.
+ for i in range(number_of_tries):
+ sub_type = random.randint(0, self.__GetMaxValue(video_only))
+ name = self.__video_titles[random.randint(0, len(self.__video_titles)-1)]
+ (info, url, link, tag,
+ is_video, nickname) = self.__GenerateMediaInfo(sub_type,
+ name,
+ video_matrix_home_url)
dennis_jeffrey 2011/03/18 17:47:50 I think lines 143-145 might look better like this:
imasaki1 2011/03/18 21:54:25 Changed as well as other places.
+ if NOT_AVAILABLE_STRING not in info:
+ return (info, url, link, tag, is_video, nickname)
dennis_jeffrey 2011/03/18 17:47:50 Remove one of the extra spaces after the word "ret
imasaki1 2011/03/18 21:54:25 Done.
+ # Gives up after that (very small chance)
dennis_jeffrey 2011/03/18 17:47:50 Put period at end of sentence.
imasaki1 2011/03/18 21:54:25 Done.
+ return None
+
+ def GenerateAllMediaInfos(self, video_only, media_matrix_home_url=''):
+ """Generate all video infos that can be used for playing this media.
+
+ Args:
+ video_only: True if generate random video only (not audio).
+
+ Returns:
+ a list of a tuples (info, url, link, tag, is_video, nickname).
+ info: description of the video (an entry in the matrix).
+ url: URL of the video/audio.
+ is_video: True if the file is video; False otherwise.
dennis_jeffrey 2011/03/18 17:47:50 What about the "link" and "tag" tuple items?
imasaki1 2011/03/18 21:54:25 Done.
+ nickname: nickname of the video for presentation (such as bear.webm).
+ """
+ video_infos = []
+
+ for i in range(0, len(self.__video_titles)-1):
+ name = self.__video_titles[i]
+ for sub_type in range(self.__GetMaxValue(video_only)):
+ (info, url, link, tag,
+ is_video, nickname) = self.__GenerateMediaInfo(sub_type,
+ name,
+ media_matrix_home_url)
dennis_jeffrey 2011/03/18 17:47:50 Similar comment as line 145 above.
imasaki1 2011/03/18 21:54:25 Done.
+ if NOT_AVAILABLE_STRING not in info:
+ video_infos.append([info, url, link, tag, is_video, nickname])
+ return video_infos
+
+ def GenerateAllMediaInfosInCompactForm(self, video_only,
+ media_matrix_home_url=''):
+ """Generate all media information in compact form.
+
+ Compact form contains only url, nickname and tag.
+
+ Args:
+ video_only: True if generate random video only.
+
+ Returns:
+ a list of a tuples (url, nickname, tag).
+ url: URL of the video/audio.
+ nickname: nickname of the video/audio for presentation
+ (such as bear.webm).
+ tag: HTML5 tag for the video/audio.
+ """
+ video_infos = []
+ for i in range(0, len(self.__video_titles)-1):
+ name = self.__video_titles[i]
+ for sub_type in range(self.__GetMaxValue(video_only)):
+ (info, url, link, tag,
+ is_video, nickname) = self.__GenerateMediaInfo(sub_type,
+ name,
+ media_matrix_home_url)
dennis_jeffrey 2011/03/18 17:47:50 Similar comment as line 145 above.
imasaki1 2011/03/18 21:54:25 Done.
+ tag = ['audio', 'video'][is_video]
+ if NOT_AVAILABLE_STRING not in info:
+ video_infos.append([url, nickname, tag])
+ return video_infos
+
dennis_jeffrey 2011/03/18 17:47:50 Functions GenerateAllMediaInfosInCompactForm, Gene
imasaki1 2011/03/18 21:54:25 I agree. I will add TODO
+ @staticmethod
+ def LookForMediaInfoByNickName(compact_list, target):
+ """Look for video by its nickname in the compact_list.
+
+ Args:
+ compact_list: a list generated by GenerateAllMediaInfosInCompactForm.
+ target: a target nickname string to look for.
+
+ Returns:
+ A tuple (info, url, link, tag, is_video, nickname) where nickname.
dennis_jeffrey 2011/03/18 17:47:50 I don't understand what you mean by "where nicknam
imasaki1 2011/03/18 21:54:25 Done.
+ url: URL of the video/audio.
+ tag: HTML5 tag for the video/audio.
+ nickname: nickname of the video/audio for presentation
+ (such as bear.webm).
dennis_jeffrey 2011/03/18 17:47:50 What about the "info", "link", and "is_video" tupl
imasaki1 2011/03/18 21:54:25 It is using compact form where we do not need thes
+ """
+ for url, nickname, tag in compact_list:
+ if target == nickname:
+ return (url, nickname, tag)

Powered by Google App Engine
This is Rietveld 408576698