Bug 1305607 - Correct reading of baseURI from video element. r?maja_zf
Previous changes that I'd made broke the reporting of the baseURI on videos.
This changeset aims to fix those breakages, and also puts the baseURI on the
state snapshot.
MozReview-Commit-ID: 8YgPpHzoX1E
--- a/dom/media/test/external/external_media_tests/media_utils/video_puppeteer.py
+++ b/dom/media/test/external/external_media_tests/media_utils/video_puppeteer.py
@@ -54,16 +54,17 @@ class VideoPuppeteer(object):
of the video.
:param stall_wait_time: The amount of time to wait to see if a stall has
cleared. If 0, do not check for stalls.
:param timeout: The amount of time to wait until the video starts.
"""
_video_var_script = (
'var video = arguments[0];'
+ 'var baseURI = arguments[0].baseURI;'
'var currentTime = video.wrappedJSObject.currentTime;'
'var duration = video.wrappedJSObject.duration;'
'var buffered = video.wrappedJSObject.buffered;'
'var bufferedRanges = [];'
'for (var i = 0; i < buffered.length; i++) {'
'bufferedRanges.push([buffered.start(i), buffered.end(i)]);'
'}'
'var played = video.wrappedJSObject.played;'
@@ -198,17 +199,17 @@ class VideoPuppeteer(object):
if self._last_seen_video_state.remaining_time < self.interval:
return True
# Check to see if the video has stalled. Accumulate the amount of lag
# since the video started, and if it is too high, then raise.
if (self.stall_wait_time and
self._last_seen_video_state.lag > self.stall_wait_time):
raise VideoException('Video {} stalled.\n{}'
- .format(self._last_seen_video_state.video_url,
+ .format(self._last_seen_video_state.video_uri,
self))
# We are cruising, so we are not done.
return False
def _update_expected_duration(self):
"""
Update the duration of the target video at self.test_url (in seconds).
@@ -246,17 +247,18 @@ class VideoPuppeteer(object):
@staticmethod
def _video_state_named_tuple():
"""
Create a named tuple class that can be used to store state snapshots
of the wrapped element. The fields in the tuple should be used as
follows:
- current_time: The current time of the wrapped element.
+ base_uri: the baseURI attribute of the wrapped element.
+ current_time: the current time of the wrapped element.
duration: the duration of the wrapped element.
buffered: the buffered ranges of the wrapped element. In its raw form
this is as a list where the first element is the length and the second
element is a list of 2 item lists, where each two items are a buffered
range. Once assigned to the tuple this data should be wrapped in the
TimeRanges class.
played: the played ranges of the wrapped element. In its raw form this
is as a list where the first element is the length and the second
@@ -264,32 +266,31 @@ class VideoPuppeteer(object):
range. Once assigned to the tuple this data should be wrapped in the
TimeRanges class.
lag: the difference in real world time and wrapped element time.
Calculated as real world time passed - element time passed.
totalFrames: number of total frames for the wrapped element
droppedFrames: number of dropped frames for the wrapped element.
corruptedFrames: number of corrupted frames for the wrapped.
video_src: the src attribute of the wrapped element.
- video_url: the url attribute of the wrapped element.
:return: A 'video_state_info' named tuple class.
"""
return namedtuple('video_state_info',
- ['current_time',
+ ['base_uri',
+ 'current_time',
'duration',
'remaining_time',
'buffered',
'played',
'lag',
'total_frames',
'dropped_frames',
'corrupted_frames',
- 'video_src',
- 'video_url'])
+ 'video_src'])
def _create_video_state_info(self, **video_state_info_kwargs):
"""
Create an instance of the video_state_info named tuple. This function
expects a dictionary populated with the following keys: current_time,
duration, raw_played_ranges, total_frames, dropped_frames, and
corrupted_frames.
@@ -325,27 +326,27 @@ class VideoPuppeteer(object):
video_state_info_kwargs['played'].start(0))
video_state_info_kwargs['remaining_time'] = (
self.expected_duration - played_duration)
else:
# No playback has happened yet, remaining time is duration
video_state_info_kwargs['remaining_time'] = self.expected_duration
# Fetch non time critical source information
video_state_info_kwargs['video_src'] = self.video.get_attribute('src')
- video_state_info_kwargs['video_url'] = self.video.get_attribute('url')
# Create video state snapshot
state_info = self._video_state_named_tuple()
return state_info(**video_state_info_kwargs)
@property
def _fetch_state_script(self):
if not self._fetch_state_script_string:
self._fetch_state_script_string = (
self._video_var_script +
'return ['
+ 'baseURI,'
'currentTime,'
'duration,'
'[buffered.length, bufferedRanges],'
'[played.length, playedRanges],'
'totalFrames,'
'droppedFrames,'
'corruptedFrames];')
return self._fetch_state_script_string
@@ -354,17 +355,17 @@ class VideoPuppeteer(object):
"""
Refresh the snapshot of the underlying video state. We do this all
in one so that the state doesn't change in between queries.
We also store information that can be derived from the snapshotted
information, such as lag. This is stored in the last seen state to
stress that it's based on the snapshot.
"""
- keys = ['current_time', 'duration', 'raw_buffered_ranges',
+ keys = ['base_uri', 'current_time', 'duration', 'raw_buffered_ranges',
'raw_played_ranges', 'total_frames', 'dropped_frames',
'corrupted_frames']
values = self._execute_video_script(self._fetch_state_script)
self._last_seen_video_state = (
self._create_video_state_info(**dict(zip(keys, values))))
def _measure_progress(self):
self._refresh_state()
--- a/dom/media/test/external/external_media_tests/media_utils/youtube_puppeteer.py
+++ b/dom/media/test/external/external_media_tests/media_utils/youtube_puppeteer.py
@@ -339,16 +339,17 @@ class YouTubePuppeteer(VideoPuppeteer):
@property
def _fetch_state_script(self):
if not self._fetch_state_script_string:
self._fetch_state_script_string = (
self._video_var_script +
self._player_var_script +
'return ['
+ 'baseURI,'
'currentTime,'
'duration,'
'[buffered.length, bufferedRanges],'
'[played.length, playedRanges],'
'totalFrames,'
'droppedFrames,'
'corruptedFrames,'
'player_duration,'
@@ -367,19 +368,19 @@ class YouTubePuppeteer(VideoPuppeteer):
Refresh the snapshot of the underlying video and player state. We do
this allin one so that the state doesn't change in between queries.
We also store information that can be derived from the snapshotted
information, such as lag. This is stored in the last seen state to
stress that it's based on the snapshot.
"""
values = self._execute_yt_script(self._fetch_state_script)
- video_keys = ['current_time', 'duration', 'raw_buffered_ranges',
- 'raw_played_ranges', 'total_frames', 'dropped_frames',
- 'corrupted_frames']
+ video_keys = ['base_uri', 'current_time', 'duration',
+ 'raw_buffered_ranges', 'raw_played_ranges',
+ 'total_frames', 'dropped_frames', 'corrupted_frames']
player_keys = ['player_duration', 'player_current_time',
'player_playback_quality', 'player_movie_id',
'player_movie_title', 'player_url', 'player_state',
'player_ad_state', 'player_breaks_count']
# Get video state
self._last_seen_video_state = (
self._create_video_state_info(**dict(
zip(video_keys, values[:len(video_keys)]))))