def testAnnotateNodesNoLenses(self): graph_view = loading_graph_view.LoadingGraphView( self.trace, self.deps_lens) for node in graph_view.deps_graph.graph.Nodes(): self.assertFalse(node.is_ad) self.assertFalse(node.is_tracking) for edge in graph_view.deps_graph.graph.Edges(): self.assertFalse(edge.is_timing)
def get_network_dependency_graph(json_dict): trace = loading_trace.LoadingTrace.FromJsonDict(json_dict) content_lens = ( content_classification_lens.ContentClassificationLens.WithRulesFiles( trace, '', '')) frame_lens = frame_load_lens.FrameLoadLens(trace) activity = activity_lens.ActivityLens(trace) deps_lens = request_dependencies_lens.RequestDependencyLens(trace) graph_view = loading_graph_view.LoadingGraphView( trace, deps_lens, content_lens, frame_lens, activity) return graph_view
def testAnnotateNodesContentLens(self): ad_request_ids = set( [TestRequests.JS_REQUEST_UNRELATED_FRAME.request_id]) tracking_request_ids = set([TestRequests.JS_REQUEST.request_id]) content_lens = MockContentClassificationLens(ad_request_ids, tracking_request_ids) graph_view = loading_graph_view.LoadingGraphView( self.trace, self.deps_lens, content_lens) for node in graph_view.deps_graph.graph.Nodes(): request_id = node.request.request_id self.assertEqual(request_id in ad_request_ids, node.is_ad) self.assertEqual(request_id in tracking_request_ids, node.is_tracking)
def _ProcessJsonTrace(json_dict): trace = loading_trace.LoadingTrace.FromJsonDict(json_dict) content_lens = ( content_classification_lens.ContentClassificationLens.WithRulesFiles( trace, OPTIONS.ad_rules, OPTIONS.tracking_rules)) frame_lens = frame_load_lens.FrameLoadLens(trace) activity = activity_lens.ActivityLens(trace) deps_lens = request_dependencies_lens.RequestDependencyLens(trace) graph_view = loading_graph_view.LoadingGraphView( trace, deps_lens, content_lens, frame_lens, activity) if OPTIONS.noads: graph_view.RemoveAds() return graph_view
def testRemoveAdsPruneGraph(self): ad_request_ids = set([TestRequests.SECOND_REDIRECT_REQUEST.request_id]) tracking_request_ids = set([]) content_lens = MockContentClassificationLens(ad_request_ids, tracking_request_ids) graph_view = loading_graph_view.LoadingGraphView( self.trace, self.deps_lens, content_lens) graph_view.RemoveAds() request_ids = set([ n.request.request_id for n in graph_view.deps_graph.graph.Nodes() ]) expected_request_ids = set( [TestRequests.FIRST_REDIRECT_REQUEST.request_id]) self.assertSetEqual(expected_request_ids, request_ids)
def testEventInversion(self): self._UpdateRequestTiming({ '1234.redirect.1': (0, 0), '1234.redirect.2': (0, 0), '1234.1': (10, 100), '1234.12': (20, 50), '1234.42': (40, 70), '1234.56': (40, 150) }) graph_view = loading_graph_view.LoadingGraphView( self.trace, self.deps_lens) self.assertEqual(None, graph_view.GetInversionsAtTime(40)) self.assertEqual('1234.1', graph_view.GetInversionsAtTime(60)[0].request_id) self.assertEqual('1234.1', graph_view.GetInversionsAtTime(80)[0].request_id) self.assertEqual(None, graph_view.GetInversionsAtTime(110)) self.assertEqual(None, graph_view.GetInversionsAtTime(160))
def main(trace_file): import subprocess import loading_graph_view import loading_trace import request_dependencies_lens trace = loading_trace.LoadingTrace.FromJsonFile(trace_file) dependencies_lens = request_dependencies_lens.RequestDependencyLens(trace) activity = activity_lens.ActivityLens(trace) graph_view = loading_graph_view.LoadingGraphView(trace, dependencies_lens, activity=activity) visualization = LoadingGraphViewVisualization(graph_view) dotfile = trace_file + '.dot' pngfile = trace_file + '.png' with file(dotfile, 'w') as output: visualization.OutputDot(output) subprocess.check_call(['dot', '-Tpng', dotfile, '-o', pngfile])