| 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 common import ParseFlags | 10 from common import ParseFlags |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 @Slow | 53 @Slow |
| 54 def testVideoMetrics(self): | 54 def testVideoMetrics(self): |
| 55 expected = { | 55 expected = { |
| 56 'duration': 3.124, | 56 'duration': 3.124, |
| 57 'webkitDecodedFrameCount': 54.0, | 57 'webkitDecodedFrameCount': 54.0, |
| 58 'videoWidth': 1280.0, | 58 'videoWidth': 1280.0, |
| 59 'videoHeight': 720.0 | 59 'videoHeight': 720.0 |
| 60 } | 60 } |
| 61 with TestDriver() as t: | 61 with TestDriver() as t: |
| 62 t.AddChromeArg('--enable-spdy-proxy-auth') | 62 t.AddChromeArg('--enable-spdy-proxy-auth') |
| 63 t.LoadURL('http://check.googlezip.net/cacheable/video/buck_bunny_tiny.html
') | 63 t.LoadURL( |
| 64 'http://check.googlezip.net/cacheable/video/buck_bunny_tiny.html') |
| 64 # Check request was proxied and we got a compressed video back. | 65 # Check request was proxied and we got a compressed video back. |
| 65 for response in t.GetHTTPResponses(): | 66 for response in t.GetHTTPResponses(): |
| 66 self.assertHasChromeProxyViaHeader(response) | 67 self.assertHasChromeProxyViaHeader(response) |
| 67 if ('content-type' in response.response_headers | 68 if ('content-type' in response.response_headers |
| 68 and 'video' in response.response_headers['content-type']): | 69 and 'video' in response.response_headers['content-type']): |
| 69 self.assertEqual('video/webm', | 70 self.assertEqual('video/webm', |
| 70 response.response_headers['content-type']) | 71 response.response_headers['content-type']) |
| 71 if ParseFlags().android: | 72 if ParseFlags().android: |
| 72 t.FindElement(By.TAG_NAME, "video").click() | 73 t.FindElement(By.TAG_NAME, "video").click() |
| 73 else: | 74 else: |
| 74 t.ExecuteJavascriptStatement( | 75 t.ExecuteJavascriptStatement( |
| 75 'document.querySelectorAll("video")[0].play()') | 76 'document.querySelectorAll("video")[0].play()') |
| 76 # Wait for the video to finish playing, plus some headroom. | 77 # Wait for the video to finish playing, plus some headroom. |
| 77 time.sleep(5) | 78 time.sleep(5) |
| 78 # Check each metric against its expected value. | 79 # Check each metric against its expected value. |
| 79 for metric in expected: | 80 for metric in expected: |
| 80 actual = float(t.ExecuteJavascriptStatement( | 81 actual = float(t.ExecuteJavascriptStatement( |
| 81 'document.querySelectorAll("video")[0].%s' % metric)) | 82 'document.querySelectorAll("video")[0].%s' % metric)) |
| 82 self.assertAlmostEqual(expected[metric], actual, msg="Compressed video " | 83 self.assertAlmostEqual(expected[metric], actual, msg="Compressed video " |
| 83 "metric doesn't match expected! Metric=%s Expected=%f Actual=%f" | 84 "metric doesn't match expected! Metric=%s Expected=%f Actual=%f" |
| 84 % (metric, expected[metric], actual), places=None, delta=0.001) | 85 % (metric, expected[metric], actual), places=None, delta=0.001) |
| 85 | 86 |
| 87 # Check that the compressed video can be seeked. Use a slow network to ensure |
| 88 # the entire video isn't downloaded before we have a chance to seek. |
| 89 # |
| 90 # This test cannot run on android because of control_network_connection=True. |
| 91 # That option is used to reduce flakes that might happen on fast networks, |
| 92 # where the video is completely downloaded before a seeking request can be |
| 93 # sent. The test can be manually simulated by the following steps: set network |
| 94 # emulation in DevTools on Android (via device inspector), load a video, pause |
| 95 # the video, then seek and verify the seek continues to play the video. |
| 96 @Slow |
| 97 @NotAndroid |
| 98 def testVideoSeeking(self): |
| 99 with TestDriver(control_network_connection=True) as t: |
| 100 t.SetNetworkConnection("3G") |
| 101 t.AddChromeArg('--enable-spdy-proxy-auth') |
| 102 t.LoadURL( |
| 103 'http://check.googlezip.net/cacheable/video/'+ |
| 104 'buck_bunny_640x360_24fps.html') |
| 105 # Play, pause, seek to 1s before the end, play again. |
| 106 t.ExecuteJavascript( |
| 107 ''' |
| 108 window.testDone = false; |
| 109 const v = document.getElementsByTagName("video")[0]; |
| 110 let first = true; |
| 111 v.onplaying = function() { |
| 112 if (first) { |
| 113 v.pause(); |
| 114 first = false; |
| 115 } else { |
| 116 window.testDone = true; |
| 117 } |
| 118 }; |
| 119 v.onpause = function() { |
| 120 if (v.currentTime < v.duration) { |
| 121 v.currentTime = v.duration-1; |
| 122 v.play(); |
| 123 } |
| 124 }; |
| 125 v.play(); |
| 126 ''') |
| 127 t.WaitForJavascriptExpression('window.testDone', 10) |
| 128 # Check request was proxied and we got a compressed video back. |
| 129 # We expect to make multiple requests for the video: ensure they |
| 130 # all have the same ETag. |
| 131 video_etag = None |
| 132 num_partial_requests = 0 |
| 133 for response in t.GetHTTPResponses(): |
| 134 self.assertHasChromeProxyViaHeader(response) |
| 135 rh = response.response_headers |
| 136 if ('content-type' in rh and 'video' in rh['content-type']): |
| 137 self.assertTrue('etag' in rh), |
| 138 self.assertEqual('video/webm', rh['content-type']) |
| 139 if video_etag == None: |
| 140 video_etag = rh['etag'] |
| 141 else: |
| 142 self.assertEqual(video_etag, rh['etag']) |
| 143 if ('range' in response.request_headers and |
| 144 response.request_headers['range'] != 'bytes=0-'): |
| 145 num_partial_requests += 1 |
| 146 # Also make sure that we had at least one partial Range request. |
| 147 self.assertGreaterEqual(num_partial_requests, 1) |
| 148 |
| 86 # Check the frames of a compressed video. | 149 # Check the frames of a compressed video. |
| 87 @Slow | 150 @Slow |
| 88 def testVideoFrames(self): | 151 def testVideoFrames(self): |
| 89 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_video.html') | 152 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_video.html') |
| 90 | 153 |
| 91 # Check the audio volume of a compressed video. | 154 # Check the audio volume of a compressed video. |
| 92 @NotAndroid | 155 @NotAndroid |
| 93 @Slow | 156 @Slow |
| 94 def testVideoAudio(self): | 157 def testVideoAudio(self): |
| 95 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_audio.html') | 158 self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_
bunny_640x360_24fps_audio.html') |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 # Video won't auto play on Android, so give it a click. | 205 # Video won't auto play on Android, so give it a click. |
| 143 t.FindElement(By.ID, 'player').click() | 206 t.FindElement(By.ID, 'player').click() |
| 144 t.WaitForJavascriptExpression( | 207 t.WaitForJavascriptExpression( |
| 145 'window.playerState == YT.PlayerState.PLAYING', 30) | 208 'window.playerState == YT.PlayerState.PLAYING', 30) |
| 146 for response in t.GetHTTPResponses(): | 209 for response in t.GetHTTPResponses(): |
| 147 if not response.url.startswith('https'): | 210 if not response.url.startswith('https'): |
| 148 self.assertHasChromeProxyViaHeader(response) | 211 self.assertHasChromeProxyViaHeader(response) |
| 149 | 212 |
| 150 if __name__ == '__main__': | 213 if __name__ == '__main__': |
| 151 IntegrationTest.RunAllTests() | 214 IntegrationTest.RunAllTests() |
| OLD | NEW |