# Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import re def result_contains_repaint_rects(text): return isinstance(text, str) and ( re.search('"repaintRects": \[$', text, re.MULTILINE) != None or text.find('Minimum repaint:') != -1) def extract_layer_tree(input_str): if not isinstance(input_str, str): return '{}' if input_str[0:2] == '{\n': start = 0 else: start = input_str.find('\n{\n') if start == -1: return '{}' end = input_str.find('\n}\n', start) if end == -1: return '{}' # FIXME: There may be multiple layer trees in the result. return input_str[start:end + 3] def generate_repaint_overlay_html(test_name, actual_text, expected_text): if not result_contains_repaint_rects(actual_text) and not result_contains_repaint_rects(expected_text): return '' expected_layer_tree = extract_layer_tree(expected_text) actual_layer_tree = extract_layer_tree(actual_text) minimum_repaint = '[]' minimum_repaint_match = re.search('Minimum repaint:\n(\[.*\n\])', actual_text, re.DOTALL) if minimum_repaint_match: minimum_repaint = minimum_repaint_match.group(1) return """ %(title)s Known issues


Expected Invalidations
""" % { 'title': test_name, 'expected': expected_layer_tree, 'actual': actual_layer_tree, 'minimum_repaint': minimum_repaint, }