diff options
-rw-r--r-- | content/test/gpu/gpu_tests/cloud_storage_test_base.py | 42 | ||||
-rw-r--r-- | content/test/gpu/gpu_tests/gpu_rasterization.py | 80 | ||||
-rw-r--r-- | content/test/gpu/gpu_tests/maps.py | 38 | ||||
-rw-r--r-- | content/test/gpu/page_sets/gpu_rasterization_tests.json | 93 |
4 files changed, 217 insertions, 36 deletions
diff --git a/content/test/gpu/gpu_tests/cloud_storage_test_base.py b/content/test/gpu/gpu_tests/cloud_storage_test_base.py index 90fb601..66a018d 100644 --- a/content/test/gpu/gpu_tests/cloud_storage_test_base.py +++ b/content/test/gpu/gpu_tests/cloud_storage_test_base.py @@ -21,6 +21,30 @@ default_generated_data_dir = os.path.join(test_data_dir, 'generated') error_image_cloud_storage_bucket = 'chromium-browser-gpu-tests' +def _CompareScreenshotSamples(screenshot, expectations, device_pixel_ratio): + for expectation in expectations: + location = expectation["location"] + x = location[0] * device_pixel_ratio + y = location[1] * device_pixel_ratio + + if x < 0 or y < 0 or x > screenshot.width or y > screenshot.height: + raise page_test.Failure( + 'Expected pixel location [%d, %d] is out of range on [%d, %d] image' % + (x, y, screenshot.width, screenshot.height)) + + actual_color = screenshot.GetPixelColor(x, y) + expected_color = bitmap.RgbaColor( + expectation["color"][0], + expectation["color"][1], + expectation["color"][2]) + if not actual_color.IsEqual(expected_color, expectation["tolerance"]): + raise page_test.Failure('Expected pixel at ' + str(location) + + ' to be ' + + str(expectation["color"]) + " but got [" + + str(actual_color.r) + ", " + + str(actual_color.g) + ", " + + str(actual_color.b) + "]") + class ValidatorBase(page_test.PageTest): def __init__(self, test_method_name): super(ValidatorBase, self).__init__(test_method_name) @@ -172,6 +196,24 @@ class ValidatorBase(page_test.PageTest): 'view_test_results.html?%s for this run\'s test results') % ( error_image_cloud_storage_bucket, upload_dir) + def _ValidateScreenshotSamples(self, url, + screenshot, expectations, device_pixel_ratio): + """Samples the given screenshot and verifies pixel color values. + The sample locations and expected color values are given in expectations. + In case any of the samples do not match the expected color, it raises + a Failure and dumps the screenshot locally or cloud storage depending on + what machine the test is being run.""" + try: + _CompareScreenshotSamples(screenshot, expectations, device_pixel_ratio) + except page_test.Failure: + image_name = self._UrlToImageName(url) + if self.options.test_machine_name: + self._UploadErrorImagesToCloudStorage(image_name, screenshot, None) + else: + self._WriteErrorImages(self.options.generated_dir, image_name, + screenshot, None) + raise + class TestBase(test.Test): @staticmethod def _AddTestCommandLineOptions(parser, option_group): diff --git a/content/test/gpu/gpu_tests/gpu_rasterization.py b/content/test/gpu/gpu_tests/gpu_rasterization.py new file mode 100644 index 0000000..9b89b07 --- /dev/null +++ b/content/test/gpu/gpu_tests/gpu_rasterization.py @@ -0,0 +1,80 @@ +# 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 optparse +import cloud_storage_test_base + +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; +""" + +def _DidTestSucceed(tab): + return tab.EvaluateJavaScript('domAutomationController._succeeded') + +class GpuRasterizationValidator(cloud_storage_test_base.ValidatorBase): + def __init__(self): + super(GpuRasterizationValidator, self).__init__('ValidatePage') + + def CustomizeBrowserOptions(self, options): + options.AppendExtraBrowserArgs(['--force-compositing-mode', + '--enable-threaded-compositing', + '--enable-impl-side-painting', + '--enable-gpu-rasterization', + '--enable-gpu-benchmarking']) + + def ValidatePage(self, page, tab, results): + 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() + 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]) + + if not hasattr(page, 'expectations') or not page.expectations: + raise page_test.Failure('Expectations not specified') + + device_pixel_ratio = tab.EvaluateJavaScript('window.devicePixelRatio') + self._ValidateScreenshotSamples( + page.display_name, + screenshot, + page.expectations, + device_pixel_ratio) + +class GpuRasterization(cloud_storage_test_base.TestBase): + """Tests that GPU rasterization produces valid content""" + test = GpuRasterizationValidator + page_set = 'page_sets/gpu_rasterization_tests.json' + + @staticmethod + def AddTestCommandLineOptions(parser): + group = optparse.OptionGroup(parser, 'GpuRasterization test options') + cloud_storage_test_base.TestBase._AddTestCommandLineOptions(parser, group) + parser.add_option_group(group) + + def CreatePageSet(self, options): + page_set = super(GpuRasterization, self).CreatePageSet(options) + for page in page_set.pages: + page.script_to_evaluate_on_commit = test_harness_script + return page_set diff --git a/content/test/gpu/gpu_tests/maps.py b/content/test/gpu/gpu_tests/maps.py index ed6792f..c7ea9aa 100644 --- a/content/test/gpu/gpu_tests/maps.py +++ b/content/test/gpu/gpu_tests/maps.py @@ -40,17 +40,8 @@ class MapsValidator(cloud_storage_test_base.ValidatorBase): dpr = tab.EvaluateJavaScript('window.devicePixelRatio') expected = self._ReadPixelExpectations(page) - - try: - self._CompareToExpectations(screenshot, expected, dpr) - except page_test.Failure: - image_name = self._UrlToImageName(page.display_name) - if self.options.test_machine_name: - self._UploadErrorImagesToCloudStorage(image_name, screenshot, None) - else: - self._WriteErrorImages(self.options.generated_dir, image_name, - screenshot, None) - raise + self._ValidateScreenshotSamples( + page.display_name, screenshot, expected, dpr) @staticmethod def SpinWaitOnRAF(tab, iterations, timeout = 60): @@ -81,31 +72,6 @@ class MapsValidator(cloud_storage_test_base.ValidatorBase): json_contents = json.load(f) return json_contents - def _CompareToExpectations(self, screenshot, expectations, devicePixelRatio): - for expectation in expectations: - location = expectation["location"] - x = location[0] * devicePixelRatio - y = location[1] * devicePixelRatio - - if x < 0 or y < 0 or x > screenshot.width or y > screenshot.height: - raise page_test.Failure( - 'Expected pixel location [%d, %d] is out of range on [%d, %d] image' % - (x, y, screenshot.width, screenshot.height)) - - pixel_color = screenshot.GetPixelColor(x, y) - expect_color = bitmap.RgbaColor( - expectation["color"][0], - expectation["color"][1], - expectation["color"][2]) - iter_result = pixel_color.IsEqual(expect_color, expectation["tolerance"]) - if not iter_result: - raise page_test.Failure('Expected pixel at ' + str(location) + - ' to be ' + - str(expectation["color"]) + " but got [" + - str(pixel_color.r) + ", " + - str(pixel_color.g) + ", " + - str(pixel_color.b) + "]") - class Maps(cloud_storage_test_base.TestBase): """Google Maps pixel tests.""" test = MapsValidator diff --git a/content/test/gpu/page_sets/gpu_rasterization_tests.json b/content/test/gpu/page_sets/gpu_rasterization_tests.json new file mode 100644 index 0000000..5823416 --- /dev/null +++ b/content/test/gpu/page_sets/gpu_rasterization_tests.json @@ -0,0 +1,93 @@ +{ + "description": "Basic test cases for GPU rasterization.", + "user_agent_type": "desktop", + "pages": [ + { + "name": "GpuRasterization.CSS3DBlueBox", + "url": "file://../../data/gpu/pixel_css3d.html", + "navigate_steps": [ + { "action": "navigate"}, + { + "action": "wait", + "javascript": "domAutomationController._finished", + "timeout": 30 + } + ], + "test_rect": [0, 0, 250, 250], + "expectations": [ + { + "comment": "body-t", + "location": [5, 5], + "color": [255, 255, 255], + "tolerance": 0 + }, + { + "comment": "body-r", + "location": [245, 5], + "color": [255, 255, 255], + "tolerance": 0 + }, + { + "comment": "body-b", + "location": [245, 245], + "color": [255, 255, 255], + "tolerance": 0 + }, + { + "comment": "body-l", + "location": [5, 245], + "color": [255, 255, 255], + "tolerance": 0 + }, + { + "comment": "background-t", + "location": [30, 30], + "color": [0, 0, 0], + "tolerance": 0 + }, + { + "comment": "background-r", + "location": [170, 30], + "color": [0, 0, 0], + "tolerance": 0 + }, + { + "comment": "background-b", + "location": [170, 170], + "color": [0, 0, 0], + "tolerance": 0 + }, + { + "comment": "background-l", + "location": [30, 170], + "color": [0, 0, 0], + "tolerance": 0 + }, + { + "comment": "box-t", + "location": [70, 70], + "color": [0, 0, 255], + "tolerance": 0 + }, + { + "comment": "box-r", + "location": [140, 70], + "color": [0, 0, 255], + "tolerance": 0 + }, + { + "comment": "box-b", + "location": [140, 120], + "color": [0, 0, 255], + "tolerance": 0 + }, + { + "comment": "box-l", + "location": [70, 120], + "color": [0, 0, 255], + "tolerance": 0 + } + ] + } + ] +} |