Chromium Code Reviews| Index: functional/youtube.py |
| =================================================================== |
| --- functional/youtube.py (revision 109125) |
| +++ functional/youtube.py (working copy) |
| @@ -3,6 +3,7 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import re |
| import time |
| import pyauto_functional |
| @@ -45,8 +46,42 @@ |
| """ |
| return self._pyauto.ExecuteJavascript(js) |
| + def GetVideoInfo(self): |
| + """Returns video info""" |
|
Nirnimesh
2011/11/15 02:13:50
What info? Include sample.
rohitbm
2011/11/15 03:10:50
This API is undocumented, so do we want to include
|
| + youtube_apis = self._pyauto.GetPrivateInfo()['youtube_api'] |
| + youtube_debug_text = youtube_apis['GetDebugText'] |
| + video_data = self._pyauto.ExecuteJavascript( |
| + 'window.domAutomationController.send(%s);' % youtube_debug_text) |
| + return video_data |
|
Nirnimesh
2011/11/15 02:13:50
merge with previous line
rohitbm
2011/11/15 03:10:50
Done.
|
| + |
| + def GetVideoDroppedFrames(self): |
| + """Returns total Youtube video dropped frames. |
| + |
| + Returns: |
| + -1 if failed to get video frames from the video data |
| + """ |
| + video_data = self._pyauto.GetVideoInfo() |
| + matched = re.search('droppedFrames=([\d\.]+)', video_data) |
| + if matched: |
| + return int(matched.group(1)) |
| + else: |
| + return -1 |
| + |
| + def GetVideoFrames(self): |
| + """Returns Youtube video frames/second |
|
Nirnimesh
2011/11/15 02:13:50
end with . for consistency
rohitbm
2011/11/15 03:10:50
Done.
|
| + |
| + Returns: |
| + -1 if failed to get droppd frames from the video data. |
| + """ |
| + video_data = self._pyauto.GetVideoInfo() |
| + matched = re.search('videoFps=([\d\.]+)', video_data) |
| + if matched: |
| + return int(matched.group(1)) |
| + else: |
| + return -1 |
| + |
| def GetVideoTotalBytes(self): |
| - """Returns video size in bytes |
| + """Returns video total size in bytes |
| To call this function, video must be in the paying state, |
| or this returns 0. |
| @@ -58,6 +93,15 @@ |
| """) |
| return int(total_bytes) |
| + def GetVideoLoadedBytes(self): |
| + """Returns video size in bytes.""" |
| + loaded_bytes = 0 |
| + loaded_bytes = self.ExecuteJavascript(""" |
| + bytes = ytplayer.getVideoBytesLoaded(); |
| + window.domAutomationController.send(bytes + ''); |
| + """) |
| + return int(loaded_bytes) |
| + |
| def PlayVideo(self): |
| """Plays the loaded video""" |
| self._pyauto.ExecuteJavascript(""" |
| @@ -65,6 +109,13 @@ |
| window.domAutomationController.send(''); |
| """) |
| + def PauseVideo(self): |
| + """Pause the video""" |
| + self.ExecuteJavascript(""" |
| + ytplayer.pauseVideo(); |
| + window.domAutomationController.send(''); |
| + """) |
| + |
| def AssertPlayingState(self): |
| """Assert player's playing state""" |
| self._pyauto.assertTrue(self._pyauto.WaitUntil(self._pyauto.GetPlayerState, |
| @@ -74,7 +125,7 @@ |
| def PlayVideoAndAssert(self): |
| """Start video and assert the playing state""" |
| self._pyauto.assertTrue(self._pyauto.IsFlashPluginEnabled(), |
| - msg='From here Flash plugin is disabled or not available') |
| + msg='From here Flash plugin is disabled or not available') |
| url = self._pyauto.GetHttpURLForDataPath('media', 'youtube.html') |
| self._pyauto.NavigateToURL(url) |
| self._pyauto.assertTrue(self._pyauto.WaitUntilPlayerReady(), |
| @@ -99,11 +150,7 @@ |
| # Navigating to Youtube video. This video is 122 seconds long. |
| # During tests, we are not goinig to play this video full. |
| self.PlayVideoAndAssert() |
| - # Pause the playing video |
| - self.ExecuteJavascript(""" |
| - ytplayer.pauseVideo(); |
| - window.domAutomationController.send(''); |
| - """) |
| + self.PauseVideo() |
| self.assertEqual(self.GetPlayerState(), self.is_paused, |
| msg='Player did not enter the paused state') |
| # Seek to the end of video |
| @@ -150,11 +197,7 @@ |
| count = count + 1 |
| if count == 2: |
| break |
| - loaded_bytes = self.ExecuteJavascript(""" |
| - bytes = ytplayer.getVideoBytesLoaded(); |
| - window.domAutomationController.send(bytes + ''); |
| - """) |
| - loaded_bytes = int(loaded_bytes) |
| + loaded_bytes = self.GetVideoLoadedBytes() |
| self.assertTrue(prev_loaded_bytes <= loaded_bytes) |
| prev_loaded_bytes = loaded_bytes |
| # Give some time to load a video |