Beispiel #1
0
 def __init__(self, restart_after_each_page=False):
     super(ChromeProxyValidation, self).__init__(
         needs_browser_restart_after_each_page=restart_after_each_page)
     self._metrics = chrome_proxy.ChromeProxyMetric()
     self._page = None
     # Whether a timeout exception is expected during the test.
     self._expect_timeout = False
    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)
    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)
Beispiel #7
0
 def __init__(self, *args, **kwargs):
     super(ChromeProxyDataSaving, self).__init__(*args, **kwargs)
     self._metrics = chrome_proxy.ChromeProxyMetric()