Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1413)

Unified Diff: content/test/gpu/gpu_tests/pixel.py

Issue 23478021: Made Pixel tests functional. Captures tab content and compares to ref image (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/test/gpu/gpu_tests/pixel.py
diff --git a/content/test/gpu/gpu_tests/pixel.py b/content/test/gpu/gpu_tests/pixel.py
index 8545dd20336c9cade23dd0d209d069adfb26b169..28035299167ca4417b5a44778ecbf71008716bb4 100644
--- a/content/test/gpu/gpu_tests/pixel.py
+++ b/content/test/gpu/gpu_tests/pixel.py
@@ -1,23 +1,115 @@
# Copyright (c) 2012 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.
+from datetime import datetime
+import glob
+import os
+import re
+
from telemetry import test
+from telemetry.core.backends import png_bitmap
from telemetry.page import page_test
+test_data_dir = os.path.abspath(os.path.join(
Zhenyao Mo 2013/09/05 00:23:14 The reason we use a passed in dir is because the s
+ os.path.dirname(__file__), '..', '..', 'data', 'gpu'))
+
+generated_data_dir = os.path.join(test_data_dir, 'generated')
+ref_image_dir = os.path.join(test_data_dir, 'gpu_reference')
Ken Russell (switch to Gerrit) 2013/09/05 00:27:04 The current harness is careful not to dump images
class PixelTestFailure(Exception):
pass
-
class PixelValidator(page_test.PageTest):
def __init__(self):
super(PixelValidator, self).__init__('ValidatePage')
+ def CustomizeBrowserOptions(self, options):
+ options.AppendExtraBrowserArg('--enable-gpu-benchmarking')
+
def ValidatePage(self, page, tab, results):
- # TODO(bajones): Grab screenshot, compare to reference.
- # page.reference_image
- pass
+ if not tab.screenshot_supported:
+ raise page_test.Failure("Browser does not support screenshot capture")
+
+ screenshot = tab.Screenshot(5)
+
+ if not screenshot:
+ raise page_test.Failure("Could not capture screenshot")
+
+ image_name = PixelValidator.UrlToImageName(page.url)
+
+ ref_png = PixelValidator.GetReferenceImage(image_name, page.revision,
+ screenshot)
+
+ # Test new snapshot against existing reference image
+ if not ref_png.IsEqual(screenshot, tolerance=2):
+ PixelValidator.WriteErrorImages(image_name, page.revision, screenshot,
+ ref_png)
+ raise page_test.Failure("Reference image did not match captured screen")
+
+ @staticmethod
+ def UrlToImageName(url):
+ image_name = re.sub(r'^(http|https|file)://(/*)', '', url)
+ image_name = re.sub(r'\.\./', '', image_name)
+ image_name = re.sub(r'(\.|/|-)', '_', image_name)
+ return image_name
+
+ @staticmethod
+ def DeleteOldReferenceImages(ref_image_path, cur_revision):
+ if not cur_revision:
+ return
+
+ old_revisions = glob.glob(ref_image_path + "__rev_*.png")
+ for rev_path in old_revisions:
+ m = re.match(r'^.*__rev_(\d+)\.png$', rev_path)
+ if m and int(m.group(1)) < cur_revision:
+ print 'Found deprecated reference image. Deleting rev ' + m.group(1)
+ os.remove(rev_path)
+
+ @staticmethod
+ def GetReferenceImage(image_name, cur_revision, screenshot):
+ if not cur_revision:
+ cur_revision = 0
+
+ image_path = os.path.join(ref_image_dir, image_name)
+
+ PixelValidator.DeleteOldReferenceImages(image_path, cur_revision)
+
+ image_path = image_path + '__rev_' + str(cur_revision) + '.png'
+
+ try:
+ ref_png = png_bitmap.PngBitmap.FromFile(image_path)
+ except IOError:
+ ref_png = None
+
+ if ref_png:
+ return ref_png
+
+ print 'Reference image not found. Writing tab contents as reference.'
+
+ PixelValidator.WriteImage(image_path, screenshot)
+ return screenshot
+
+ @staticmethod
+ def WriteErrorImages(image_name, cur_revision, screenshot, ref_png):
+ capture_time = datetime.now()
+ full_image_name = image_name + '__rev_' + str(cur_revision)
+ full_image_name = full_image_name + capture_time.strftime("__%b%d_%H_%M_%S")
+ full_image_name = full_image_name + '.png'
+
+ PixelValidator.WriteImage(
+ os.path.join(generated_data_dir, 'FAIL_' + full_image_name), screenshot)
+
+ diff_png = screenshot.Diff(ref_png)
+ PixelValidator.WriteImage(
+ os.path.join(generated_data_dir, 'DIFF_' + full_image_name), diff_png)
+
+ @staticmethod
+ def WriteImage(image_path, png_image):
+ output_dir = os.path.dirname(image_path)
+ if not os.path.exists(output_dir):
+ os.makedirs(output_dir)
+ png_image.WriteFile(image_path)
class Pixel(test.Test):
enabled = False

Powered by Google App Engine
This is Rietveld 408576698