Exemple #1
0
    def testLitePage(self):
        # If it was attempted to run with another experiment, skip this test.
        if common.ParseFlags().browser_args and (
                '--data-reduction-proxy-experiment'
                in common.ParseFlags().browser_args):
            self.skipTest('This test cannot be run with other experiments.')
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
            test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page')

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

            lite_page_responses = 0
            for response in test_driver.GetHTTPResponses():
                # Skip CSI requests when validating Lite Page headers. CSI requests
                # aren't expected to have LoFi headers.
                if '/csi?' in response.url:
                    continue
                if response.url.startswith('data:'):
                    continue
                self.assertIn('exp=ignore_preview_blacklist',
                              response.request_headers['chrome-proxy'])
                if (self.checkLitePageResponse(response)):
                    lite_page_responses = lite_page_responses + 1

            # Verify that a Lite Page response for the main frame was seen.
            self.assertEqual(1, lite_page_responses)
Exemple #2
0
  def testExpDirectiveBypass(self):
    # If it was attempted to run with another experiment, skip this test.
    if common.ParseFlags().browser_args and ('--data-reduction-proxy-experiment'
        in common.ParseFlags().browser_args):
      self.skipTest('This test cannot be run with other experiments.')
    with TestDriver() as test_driver:
      test_driver.AddChromeArg('--enable-spdy-proxy-auth')
      test_driver.AddChromeArg('--data-reduction-proxy-experiment=client_test_bypass')

      # Verify that loading a page other than the specific exp directive test
      # page loads through the proxy without being bypassed.
      test_driver.LoadURL('http://check.googlezip.net/test.html')
      responses = test_driver.GetHTTPResponses()
      self.assertNotEqual(0, len(responses))
      for response in responses:
        self.assertHasChromeProxyViaHeader(response)

      # Verify that loading the exp directive test page with "exp=client_test_bypass" triggers
      # a bypass.
      test_driver.LoadURL('http://check.googlezip.net/exp/')
      responses = test_driver.GetHTTPResponses()
      self.assertNotEqual(0, len(responses))
      for response in responses:
        self.assertNotHasChromeProxyViaHeader(response)

    # Verify that loading the same test page without setting "exp=client_test_bypass" loads
    # through the proxy without being bypassed.
    with TestDriver() as test_driver:
      test_driver.AddChromeArg('--enable-spdy-proxy-auth')

      test_driver.LoadURL('http://check.googlezip.net/exp/')
      responses = test_driver.GetHTTPResponses()
      self.assertNotEqual(0, len(responses))
      for response in responses:
        self.assertHasChromeProxyViaHeader(response)
Exemple #3
0
    def testLitePageNotAcceptedForCellularOnlyFlag(self):
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg(
                '--data-reduction-proxy-lo-fi=cellular-only')
            test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page')

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

            non_lite_page_responses = 0
            for response in test_driver.GetHTTPResponses():
                if response.url.endswith('html'):
                    self.assertNotIn('chrome-proxy-accept-transform',
                                     response.request_headers)
                    self.assertNotIn('chrome-proxy-content-transform',
                                     response.response_headers)
                    non_lite_page_responses = non_lite_page_responses + 1
                    # Note that the client will still send exp=force_lite_page (if not
                    # using the exp paramter to specify other experiments).
                    if common.ParseFlags().browser_args:
                        if ('--data-reduction-proxy-experiment'
                                not in common.ParseFlags().browser_args):
                            # Verify force directive present.
                            self.assertIn(
                                'exp=force_lite_page',
                                response.request_headers['chrome-proxy'])

            # Verify that a main frame without Lite Page was seen.
            self.assertEqual(1, non_lite_page_responses)
Exemple #4
0
    def testLitePageWithoutCopyrightRestriction(self):
        # If it was attempted to run with another experiment, skip this test.
        if common.ParseFlags().browser_args and (
                '--data-reduction-proxy-experiment'
                in common.ParseFlags().browser_args):
            self.skipTest('This test cannot be run with other experiments.')
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg(
                '--enable-features=NetworkQualityEstimator'
                '<NetworkQualityEstimator,'
                'Previews,DataReductionProxyDecidesTransform,'
                'NetworkService,'
                'DataReductionProxyEnabledWithNetworkService')
            test_driver.AddChromeArg(
                '--force-fieldtrial-params=NetworkQualityEstimator.Enabled:'
                'force_effective_connection_type/2G,'
                'DataReductionProxyServerExperiments.IgnoreCountryBlacklist:'
                'exp/ignore_preview_blacklist')
            test_driver.AddChromeArg(
                '--force-fieldtrials=NetworkQualityEstimator/Enabled/'
                'DataReductionProxyServerExperiments/IgnoreCountryBlacklist')

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

            lite_page_responses = 0
            checked_chrome_proxy_header = False
            for response in test_driver.GetHTTPResponses():
                if response.request_headers:
                    # Verify client sends ignore directive on main frame request.
                    self.assertIn('exp=ignore_preview_blacklist',
                                  response.request_headers['chrome-proxy'])
                    self.assertEqual(
                        '2G', response.request_headers['chrome-proxy-ect'])
                    checked_chrome_proxy_header = True
                if response.url.endswith('html'):
                    self.assertTrue(self.checkLitePageResponse(response))
                    lite_page_responses = lite_page_responses + 1
                    # Expect no fallback page policy
                    if 'chrome-proxy' in response.response_headers:
                        self.assertNotIn(
                            'page-policies',
                            response.response_headers['chrome-proxy'])
                else:
                    # No subresources should accept transforms.
                    self.assertNotIn('chrome-proxy-accept-transform',
                                     response.request_headers)
            self.assertTrue(checked_chrome_proxy_header)

            # Verify that a Lite Page response for the main frame was seen.
            self.assertEqual(1, lite_page_responses)

            self.assertPreviewShownViaHistogram(test_driver, 'LitePage')
Exemple #5
0
    def testLitePageNano(self):
        # If it was attempted to run with another experiment, skip this test.
        if common.ParseFlags().browser_args and (
                '--data-reduction-proxy-experiment'
                in common.ParseFlags().browser_args):
            self.skipTest('This test cannot be run with other experiments.')
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg(
                '--enable-features='
                'Previews,DataReductionProxyDecidesTransform')
            # Need to force 2G speed to get lite-page response.
            test_driver.AddChromeArg('--force-effective-connection-type=2G')
            # Set exp=client_test_nano to force Nano response.
            test_driver.AddChromeArg(
                '--data-reduction-proxy-experiment=client_test_nano')

            # This page is long and has many media resources.
            test_driver.LoadURL(
                'http://check.googlezip.net/metrics/index.html')
            time.sleep(2)

            lite_page_responses = 0
            btf_response = 0
            image_responses = 0
            for response in test_driver.GetHTTPResponses():
                # Verify that a Lite Page response for the main frame was seen.
                if response.url.endswith('html'):
                    if (self.checkLitePageResponse(response)):
                        lite_page_responses = lite_page_responses + 1
                # Keep track of BTF responses.
                u = urlparse(response.url)
                if u.path == "/b":
                    btf_response = btf_response + 1
                # Keep track of image responses.
                if response.url.startswith("data:image"):
                    image_responses = image_responses + 1
                # Some video requests don't go through Flywheel.
                if 'content-type' in response.response_headers and (
                        'video/mp4'
                        in response.response_headers['content-type']):
                    continue
                # Make sure non-video requests are proxied.
                self.assertHasProxyHeaders(response)
                # Make sure there are no 4XX or 5xx status codes.
                self.assertLess(response.status, 400)

            self.assertEqual(1, lite_page_responses)
            self.assertEqual(1, btf_response)
            self.assertGreater(1, image_responses)
Exemple #6
0
    def testLitePageBTFWithoutFallback(self):
        # If it was attempted to run with another experiment, skip this test.
        if common.ParseFlags().browser_args and (
                '--data-reduction-proxy-experiment'
                in common.ParseFlags().browser_args):
            self.skipTest('This test cannot be run with other experiments.')
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            # Need to force 2G speed to get lite-page response.
            test_driver.AddChromeArg('--force-effective-connection-type=2G')

            # Need to force lite page so target page doesn't fallback to Lo-Fi
            # Set exp=alt1 to force Lite-page response.
            test_driver.AddChromeArg('--data-reduction-proxy-experiment=alt1')

            # This page is long and has many media resources.
            test_driver.LoadURL(
                'http://check.googlezip.net/metrics/index.html')

            # Verify that a Lite Page response for the main frame was seen.
            lite_page_responses = 0
            for response in test_driver.GetHTTPResponses():
                # Skip CSI requests when validating Lite Page headers. CSI requests
                # aren't expected to have LoFi headers.
                if '/csi?' in response.url:
                    continue
                if response.url.startswith('data:'):
                    continue
                if (self.checkLitePageResponse(response)):
                    lite_page_responses = lite_page_responses + 1
            self.assertEqual(1, lite_page_responses)

            # Scroll to the bottom of the window and ensure scrollHeight increases.
            original_scroll_height = test_driver.ExecuteJavascriptStatement(
                'document.body.scrollHeight')
            test_driver.ExecuteJavascriptStatement(
                'window.scrollTo(0,Math.max(document.body.scrollHeight));')
            # Give some time for loading after scrolling.
            time.sleep(2)
            new_scroll_height = test_driver.ExecuteJavascriptStatement(
                'document.body.scrollHeight')
            self.assertGreater(new_scroll_height, original_scroll_height)

            # Make sure there were more requests that were proxied.
            responses = test_driver.GetHTTPResponses(override_has_logs=True)
            self.assertNotEqual(0, len(responses))
            for response in responses:
                self.assertHasChromeProxyViaHeader(response)
                self.assertIn(response.status, [200, 204])
Exemple #7
0
def main():
    """Runs all non-blacklisted tests against Chromium field trials.

  This script run all chrome proxy integration tests that haven't been
  blacklisted against the field trial testing configuration used by Chromium
  perf bots.
  """
    flags = common.ParseFlags()
    experiment_args = ' '.join(GetExperimentArgs())
    common.ParseFlags = ParseFlagsWithExtraBrowserArgs(experiment_args)
    # Each test is wrapped in its own test suite so results can be evaluated
    # individually.
    for test_suite, test_id in GenerateTestSuites():
        buf = io.BytesIO()
        sys.stdout.write('%s... ' % test_id)
        sys.stdout.flush()
        testRunner = unittest.runner.TextTestRunner(
            stream=buf, verbosity=2, buffer=(not flags.disable_buffer))
        result = testRunner.run(test_suite)
        if result.wasSuccessful():
            print 'ok'
        else:
            print 'failed'
            print buf.getvalue()
            print 'To repeat this test, run: '
            print "%s %s %s --test_filter=%s --browser_args='%s'" % (
                sys.executable,
                os.path.join(os.path.dirname(__file__), 'run_all_tests.py'),
                ' '.join(sys.argv[1:]), '.'.join(
                    test_id.split('.')[1:]), experiment_args)
            if flags.failfast:
                return
def main():
    """Runs each set of tests against its set of variations.

  For each test combination, the above variation specifications will be used to
  setup the browser arguments for each test given above that will be run.
  """
    flags = common.ParseFlags()
    for variation_test in combinations:
        # Set browser arguments to use the given variations.
        extra_args = '--force-fieldtrials=' + '/'.join(
            variation_test['variations'])
        extra_args += ' --force-fieldtrial-params=' + ','.join(
            variation_test['variations-params'])
        common.ParseFlags = ParseFlagsWithExtraBrowserArgs(extra_args)
        # Run the given tests.
        loader = unittest.TestLoader()
        test_suite_iter = loader.discover(os.path.dirname(__file__),
                                          pattern='*.py')
        my_test_suite = GetAllTestsFromRegexList(variation_test['tests'],
                                                 test_suite_iter)
        testRunner = unittest.runner.TextTestRunner(
            verbosity=2,
            failfast=flags.failfast,
            buffer=(not flags.disable_buffer))
        testRunner.run(my_test_suite)
Exemple #9
0
    def testStaleLitePageNano(self):
        # If it was attempted to run with another experiment, skip this test.
        if common.ParseFlags().browser_args and (
                '--data-reduction-proxy-experiment'
                in common.ParseFlags().browser_args):
            self.skipTest('This test cannot be run with other experiments.')
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg(
                '--enable-features='
                'Previews,DataReductionProxyDecidesTransform')
            test_driver.AddChromeArg(
                '--disable-features=AndroidOmniboxPreviewsBadge')
            test_driver.AddChromeArg('--force-effective-connection-type=2G')
            # Set exp=client_test_nano to force Lite page response.
            test_driver.AddChromeArg(
                '--data-reduction-proxy-experiment=client_test_nano')
            # LoadURL waits for onLoadFinish so the Previews UI will be showing by
            # then since it's triggered on commit.
            test_driver.LoadURL(
                'http://check.googlezip.net/cacheable/test.html?age_seconds=360'
            )

            histogram = test_driver.GetHistogram(
                'Previews.StalePreviewTimestampShown')
            self.assertEqual(1, histogram['count'])
            # Check that there is a single entry in the 'Timestamp Shown' bucket.
            self.assertEqual({
                'count': 1,
                'high': 1,
                'low': 0
            }, histogram['buckets'][0])

            # Go to a non stale page and check that the stale timestamp is not shown.
            test_driver.LoadURL(
                'http://check.googlezip.net/cacheable/test.html?age_seconds=0')

            histogram = test_driver.GetHistogram(
                'Previews.StalePreviewTimestampShown')
            # Check that there is still a single entry in the 'Timestamp Shown'
            # bucket.
            self.assertEqual({
                'count': 1,
                'high': 1,
                'low': 0
            }, histogram['buckets'][0])
Exemple #10
0
    def testLitePageForcedExperiment(self):
        # If it was attempted to run with another experiment, skip this test.
        if common.ParseFlags().browser_args and (
                '--data-reduction-proxy-experiment'
                in common.ParseFlags().browser_args):
            self.skipTest('This test cannot be run with other experiments.')
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg(
                '--enable-features=NetworkQualityEstimator'
                '<NetworkQualityEstimator,'
                'Previews,DataReductionProxyDecidesTransform')
            test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
            test_driver.AddChromeArg('--enable-data-reduction-proxy-lite-page')

            # Force ECT to be 4G to confirm that we get Lite Page even for fast
            # conneciton.
            test_driver.AddChromeArg('--force-fieldtrial-params='
                                     'NetworkQualityEstimator.Enabled:'
                                     'force_effective_connection_type/4G')
            test_driver.AddChromeArg('--force-fieldtrials='
                                     'NetworkQualityEstimator/Enabled/')

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

            lite_page_responses = 0
            for response in test_driver.GetHTTPResponses():
                # Verify client sends force directive on every request for session.
                self.assertIn('exp=force_lite_page',
                              response.request_headers['chrome-proxy'])
                self.assertEqual('4G',
                                 response.request_headers['chrome-proxy-ect'])
                # Skip CSI requests when validating Lite Page headers. CSI requests
                # aren't expected to have LoFi headers.
                if '/csi?' in response.url:
                    continue
                if response.url.startswith('data:'):
                    continue
                if (self.checkLitePageResponse(response)):
                    lite_page_responses = lite_page_responses + 1

            # Verify that a Lite Page response for the main frame was seen.
            self.assertEqual(1, lite_page_responses)
Exemple #11
0
    def testLoFiForcedExperimentOldFlags(self):
        # If it was attempted to run with another experiment, skip this test.
        if common.ParseFlags().browser_args and (
                '--data-reduction-proxy-experiment'
                in common.ParseFlags().browser_args):
            self.skipTest('This test cannot be run with other experiments.')
        with TestDriver() as test_driver:
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg(
                '--enable-features='
                'Previews,DataReductionProxyDecidesTransform')
            test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')

            # Ensure fast network (4G) to ensure force flag ignores ECT.
            test_driver.AddChromeArg('--force-fieldtrial-params='
                                     'NetworkQualityEstimator.Enabled:'
                                     'force_effective_connection_type/4G')
            test_driver.AddChromeArg(
                '--force-fieldtrials=NetworkQualityEstimator/'
                'Enabled')

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

            lofi_responses = 0
            for response in test_driver.GetHTTPResponses():
                self.assertIn('exp=force_page_policies_empty_image',
                              response.request_headers['chrome-proxy'])
                if response.url.endswith('html'):
                    # Verify that the server provides the fallback directive
                    self.assertIn('chrome-proxy', response.response_headers)
                    self.assertIn('page-policies=empty-image',
                                  response.response_headers['chrome-proxy'])
                    continue
                if response.url.endswith('png'):
                    self.checkLoFiResponse(response, True)
                    lofi_responses = lofi_responses + 1

            # Verify that Lo-Fi responses were seen.
            self.assertNotEqual(0, lofi_responses)
def ParseFlagsWithExtraBrowserArgs(extra_args):
  """Generates a function to override common.ParseFlags.

  The returned function will honor everything in the original ParseFlags(), but
  adds on additional browser_args.

  Args:
    extra_args: The extra browser agruments to add.
  Returns:
    A function to override common.ParseFlags with additional browser_args.
  """
  original_flags = common.ParseFlags()
  def AddExtraBrowserArgs():
    original_flags.browser_args = ((original_flags.browser_args if
      original_flags.browser_args else '') + ' ' + extra_args)
    return original_flags
  return AddExtraBrowserArgs
def GetExperimentArgs():
  """Returns a list of arguments with all tested field trials.

  This function is a simple wrapper around the variation team's fieldtrail_util
  script that generates command line arguments to test Chromium field trials.

  Returns:
    an array of command line arguments to pass to chrome
  """
  config_path = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
    os.pardir, 'testing', 'variations', 'fieldtrial_testing_config.json')
  my_platform = ''
  if common.ParseFlags().android:
    my_platform = 'android'
  elif platform.system().lower() == 'linux':
    my_platform = 'linux'
  elif platform.system().lower() == 'windows':
    my_platform = 'windows'
  elif platform.system().lower() == 'darwin':
    my_platform = 'mac'
  else:
    raise Exception('unknown platform!')
  return fieldtrial_util.GenerateArgs(config_path, [my_platform])
Exemple #14
0
    def testLoFiCacheBypass(self):
        # If it was attempted to run with another experiment, skip this test.
        if common.ParseFlags().browser_args and (
                '--data-reduction-proxy-experiment'
                in common.ParseFlags().browser_args):
            self.skipTest('This test cannot be run with other experiments.')
        with TestDriver() as test_driver:
            # First page load, enable Lo-Fi and chrome proxy. Disable server
            # experiments such as tamper detection. This test should be run with
            # --profile-type=default command line for the same user profile and cache
            # to be used across the two page loads.
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=always-on')
            test_driver.AddChromeArg('--profile-type=default')
            test_driver.AddChromeArg(
                '--data-reduction-proxy-server-experiments-'
                'disabled')

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

            lofi_responses = 0
            for response in test_driver.GetHTTPResponses():
                if not response.url.endswith('png'):
                    continue
                if not response.request_headers:
                    continue
                if (self.checkLoFiResponse(response, True)):
                    lofi_responses = lofi_responses + 1

            # Verify that Lo-Fi responses were seen.
            self.assertNotEqual(0, lofi_responses)

            # Second page load with the chrome proxy off.
            test_driver._StopDriver()
            test_driver.RemoveChromeArg('--enable-spdy-proxy-auth')
            test_driver.LoadURL(
                'http://check.googlezip.net/cacheable/test.html')

            responses = 0
            for response in test_driver.GetHTTPResponses():
                if not response.url.endswith('png'):
                    continue
                if not response.request_headers:
                    continue
                responses = responses + 1
                self.assertNotHasChromeProxyViaHeader(response)
                self.checkLoFiResponse(response, False)

            # Verify that responses were seen.
            self.assertNotEqual(0, responses)

            # Third page load with the chrome proxy on and Lo-Fi off.
            test_driver._StopDriver()
            test_driver.AddChromeArg('--enable-spdy-proxy-auth')
            test_driver.RemoveChromeArg(
                '--data-reduction-proxy-lo-fi=always-on')
            test_driver.AddChromeArg('--data-reduction-proxy-lo-fi=disabled')
            test_driver.LoadURL(
                'http://check.googlezip.net/cacheable/test.html')

            responses = 0
            for response in test_driver.GetHTTPResponses():
                if not response.url.endswith('png'):
                    continue
                if not response.request_headers:
                    continue
                responses = responses + 1
                self.assertHasChromeProxyViaHeader(response)
                self.checkLoFiResponse(response, False)

            # Verify that responses were seen.
            self.assertNotEqual(0, responses)