Chromium Code Reviews| Index: tools/chrome_proxy/webdriver/video.py |
| diff --git a/tools/chrome_proxy/webdriver/video.py b/tools/chrome_proxy/webdriver/video.py |
| index ef02a0f278e79020b58dfa4e5c31c197b248389b..5d950d8b235796445e7714c0bfb801d87b635446 100644 |
| --- a/tools/chrome_proxy/webdriver/video.py |
| +++ b/tools/chrome_proxy/webdriver/video.py |
| @@ -2,6 +2,8 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import time |
| + |
| import common |
| from common import TestDriver |
| from common import IntegrationTest |
| @@ -40,5 +42,49 @@ class Video(IntegrationTest): |
| self.assertHasChromeProxyViaHeader(response) |
| self.assertTrue(saw_video_response, 'No video request seen in test!') |
| + # Check the frames of a compressed video. |
| + def testVideoFrames(self): |
| + self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_bunny_640x360_24fps_video.html') |
| + |
| + # Check the audio volume of a compressed video. |
| + def testVideoAudio(self): |
| + self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_bunny_640x360_24fps_audio.html') |
| + |
| + def instrumentedVideoTest(self, url): |
| + """Run an instrumented video test. The given page is reloaded up to some |
| + maximum number of times until a compressed video is seen by ChromeDriver by |
| + inspecting the network logs. Once that happens, test.ready is set and that |
| + will signal the Javascript test on the page to begin. Once it is complete, |
| + check the results. |
| + """ |
| + # The maximum number of times to attempt to reload the page for a compressed |
| + # video. |
| + max_attempts = 10 |
|
Tom Bergan
2017/02/14 18:27:18
Hopefully 10 attempts aren't actually necessary in
Robert Ogden
2017/02/14 18:57:32
Of the numerous times I've run it on my machine, i
|
| + with TestDriver() as t: |
| + t.AddChromeArg('--enable-spdy-proxy-auth') |
| + loaded_compressed_video = False |
| + attempts = 0 |
| + while not loaded_compressed_video and attempts < max_attempts: |
| + t.LoadURL(url) |
| + attempts += 1 |
| + for resp in t.GetHTTPResponses(): |
| + self.assertHasChromeProxyViaHeader(resp) |
|
Tom Bergan
2017/02/14 18:27:18
Will this assertion fail (and crash the test) on a
Robert Ogden
2017/02/14 18:57:32
Done.
|
| + if ('content-type' in resp.response_headers |
| + and resp.response_headers['content-type'] == 'video/webm'): |
| + loaded_compressed_video = True |
| + else: |
| + # Take a breath before requesting again. |
| + time.sleep(1) |
| + if attempts >= max_attempts: |
| + self.fail('Could not get a compressed video after %d tries' % attempts) |
| + t.ExecuteJavascriptStatement('test.ready = true') |
| + wait_time = int(t.ExecuteJavascriptStatement('test.waitTime')) |
| + t.WaitForJavascriptExpression('test.metrics.complete', wait_time) |
| + metrics = t.ExecuteJavascriptStatement('test.metrics') |
| + if not metrics['complete']: |
| + raise Exception('Test not complete after %d seconds.' % wait_time) |
| + if metrics['failed']: |
| + raise Exception('Test failed!') |
| + |
| if __name__ == '__main__': |
| IntegrationTest.RunAllTests() |