Example #1
0
  def testChromeProxyMetricForSafebrowsing(self):
    metric = metrics.ChromeProxyMetric()
    metric.SetEvents([EVENT_MALWARE_PROXY])
    results = test_page_test_results.TestPageTestResults(self)

    metric.AddResultsForSafebrowsing(None, results)
    results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True)

    # Clear results and metrics to test no response for safebrowsing
    results = test_page_test_results.TestPageTestResults(self)
    metric.SetEvents([])
    metric.AddResultsForSafebrowsing(None, results)
    results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean', True)
Example #2
0
 def testChromeProxyMetricForCorsBypass(self):
   metric = metrics.ChromeProxyMetric()
   metric.SetEvents([EVENT_HTML_PROXY_DEPRECATED_VIA,
                     EVENT_IMAGE_BYPASS,
                     EVENT_IMAGE_DIRECT])
   results = test_page_test_results.TestPageTestResults(self)
   metric.AddResultsForCorsBypass(None, results)
   results.AssertHasPageSpecificScalarValue('cors_bypass', 'count', 1)
Example #3
0
    def testNetworkMetricResults(self):
        events = [
            # A plain text HTML.
            self.MakeNetworkTimelineEvent(url='http://test.html1',
                                          response_headers={
                                              'Content-Type':
                                              'text/html',
                                              'Content-Length':
                                              str(len(HTML_BODY)),
                                          },
                                          body=HTML_BODY),
            # A compressed HTML.
            self.MakeNetworkTimelineEvent(url='http://test.html2',
                                          response_headers={
                                              'Content-Type':
                                              'text/html',
                                              'Content-Encoding':
                                              'gzip',
                                              'X-Original-Content-Length':
                                              str(len(HTML_BODY)),
                                          },
                                          body=HTML_BODY),
            # A base64 encoded image.
            self.MakeNetworkTimelineEvent(url='http://test.image',
                                          response_headers={
                                              'Content-Type':
                                              'image/jpeg',
                                              'Content-Encoding':
                                              'gzip',
                                              'X-Original-Content-Length':
                                              str(IMAGE_OCL),
                                          },
                                          body=base64.b64encode(IMAGE_BODY),
                                          base64_encoded_body=True),
        ]
        metric = network_metrics.NetworkMetric()
        metric._events = events
        metric.compute_data_saving = True

        self.assertTrue(len(events), len(list(metric.IterResponses(None))))
        results = test_page_test_results.TestPageTestResults(self)
        metric.AddResults(None, results)

        cl = len(HTML_BODY) + GZIPPED_HTML_LEN + len(IMAGE_BODY)
        results.AssertHasPageSpecificScalarValue('content_length', 'bytes', cl)

        ocl = len(HTML_BODY) + len(HTML_BODY) + IMAGE_OCL
        results.AssertHasPageSpecificScalarValue('original_content_length',
                                                 'bytes', ocl)

        saving_percent = float(ocl - cl) * 100 / ocl
        results.AssertHasPageSpecificScalarValue('data_saving', 'percent',
                                                 saving_percent)
Example #4
0
  def testChromeProxyMetricForDataSaving(self):
    metric = metrics.ChromeProxyMetric()
    events = [
        EVENT_HTML_PROXY,
        EVENT_HTML_PROXY_DEPRECATED_VIA,
        EVENT_IMAGE_PROXY_CACHED,
        EVENT_IMAGE_DIRECT]
    metric.SetEvents(events)

    self.assertTrue(len(events), len(list(metric.IterResponses(None))))
    results = test_page_test_results.TestPageTestResults(self)

    metric.AddResultsForDataSaving(None, results)
    results.AssertHasPageSpecificScalarValue('resources_via_proxy', 'count', 2)
    results.AssertHasPageSpecificScalarValue('resources_from_cache', 'count', 1)
    results.AssertHasPageSpecificScalarValue('resources_direct', 'count', 2)
    def testChromeProxyMetricForBlockOnce(self):
        metric = metrics.ChromeProxyMetric()
        metric.SetEvents([EVENT_HTML_DIRECT, EVENT_IMAGE_PROXY_VIA])
        results = test_page_test_results.TestPageTestResults(self)
        metric.AddResultsForBlockOnce(None, results)
        results.AssertHasPageSpecificScalarValue('eligible_responses', 'count',
                                                 2)
        results.AssertHasPageSpecificScalarValue('bypass', 'count', 1)

        metric.SetEvents([EVENT_HTML_DIRECT, EVENT_IMAGE_DIRECT])
        exception_occurred = False
        try:
            metric.AddResultsForBlockOnce(None, results)
        except metrics.ChromeProxyMetricException:
            exception_occurred = True
        # The second response was over direct, but was expected via proxy.
        self.assertTrue(exception_occurred)
    def testChromeProxyMetricForHTTPFallback(self):
        metric = metrics.ChromeProxyMetric()
        metric.SetEvents([
            EVENT_HTML_PROXY_VIA_HTTP_FALLBACK,
            EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK
        ])
        results = test_page_test_results.TestPageTestResults(self)
        metric.AddResultsForHTTPFallback(None, results)
        results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 2)

        metric.SetEvents([EVENT_HTML_PROXY_VIA, EVENT_IMAGE_PROXY_VIA])
        exception_occurred = False
        try:
            metric.AddResultsForHTTPFallback(None, results)
        except metrics.ChromeProxyMetricException:
            exception_occurred = True
        # The responses came through the SPDY proxy, but were expected through the
        # HTTP fallback proxy.
        self.assertTrue(exception_occurred)
    def testChromeProxyMetricForHTTPToDirectFallback(self):
        metric = metrics.ChromeProxyMetric()
        metric.SetEvents([
            EVENT_HTML_PROXY_VIA_HTTP_FALLBACK, EVENT_HTML_DIRECT,
            EVENT_IMAGE_DIRECT
        ])
        results = test_page_test_results.TestPageTestResults(self)
        metric.AddResultsForHTTPToDirectFallback(None, results)
        results.AssertHasPageSpecificScalarValue('via_fallback', 'count', 1)
        results.AssertHasPageSpecificScalarValue('bypass', 'count', 2)

        metric.SetEvents([EVENT_HTML_PROXY_VIA, EVENT_HTML_DIRECT])
        exception_occurred = False
        try:
            metric.AddResultsForHTTPToDirectFallback(None, results)
        except metrics.ChromeProxyMetricException:
            exception_occurred = True
        # The first response was expected through the HTTP fallback proxy.
        self.assertTrue(exception_occurred)

        metric.SetEvents([
            EVENT_HTML_PROXY_VIA_HTTP_FALLBACK,
            EVENT_HTML_PROXY_VIA_HTTP_FALLBACK,
            EVENT_IMAGE_PROXY_VIA_HTTP_FALLBACK
        ])
        exception_occurred = False
        try:
            metric.AddResultsForHTTPToDirectFallback(None, results)
        except metrics.ChromeProxyMetricException:
            exception_occurred = True
        # All but the first response were expected to be over direct.
        self.assertTrue(exception_occurred)

        metric.SetEvents(
            [EVENT_HTML_DIRECT, EVENT_HTML_DIRECT, EVENT_IMAGE_DIRECT])
        exception_occurred = False
        try:
            metric.AddResultsForHTTPToDirectFallback(None, results)
        except metrics.ChromeProxyMetricException:
            exception_occurred = True
        # The first response was expected through the HTTP fallback proxy.
        self.assertTrue(exception_occurred)
    def testChromeProxyMetricForBypass(self):
        metric = metrics.ChromeProxyMetric()
        metric.SetEvents([
            EVENT_HTML_DIRECT, EVENT_HTML_PROXY_DEPRECATED_VIA,
            EVENT_IMAGE_PROXY_CACHED, EVENT_IMAGE_DIRECT
        ])
        results = test_page_test_results.TestPageTestResults(self)

        bypass_exception = False
        try:
            metric.AddResultsForBypass(None, results)
        except metrics.ChromeProxyMetricException:
            bypass_exception = True
        # Two of the first three events have Via headers.
        self.assertTrue(bypass_exception)

        # Use directly fetched image only. It is treated as bypassed.
        metric.SetEvents([EVENT_IMAGE_DIRECT])
        metric.AddResultsForBypass(None, results)
        results.AssertHasPageSpecificScalarValue('bypass', 'count', 1)
    def testChromeProxyMetricForHeaderValidation(self):
        metric = metrics.ChromeProxyMetric()
        metric.SetEvents([
            EVENT_HTML_DIRECT, EVENT_HTML_PROXY_DEPRECATED_VIA,
            EVENT_IMAGE_PROXY_CACHED, EVENT_IMAGE_DIRECT
        ])

        results = test_page_test_results.TestPageTestResults(self)

        missing_via_exception = False
        try:
            metric.AddResultsForHeaderValidation(None, results)
        except metrics.ChromeProxyMetricException:
            missing_via_exception = True
        # Only the HTTP image response does not have a valid Via header.
        self.assertTrue(missing_via_exception)

        # Two events with valid Via headers.
        metric.SetEvents(
            [EVENT_HTML_PROXY_DEPRECATED_VIA, EVENT_IMAGE_PROXY_CACHED])
        metric.AddResultsForHeaderValidation(None, results)
        results.AssertHasPageSpecificScalarValue('checked_via_header', 'count',
                                                 2)
Example #10
0
  def testChromeProxyMetricForHTTPFallback(self):
    metric = metrics.ChromeProxyMetric()
    metric.SetEvents([
        EVENT_HTML_PROXY,
        EVENT_HTML_PROXY_DEPRECATED_VIA])
    results = test_page_test_results.TestPageTestResults(self)

    fallback_exception = False
    info = {}
    info['enabled'] = False
    self._StubGetProxyInfo(info)
    try:
      metric.AddResultsForBypass(None, results)
    except metrics.ChromeProxyMetricException:
      fallback_exception = True
    self.assertTrue(fallback_exception)

    fallback_exception = False
    info['enabled'] = True
    info['proxies'] = [
        'something.else.com:80',
        metrics.PROXY_SETTING_DIRECT
        ]
    self._StubGetProxyInfo(info)
    try:
      metric.AddResultsForBypass(None, results)
    except metrics.ChromeProxyMetricException:
      fallback_exception = True
    self.assertTrue(fallback_exception)

    info['enabled'] = True
    info['proxies'] = [
        metrics.PROXY_SETTING_HTTP,
        metrics.PROXY_SETTING_DIRECT
        ]
    self._StubGetProxyInfo(info)
    metric.AddResultsForHTTPFallback(None, results)
Example #11
0
 def GetResults(self, metric, model, renderer_thread, interaction_record):
     results = test_page_test_results.TestPageTestResults(self)
     metric.AddResults(model, renderer_thread, interaction_record, results)
     return results