| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import time | 5 import time |
| 6 | 6 |
| 7 import common | 7 import common |
| 8 from common import TestDriver | 8 from common import TestDriver |
| 9 from common import IntegrationTest | 9 from common import IntegrationTest |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 ) | 35 ) |
| 36 saw_video_response = False | 36 saw_video_response = False |
| 37 for response in t.GetHTTPResponses(): | 37 for response in t.GetHTTPResponses(): |
| 38 if 'video' in response.response_headers['content-type']: | 38 if 'video' in response.response_headers['content-type']: |
| 39 self.assertNotHasChromeProxyViaHeader(response) | 39 self.assertNotHasChromeProxyViaHeader(response) |
| 40 saw_video_response = True | 40 saw_video_response = True |
| 41 else: | 41 else: |
| 42 self.assertHasChromeProxyViaHeader(response) | 42 self.assertHasChromeProxyViaHeader(response) |
| 43 self.assertTrue(saw_video_response, 'No video request seen in test!') | 43 self.assertTrue(saw_video_response, 'No video request seen in test!') |
| 44 | 44 |
| 45 # Check the compressed video has the same frame count, width, height, and |
| 46 # duration as uncompressed. |
| 47 def testVideoMetrics(self): |
| 48 expected = { |
| 49 'duration': 3.124, |
| 50 'webkitDecodedFrameCount': 54.0, |
| 51 'videoWidth': 1280.0, |
| 52 'videoHeight': 720.0 |
| 53 } |
| 54 with TestDriver() as t: |
| 55 t.AddChromeArg('--enable-spdy-proxy-auth') |
| 56 t.LoadURL('http://check.googlezip.net/cacheable/video/buck_bunny_tiny.html
') |
| 57 # Check request was proxied and we got a compressed video back. |
| 58 for response in t.GetHTTPResponses(): |
| 59 self.assertHasChromeProxyViaHeader(response) |
| 60 if ('content-type' in response.response_headers |
| 61 and 'video' in response.response_headers['content-type']): |
| 62 self.assertEqual('video/webm', |
| 63 response.response_headers['content-type']) |
| 64 t.ExecuteJavascriptStatement( |
| 65 'document.querySelectorAll("video")[0].play()') |
| 66 # Wait for the video to finish playing, plus some headroom. |
| 67 time.sleep(5) |
| 68 # Check each metric against its expected value. |
| 69 for metric in expected: |
| 70 actual = float(t.ExecuteJavascriptStatement( |
| 71 'document.querySelectorAll("video")[0].%s' % metric)) |
| 72 self.assertAlmostEqual(expected[metric], actual, msg="Compressed video " |
| 73 "metric doesn't match expected! Metric=%s Expected=%f Actual=%f" |
| 74 % (metric, expected[metric], actual), places=None, delta=0.001) |
| 75 |
| 45 # Check the frames of a compressed video. | 76 # Check the frames of a compressed video. |
| 46 def testVideoFrames(self): | 77 def testVideoFrames(self): |
| 47 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_video.html') | 78 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_video.html') |
| 48 | 79 |
| 49 # Check the audio volume of a compressed video. | 80 # Check the audio volume of a compressed video. |
| 50 def testVideoAudio(self): | 81 def testVideoAudio(self): |
| 51 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_audio.html') | 82 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_audio.html') |
| 52 | 83 |
| 53 def instrumentedVideoTest(self, url): | 84 def instrumentedVideoTest(self, url): |
| 54 """Run an instrumented video test. The given page is reloaded up to some | 85 """Run an instrumented video test. The given page is reloaded up to some |
| (...skipping 26 matching lines...) Expand all Loading... |
| 81 wait_time = int(t.ExecuteJavascriptStatement('test.waitTime')) | 112 wait_time = int(t.ExecuteJavascriptStatement('test.waitTime')) |
| 82 t.WaitForJavascriptExpression('test.metrics.complete', wait_time) | 113 t.WaitForJavascriptExpression('test.metrics.complete', wait_time) |
| 83 metrics = t.ExecuteJavascriptStatement('test.metrics') | 114 metrics = t.ExecuteJavascriptStatement('test.metrics') |
| 84 if not metrics['complete']: | 115 if not metrics['complete']: |
| 85 raise Exception('Test not complete after %d seconds.' % wait_time) | 116 raise Exception('Test not complete after %d seconds.' % wait_time) |
| 86 if metrics['failed']: | 117 if metrics['failed']: |
| 87 raise Exception('Test failed!') | 118 raise Exception('Test failed!') |
| 88 | 119 |
| 89 if __name__ == '__main__': | 120 if __name__ == '__main__': |
| 90 IntegrationTest.RunAllTests() | 121 IntegrationTest.RunAllTests() |
| OLD | NEW |