def _AdRequestsReport(cls, trace, ad_rules, tracking_rules):
     has_rules = bool(ad_rules) or bool(tracking_rules)
     requests = trace.request_track.GetEvents()
     result = {
         'request_count': len(requests),
         'ad_requests': 0 if ad_rules else None,
         'tracking_requests': 0 if tracking_rules else None,
         'ad_or_tracking_requests': 0 if has_rules else None,
         'ad_or_tracking_initiated_requests': 0 if has_rules else None
     }
     content_classification_lens = ContentClassificationLens(
         trace, ad_rules, tracking_rules)
     if not has_rules:
         return result
     for request in trace.request_track.GetEvents():
         is_ad = content_classification_lens.IsAdRequest(request)
         is_tracking = content_classification_lens.IsTrackingRequest(
             request)
         if ad_rules:
             result['ad_requests'] += int(is_ad)
         if tracking_rules:
             result['tracking_requests'] += int(is_tracking)
         result['ad_or_tracking_requests'] += int(is_ad or is_tracking)
     result['ad_or_tracking_initiated_requests'] = len(
         content_classification_lens.AdAndTrackingRequests())
     return result
 def testTrackingRequest(self):
     trace = test_utils.LoadingTraceFromEvents([self._REQUEST],
                                               self._PAGE_EVENTS)
     lens = ContentClassificationLens(trace, [], self._RULES)
     self.assertFalse(lens.IsAdRequest(self._REQUEST))
     self.assertTrue(lens.IsTrackingRequest(self._REQUEST))