diff options
-rw-r--r-- | chrome/test/data/media/html/media_constrained_network.html | 29 | ||||
-rwxr-xr-x | chrome/test/functional/media/media_constrained_network_perf.py | 42 |
2 files changed, 58 insertions, 13 deletions
diff --git a/chrome/test/data/media/html/media_constrained_network.html b/chrome/test/data/media/html/media_constrained_network.html index 21ba85c..ea37cc3 100644 --- a/chrome/test/data/media/html/media_constrained_network.html +++ b/chrome/test/data/media/html/media_constrained_network.html @@ -23,18 +23,39 @@ // controller will poll for these values until they are each >= 0. var epp = -1, ttp = -1; + // Video play progress to calculate percentage of video played. + var vpp = -1; + + // String to indicate if error or abort events happen. + var errorMsg = ''; + video.addEventListener('playing', function(event) { startTime = new Date().getTime(); - ttp = Math.max(0, startTime - loadTime); }, false); - video.addEventListener('ended', function(event) { + video.addEventListener('ended', setEPP, false); + video.addEventListener('error', logEvent, false); + video.addEventListener('abort', logEvent, false); + + function logEvent(evt) { + errorMsg += evt.target + ' ' + evt.type + ' event fired.\n'; + } + + function setEPP() { playTime = new Date().getTime() - startTime; durMs = video.duration * 1000; - epp = Math.max(0, (playTime - durMs) * 100 / durMs) - }, false); + epp = Math.max(0, (playTime - durMs) * 100 / durMs); + } + + function calculateProgress() { + if (!isNaN(video.duration)) + vpp = (video.currentTime / video.duration) * 100; + + if (window.domAutomationController) + window.domAutomationController.send(vpp); + } // Called by the PyAuto controller to initiate testing. function startTest(src) { diff --git a/chrome/test/functional/media/media_constrained_network_perf.py b/chrome/test/functional/media/media_constrained_network_perf.py index 73b1ce53..29ac2f1 100755 --- a/chrome/test/functional/media/media_constrained_network_perf.py +++ b/chrome/test/functional/media/media_constrained_network_perf.py @@ -105,18 +105,36 @@ class TestWorker(threading.Thread): if tab['url'] == url: return tab['index'] - def _HaveMetric(self, var_name, unique_url): - """Checks if unique_url page has variable value ready. Set to < 0 pre-run. + def _HaveMetricOrError(self, var_name, unique_url): + """Checks if the page has variable value ready or if an error has occured. + + The varaible value must be set to < 0 pre-run. Args: var_name: The variable name to check the metric for. unique_url: The url of the page to check for the variable's metric. + + Returns: + True is the var_name value is >=0 or if an error_msg exists. """ with self._automation_lock: tab = self._FindTabLocked(unique_url) self._metrics[var_name] = int(self._pyauto.GetDOMValue(var_name, tab_index=tab)) - return self._metrics[var_name] >= 0 + self._metrics['errorMsg'] = self._pyauto.GetDOMValue('errorMsg', + tab_index=tab) + + return self._metrics[var_name] >= 0 or self._metrics['errorMsg'] != '' + + def _GetVideoProgress(self, unique_url): + """Gets the video's current play progress percentage. + + Args: + unique_url: The url of the page to check for video play progress. + """ + with self._automation_lock: + return int(self._pyauto.CallJavascriptFunc( + 'calculateProgress', tab_index=self._FindTabLocked(unique_url))) def run(self): """Opens tab, starts HTML test, and records metrics for each queue entry. @@ -157,14 +175,14 @@ class TestWorker(threading.Thread): # here since pyauto.WaitUntil doesn't call into Chrome. self._metrics['epp'] = self._metrics['ttp'] = -1 self._pyauto.WaitUntil( - self._HaveMetric, args=['ttp', unique_url], retry_sleep=1, timeout=10, - debug=False) + self._HaveMetricOrError, args=['ttp', unique_url], retry_sleep=1, + timeout=10, debug=False) # Do not wait for epp if ttp is not available. series_name = ''.join(name) if self._metrics['ttp'] >= 0: self._pyauto.WaitUntil( - self._HaveMetric, args=['epp', unique_url], retry_sleep=2, + self._HaveMetricOrError, args=['epp', unique_url], retry_sleep=2, timeout=_TEST_VIDEO_DURATION_SEC * 10, debug=False) # Record results. @@ -173,9 +191,15 @@ class TestWorker(threading.Thread): '%') pyauto_utils.PrintPerfResult('ttp', series_name, self._metrics['ttp'], 'ms') - else: + logging.debug('Test %s ended with %d%% of the video played.', + series_name, self._GetVideoProgress(unique_url)) + elif self._metrics['errorMsg'] == '': logging.error('Test %s timed-out.', series_name) + if self._metrics['errorMsg'] != '': + logging.debug('Test %s ended with error: %s', series_name, + self._metrics['errorMsg']) + # Close the tab. with self._automation_lock: self._pyauto.GetBrowserWindow(0).GetTab( @@ -203,7 +227,7 @@ class ProcessLogger(threading.Thread): line = True while line: line = self._process.stderr.readline() - logging.debug(line) + logging.debug(line.strip()) class MediaConstrainedNetworkPerfTest(pyauto.PyUITest): @@ -224,7 +248,7 @@ class MediaConstrainedNetworkPerfTest(pyauto.PyUITest): line = True while line: line = process.stderr.readline() - logging.debug(line) + logging.debug(line.strip()) if 'STARTED' in line: self._server_pid = process.pid pyauto.PyUITest.setUp(self) |