Exemple #1
0
    def testDataReductionProxyDecidesTransformDefault(self):
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg('--force-fieldtrial-params='
                                     'NetworkQualityEstimator.Enabled:'
                                     'force_effective_connection_type/2G')
            test_driver.AddChromeArg(
                '--force-fieldtrials='
                'NetworkQualityEstimator/Enabled/'
                'DataReductionProxyPreviewsBlackListTransition/Enabled/')

            test_driver.LoadURL('http://check.googlezip.net/test.html')

            for response in test_driver.GetHTTPResponses():
                self.assertEqual('2G',
                                 response.request_headers['chrome-proxy-ect'])
                if response.url.endswith('html'):
                    if ParseFlags().android:
                        # CPAT provided on Android
                        self.assertIn('chrome-proxy-accept-transform',
                                      response.request_headers)
                    else:
                        # CPAT NOT provided on Desktop
                        self.assertNotIn('chrome-proxy-accept-transform',
                                         response.request_headers)
                        self.assertNotIn('chrome-proxy-content-transform',
                                         response.response_headers)
                    continue
Exemple #2
0
 def testVideoMetrics(self):
   expected = {
     'duration': 3.124,
     'webkitDecodedFrameCount': 54.0,
     'videoWidth': 1280.0,
     'videoHeight': 720.0
   }
   with TestDriver() as t:
     t.AddChromeArg('--enable-spdy-proxy-auth')
     t.LoadURL('http://check.googlezip.net/cacheable/video/buck_bunny_tiny.html')
     # Check request was proxied and we got a compressed video back.
     for response in t.GetHTTPResponses():
       self.assertHasChromeProxyViaHeader(response)
       if ('content-type' in response.response_headers
           and 'video' in response.response_headers['content-type']):
         self.assertEqual('video/webm',
           response.response_headers['content-type'])
     if ParseFlags().android:
       t.FindElement(By.TAG_NAME, "video").click()
     else:
       t.ExecuteJavascriptStatement(
         'document.querySelectorAll("video")[0].play()')
     # Wait for the video to finish playing, plus some headroom.
     time.sleep(5)
     # Check each metric against its expected value.
     for metric in expected:
       actual = float(t.ExecuteJavascriptStatement(
         'document.querySelectorAll("video")[0].%s' % metric))
       self.assertAlmostEqual(expected[metric], actual, msg="Compressed video "
         "metric doesn't match expected! Metric=%s Expected=%f Actual=%f"
         % (metric, expected[metric], actual), places=None, delta=0.001)
Exemple #3
0
 def testVideoAudio(self):
   alt_data = None
   is_android = ParseFlags().android
   if is_android:
     alt_data = 'data/buck_bunny_640x360_24fps.mp4.expected_volume_alt.json'
   self.instrumentedVideoTest('http://check.googlezip.net/cacheable/video/buck_bunny_640x360_24fps_audio.html',
     alt_data=alt_data)
Exemple #4
0
 def instrumentedVideoTest(self, url, alt_data=None):
   """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
   with TestDriver() as t:
     t.AddChromeArg('--enable-spdy-proxy-auth')
     t.AddChromeArg('--autoplay-policy=no-user-gesture-required')
     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():
         if ('content-type' in resp.response_headers
             and resp.response_headers['content-type'] == 'video/webm'):
           loaded_compressed_video = True
           self.assertHasChromeProxyViaHeader(resp)
         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)
     if alt_data != None:
       t.ExecuteJavascriptStatement('test.expectedVolumeSrc = "%s"' % alt_data)
     t.ExecuteJavascriptStatement('test.ready = true')
     t.WaitForJavascriptExpression('test.video_ != undefined', 5)
     # Click the video to start if Android.
     if ParseFlags().android:
       t.FindElement(By.ID, 'video').click()
     else:
       t.ExecuteJavascriptStatement('test.video_.play()')
     waitTimeQuery = 'test.waitTime'
     if ParseFlags().android:
       waitTimeQuery = 'test.androidWaitTime'
     wait_time = int(t.ExecuteJavascriptStatement(waitTimeQuery))
     t.WaitForJavascriptExpression('test.metrics.complete', wait_time)
     metrics = t.ExecuteJavascriptStatement('test.metrics')
     if not metrics['complete']:
       self.fail('Test not complete after %d seconds.' % wait_time)
     if metrics['failed']:
       self.fail('Test failed! ' + metrics['detailedStatus'])
Exemple #5
0
 def testVideoSeeking(self):
   with TestDriver(control_network_connection=True) as t:
     t.SetNetworkConnection("2G")
     t.AddChromeArg('--enable-spdy-proxy-auth')
     t.LoadURL(
         'http://check.googlezip.net/cacheable/video/'+
         'buck_bunny_640x360_24fps.html')
     # Play, pause, seek to 1s before the end, play again.
     t.ExecuteJavascript(
       '''
       window.testDone = false;
       const v = document.getElementsByTagName("video")[0];
       let first = true;
       v.onplaying = function() {
         if (first) {
           v.pause();
           first = false;
         } else {
           window.testDone = true;
         }
       };
       v.onpause = function() {
         if (v.currentTime < v.duration) {
           v.currentTime = v.duration-1;
           v.play();
         }
       };
       v.play();
       ''')
     if ParseFlags().android:
       # v.play() won't work on Android, so give it a click instead.
       t.FindElement(By.TAG_NAME, "video").click()
     t.WaitForJavascriptExpression('window.testDone', 15)
     # Check request was proxied and we got a compressed video back.
     # We expect to make multiple requests for the video: ensure they
     # all have the same ETag.
     video_etag = None
     num_partial_requests = 0
     for response in t.GetHTTPResponses():
       self.assertHasProxyHeaders(response)
       rh = response.response_headers
       if ('content-type' in rh and 'video' in rh['content-type']):
         self.assertIn('etag', rh),
         self.assertEqual('video/webm', rh['content-type'])
         if video_etag == None:
           video_etag = rh['etag']
         else:
           self.assertEqual(video_etag, rh['etag'])
         if ('status' in rh and rh['status']=='206' and 'content-range' in rh
             and rh['content-range'].startswith('bytes ') and
             not rh['content-range'].startswith('bytes 0-')):
           num_partial_requests += 1
     # Also make sure that we had at least one partial Range request.
     self.assertGreaterEqual(num_partial_requests, 1)
Exemple #6
0
 def testYoutube(self):
   with TestDriver() as t:
     t.AddChromeArg('--enable-spdy-proxy-auth')
     t.LoadURL('http://data-saver-test.appspot.com/youtube')
     if ParseFlags().android:
       # Video won't auto play on Android, so give it a click.
       t.FindElement(By.ID, 'player').click()
     t.WaitForJavascriptExpression(
       'window.playerState == YT.PlayerState.PLAYING', 30)
     for response in t.GetHTTPResponses():
       if not response.url.startswith('https'):
         self.assertHasChromeProxyViaHeader(response)
Exemple #7
0
 def wrapper(*args, **kwargs):
   if not ParseFlags().android:
     func(*args, **kwargs)
   else:
     args[0].skipTest('This test does not run on Android.')
Exemple #8
0
 def wrapper(*args, **kwargs):
   if ParseFlags().android:
     func(*args, **kwargs)
   else:
     args[0].skipTest('This test runs on Android only.')
Exemple #9
0
 def wrapper(*args, **kwargs):
   if ParseFlags().browser_args and arg in ParseFlags().browser_args:
     args[0].skipTest(
       'Test skipped because "%s" was given on the command line' % arg)
Exemple #10
0
 def wrapper(*args, **kwargs):
   if ParseFlags().skip_slow:
     args[0].skipTest('Skipping slow test.')
   else:
     func(*args, **kwargs)
Exemple #11
0
 def testDecorator(self):
     # This test should always result as 'skipped' or pass if --android given.
     if not ParseFlags().android:
         self.AndroidOnlyFunction()