def testChromeProxyMetricForHTTPFallback(self):
        metric = chrome_proxy.ChromeProxyMetric()
        metric.SetEvents([EVENT_HTML_PROXY, EVENT_HTML_PROXY_DEPRECATED_VIA])
        results = test_page_measurement_results.TestPageMeasurementResults(
            self)

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

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

        info['enabled'] = True
        info['proxies'] = [
            chrome_proxy.PROXY_SETTING_HTTP, chrome_proxy.PROXY_SETTING_DIRECT
        ]
        self._StubGetProxyInfo(info)
        metric.AddResultsForHTTPFallback(None, results)
    def testChromeProxyMetricForSafebrowsing(self):
        metric = chrome_proxy.ChromeProxyMetric()
        metric.SetEvents([EVENT_MALWARE_PROXY])
        results = test_page_measurement_results.TestPageMeasurementResults(
            self)

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

        # Clear results and metrics to test no response for safebrowsing
        results = test_page_measurement_results.TestPageMeasurementResults(
            self)
        metric.SetEvents([])
        metric.AddResultsForSafebrowsing(None, results)
        results.AssertHasPageSpecificScalarValue('safebrowsing', 'boolean',
                                                 True)
Esempio n. 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.NetworkMetric()
        metric._events = events
        metric.compute_data_saving = True

        self.assertTrue(len(events), len(list(metric.IterResponses(None))))
        results = test_page_measurement_results.TestPageMeasurementResults(
            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)
    def testChromeProxyMetricForDataSaving(self):
        metric = chrome_proxy.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_measurement_results.TestPageMeasurementResults(
            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 testChromeProxyMetricForBypass(self):
        metric = chrome_proxy.ChromeProxyMetric()
        metric.SetEvents([
            EVENT_HTML_PROXY, EVENT_HTML_PROXY_DEPRECATED_VIA,
            EVENT_IMAGE_PROXY_CACHED, EVENT_IMAGE_DIRECT
        ])
        results = test_page_measurement_results.TestPageMeasurementResults(
            self)

        bypass_exception = False
        try:
            metric.AddResultsForBypass(None, results)
        except chrome_proxy.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 = chrome_proxy.ChromeProxyMetric()
        metric.SetEvents([
            EVENT_HTML_PROXY, EVENT_HTML_PROXY_DEPRECATED_VIA,
            EVENT_IMAGE_PROXY_CACHED, EVENT_IMAGE_DIRECT
        ])

        results = test_page_measurement_results.TestPageMeasurementResults(
            self)

        missing_via_exception = False
        try:
            metric.AddResultsForHeaderValidation(None, results)
        except chrome_proxy.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)
Esempio n. 7
0
 def GetResults(self, metric, model, renderer_thread, interaction_record):
     results = test_page_measurement_results.TestPageMeasurementResults(
         self)
     metric.AddResults(model, renderer_thread, interaction_record, results)
     return results
Esempio n. 8
0
 def GetResults(self, metric):
     results = test_page_measurement_results.TestPageMeasurementResults(
         self)
     tab = None
     metric.AddResults(tab, results)
     return results