diff options
author | bajones@chromium.org <bajones@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-16 18:08:28 +0000 |
---|---|---|
committer | bajones@chromium.org <bajones@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-16 18:08:28 +0000 |
commit | fb16be49af31a2f000ab8277b9e77d48ecf5825b (patch) | |
tree | 2376487cb5da147415ad91e67cd7dbbc5a7862e1 /content | |
parent | 5d7acdd3818238dfe27441540a6a9f9bbdb05c68 (diff) | |
download | chromium_src-fb16be49af31a2f000ab8277b9e77d48ecf5825b.zip chromium_src-fb16be49af31a2f000ab8277b9e77d48ecf5825b.tar.gz chromium_src-fb16be49af31a2f000ab8277b9e77d48ecf5825b.tar.bz2 |
Made Pixel tests functional. Captures tab content and compares to ref image
BUG=278398
R=dtu@chromium.org, kbr@chromium.org, piman@chromium.org
Review URL: https://codereview.chromium.org/23478021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228950 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/test/data/gpu/pixel_browser_plugin.html | 7 | ||||
-rw-r--r-- | content/test/data/gpu/pixel_canvas2d.html | 7 | ||||
-rw-r--r-- | content/test/data/gpu/pixel_css3d.html | 7 | ||||
-rw-r--r-- | content/test/data/gpu/pixel_webgl.html | 7 | ||||
-rw-r--r-- | content/test/gpu/gpu_tests/pixel.py | 155 | ||||
-rw-r--r-- | content/test/gpu/page_sets/pixel_tests.json | 39 |
6 files changed, 217 insertions, 5 deletions
diff --git a/content/test/data/gpu/pixel_browser_plugin.html b/content/test/data/gpu/pixel_browser_plugin.html index b084c99..1534cec 100644 --- a/content/test/data/gpu/pixel_browser_plugin.html +++ b/content/test/data/gpu/pixel_browser_plugin.html @@ -1,4 +1,11 @@ <!DOCTYPE HTML> + +<!-- READ BEFORE UPDATING: +If this test is updated make sure to increment the "revision" value of the +associated test in content/test/gpu/page_sets/pixel_tests.json. This will ensure +that the baseline images are regenerated on the next run. +--> + <html> <head> <title>Browser Plugin Compositing Test: Projected Blue Box over Black Background</title> diff --git a/content/test/data/gpu/pixel_canvas2d.html b/content/test/data/gpu/pixel_canvas2d.html index 1df3d4b..75bfe49 100644 --- a/content/test/data/gpu/pixel_canvas2d.html +++ b/content/test/data/gpu/pixel_canvas2d.html @@ -1,4 +1,11 @@ <!DOCTYPE HTML> + +<!-- READ BEFORE UPDATING: +If this test is updated make sure to increment the "revision" value of the +associated test in content/test/gpu/page_sets/pixel_tests.json. This will ensure +that the baseline images are regenerated on the next run. +--> + <html> <head> <title>Canvas 2D Test: Red Box over Black Background</title> diff --git a/content/test/data/gpu/pixel_css3d.html b/content/test/data/gpu/pixel_css3d.html index ca49d9a..38e4f4e 100644 --- a/content/test/data/gpu/pixel_css3d.html +++ b/content/test/data/gpu/pixel_css3d.html @@ -1,4 +1,11 @@ <!DOCTYPE HTML> + +<!-- READ BEFORE UPDATING: +If this test is updated make sure to increment the "revision" value of the +associated test in content/test/gpu/page_sets/pixel_tests.json. This will ensure +that the baseline images are regenerated on the next run. +--> + <html> <head> <title>CSS 3D Test: Projected Blue Box over Black Background</title> diff --git a/content/test/data/gpu/pixel_webgl.html b/content/test/data/gpu/pixel_webgl.html index 40240f9..b82fa81 100644 --- a/content/test/data/gpu/pixel_webgl.html +++ b/content/test/data/gpu/pixel_webgl.html @@ -1,4 +1,11 @@ <!DOCTYPE HTML> + +<!-- READ BEFORE UPDATING: +If this test is updated make sure to increment the "revision" value of the +associated test in content/test/gpu/page_sets/pixel_tests.json. This will ensure +that the baseline images are regenerated on the next run. +--> + <html> <head> <title>WebGL Test: Green Triangle over Black Background</title> diff --git a/content/test/gpu/gpu_tests/pixel.py b/content/test/gpu/gpu_tests/pixel.py index 8545dd2..1f98853 100644 --- a/content/test/gpu/gpu_tests/pixel.py +++ b/content/test/gpu/gpu_tests/pixel.py @@ -1,25 +1,174 @@ # 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 optparse +import os +import re + from telemetry import test +from telemetry.core.backends import png_bitmap from telemetry.page import page_test +from telemetry.page import test_expectations + +test_data_dir = os.path.abspath(os.path.join( + os.path.dirname(__file__), '..', '..', 'data', 'gpu')) + +default_generated_data_dir = os.path.join(test_data_dir, 'generated') +default_reference_image_dir = os.path.join(test_data_dir, 'gpu_reference') + +test_harness_script = r""" + var domAutomationController = {}; + + domAutomationController._succeeded = false; + domAutomationController._finished = false; + domAutomationController.setAutomationId = function(id) {} + + domAutomationController.send = function(msg) { + domAutomationController._finished = true; + + if(msg.toLowerCase() == "success") { + domAutomationController._succeeded = true; + } else { + domAutomationController._succeeded = false; + } + } + + window.domAutomationController = domAutomationController; + console.log("Harness injected."); +""" class PixelTestFailure(Exception): pass +def _DidTestSucceed(tab): + return tab.EvaluateJavaScript('domAutomationController._succeeded') class PixelValidator(page_test.PageTest): def __init__(self): super(PixelValidator, self).__init__('ValidatePage') + def CustomizeBrowserOptions(self, options): + options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') + def ValidatePage(self, page, tab, results): - # TODO(bajones): Grab screenshot, compare to reference. - # page.reference_image - pass + if not _DidTestSucceed(tab): + raise page_test.Failure('Page indicated a failure') + + 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') + + if hasattr(page, 'test_rect'): + screenshot = screenshot.Crop( + page.test_rect[0], page.test_rect[1], + page.test_rect[2], page.test_rect[3]) + + image_name = PixelValidator.UrlToImageName(page.display_name) + + ref_png = PixelValidator.GetReferenceImage(self.options.reference_dir, + image_name, page.revision, screenshot) + + # Test new snapshot against existing reference image + if not ref_png.IsEqual(screenshot, tolerance=2): + PixelValidator.WriteErrorImages(self.options.generated_dir, image_name, + self.options.build_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 + "_*.png") + for rev_path in old_revisions: + m = re.match(r'^.*_(\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(img_dir, img_name, cur_revision, screenshot): + if not cur_revision: + cur_revision = 0 + + image_path = os.path.join(img_dir, img_name) + + PixelValidator.DeleteOldReferenceImages(image_path, cur_revision) + + image_path = image_path + '_' + 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(img_dir, img_name, build_revision, screenshot, ref_png): + full_image_name = img_name + '_' + str(build_revision) + full_image_name = full_image_name + '.png' + + PixelValidator.WriteImage( + os.path.join(img_dir, 'FAIL_' + full_image_name), screenshot) + + diff_png = screenshot.Diff(ref_png) + PixelValidator.WriteImage( + os.path.join(img_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 test = PixelValidator page_set = 'page_sets/pixel_tests.json' + + @staticmethod + def AddTestCommandLineOptions(parser): + group = optparse.OptionGroup(parser, 'Pixel test options') + group.add_option('--generated-dir', + help='Overrides the default location for generated test images that do ' + 'not match reference images', + default=default_generated_data_dir) + group.add_option('--reference-dir', + help='Overrides the default location for reference images', + default=default_reference_image_dir) + group.add_option('--build-revision', + help='Chrome revision being tested.', + default="unknownrev") + group.add_option('--gtest_output', + help='Ignored argument for compatibility with runtest.py harness') + parser.add_option_group(group) + + def CreateExpectations(self, page_set): + print page_set.pages + for page in page_set.pages: + page.script_to_evaluate_on_commit = test_harness_script + + return test_expectations.TestExpectations() diff --git a/content/test/gpu/page_sets/pixel_tests.json b/content/test/gpu/page_sets/pixel_tests.json index b96dd86..fead685 100644 --- a/content/test/gpu/page_sets/pixel_tests.json +++ b/content/test/gpu/page_sets/pixel_tests.json @@ -3,11 +3,46 @@ "user_agent_type": "desktop", "pages": [ { + "name": "Pixel.Canvas2DRedBox", + "url": "file://../../data/gpu/pixel_canvas2d.html", + "navigate_steps": [ + { "action": "navigate"}, + { + "action": "wait", + "javascript": "domAutomationController._finished", + "timeout": 30 + } + ], + "revision": 1, + "test_rect": [0, 0, 400, 300] + }, + { + "name": "Pixel.CSS3DBlueBox", + "url": "file://../../data/gpu/pixel_css3d.html", + "navigate_steps": [ + { "action": "navigate"}, + { + "action": "wait", + "javascript": "domAutomationController._finished", + "timeout": 30 + } + ], + "revision": 1, + "test_rect": [0, 0, 400, 300] + }, + { + "name": "Pixel.WebGLGreenTriangle", "url": "file://../../data/gpu/pixel_webgl.html", "navigate_steps": [ { "action": "navigate"}, - { "action": "wait", "seconds": 4 } - ] + { + "action": "wait", + "javascript": "domAutomationController._finished", + "timeout": 30 + } + ], + "revision": 1, + "test_rect": [0, 0, 400, 300] } ] } |