| 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 from decorators import NotAndroid | 10 from decorators import NotAndroid |
| 11 from decorators import Slow |
| 11 | 12 |
| 12 | 13 |
| 13 class Video(IntegrationTest): | 14 class Video(IntegrationTest): |
| 14 | 15 |
| 15 # Check videos are proxied. | 16 # Check videos are proxied. |
| 16 def testCheckVideoHasViaHeader(self): | 17 def testCheckVideoHasViaHeader(self): |
| 17 with TestDriver() as t: | 18 with TestDriver() as t: |
| 18 t.AddChromeArg('--enable-spdy-proxy-auth') | 19 t.AddChromeArg('--enable-spdy-proxy-auth') |
| 19 t.LoadURL( | 20 t.LoadURL( |
| 20 'http://check.googlezip.net/cacheable/video/buck_bunny_tiny.html') | 21 'http://check.googlezip.net/cacheable/video/buck_bunny_tiny.html') |
| (...skipping 19 matching lines...) Expand all Loading... |
| 40 for response in t.GetHTTPResponses(): | 41 for response in t.GetHTTPResponses(): |
| 41 if 'video' in response.response_headers['content-type']: | 42 if 'video' in response.response_headers['content-type']: |
| 42 self.assertNotHasChromeProxyViaHeader(response) | 43 self.assertNotHasChromeProxyViaHeader(response) |
| 43 saw_video_response = True | 44 saw_video_response = True |
| 44 else: | 45 else: |
| 45 self.assertHasChromeProxyViaHeader(response) | 46 self.assertHasChromeProxyViaHeader(response) |
| 46 self.assertTrue(saw_video_response, 'No video request seen in test!') | 47 self.assertTrue(saw_video_response, 'No video request seen in test!') |
| 47 | 48 |
| 48 # Check the compressed video has the same frame count, width, height, and | 49 # Check the compressed video has the same frame count, width, height, and |
| 49 # duration as uncompressed. | 50 # duration as uncompressed. |
| 51 @Slow |
| 50 @NotAndroid | 52 @NotAndroid |
| 51 def testVideoMetrics(self): | 53 def testVideoMetrics(self): |
| 52 expected = { | 54 expected = { |
| 53 'duration': 3.124, | 55 'duration': 3.124, |
| 54 'webkitDecodedFrameCount': 54.0, | 56 'webkitDecodedFrameCount': 54.0, |
| 55 'videoWidth': 1280.0, | 57 'videoWidth': 1280.0, |
| 56 'videoHeight': 720.0 | 58 'videoHeight': 720.0 |
| 57 } | 59 } |
| 58 with TestDriver() as t: | 60 with TestDriver() as t: |
| 59 t.AddChromeArg('--enable-spdy-proxy-auth') | 61 t.AddChromeArg('--enable-spdy-proxy-auth') |
| (...skipping 12 matching lines...) Expand all Loading... |
| 72 # Check each metric against its expected value. | 74 # Check each metric against its expected value. |
| 73 for metric in expected: | 75 for metric in expected: |
| 74 actual = float(t.ExecuteJavascriptStatement( | 76 actual = float(t.ExecuteJavascriptStatement( |
| 75 'document.querySelectorAll("video")[0].%s' % metric)) | 77 'document.querySelectorAll("video")[0].%s' % metric)) |
| 76 self.assertAlmostEqual(expected[metric], actual, msg="Compressed video " | 78 self.assertAlmostEqual(expected[metric], actual, msg="Compressed video " |
| 77 "metric doesn't match expected! Metric=%s Expected=%f Actual=%f" | 79 "metric doesn't match expected! Metric=%s Expected=%f Actual=%f" |
| 78 % (metric, expected[metric], actual), places=None, delta=0.001) | 80 % (metric, expected[metric], actual), places=None, delta=0.001) |
| 79 | 81 |
| 80 # Check the frames of a compressed video. | 82 # Check the frames of a compressed video. |
| 81 @NotAndroid | 83 @NotAndroid |
| 84 @Slow |
| 82 def testVideoFrames(self): | 85 def testVideoFrames(self): |
| 83 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_video.html') | 86 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_video.html') |
| 84 | 87 |
| 85 # Check the audio volume of a compressed video. | 88 # Check the audio volume of a compressed video. |
| 86 @NotAndroid | 89 @NotAndroid |
| 90 @Slow |
| 87 def testVideoAudio(self): | 91 def testVideoAudio(self): |
| 88 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_audio.html') | 92 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_audio.html') |
| 89 | 93 |
| 90 def instrumentedVideoTest(self, url): | 94 def instrumentedVideoTest(self, url): |
| 91 """Run an instrumented video test. The given page is reloaded up to some | 95 """Run an instrumented video test. The given page is reloaded up to some |
| 92 maximum number of times until a compressed video is seen by ChromeDriver by | 96 maximum number of times until a compressed video is seen by ChromeDriver by |
| 93 inspecting the network logs. Once that happens, test.ready is set and that | 97 inspecting the network logs. Once that happens, test.ready is set and that |
| 94 will signal the Javascript test on the page to begin. Once it is complete, | 98 will signal the Javascript test on the page to begin. Once it is complete, |
| 95 check the results. | 99 check the results. |
| 96 """ | 100 """ |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 t.AddChromeArg('--enable-spdy-proxy-auth') | 134 t.AddChromeArg('--enable-spdy-proxy-auth') |
| 131 t.LoadURL('http://data-saver-test.appspot.com/youtube') | 135 t.LoadURL('http://data-saver-test.appspot.com/youtube') |
| 132 t.WaitForJavascriptExpression( | 136 t.WaitForJavascriptExpression( |
| 133 'window.playerState == YT.PlayerState.PLAYING', 30) | 137 'window.playerState == YT.PlayerState.PLAYING', 30) |
| 134 for response in t.GetHTTPResponses(): | 138 for response in t.GetHTTPResponses(): |
| 135 if not response.url.startswith('https'): | 139 if not response.url.startswith('https'): |
| 136 self.assertHasChromeProxyViaHeader(response) | 140 self.assertHasChromeProxyViaHeader(response) |
| 137 | 141 |
| 138 if __name__ == '__main__': | 142 if __name__ == '__main__': |
| 139 IntegrationTest.RunAllTests() | 143 IntegrationTest.RunAllTests() |
| OLD | NEW |