| OLD | NEW |
| (Empty) |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from gpu_tests import cloud_storage_test_base | |
| 6 from gpu_tests import gpu_rasterization_expectations | |
| 7 import page_sets | |
| 8 | |
| 9 from telemetry.page import legacy_page_test | |
| 10 from telemetry.util import image_util | |
| 11 | |
| 12 | |
| 13 test_harness_script = r""" | |
| 14 var domAutomationController = {}; | |
| 15 domAutomationController._succeeded = false; | |
| 16 domAutomationController._finished = false; | |
| 17 | |
| 18 domAutomationController.setAutomationId = function(id) {} | |
| 19 domAutomationController.send = function(msg) { | |
| 20 domAutomationController._finished = true; | |
| 21 if (msg.toLowerCase() == "success") | |
| 22 domAutomationController._succeeded = true; | |
| 23 else | |
| 24 domAutomationController._succeeded = false; | |
| 25 } | |
| 26 | |
| 27 window.domAutomationController = domAutomationController; | |
| 28 """ | |
| 29 | |
| 30 def _DidTestSucceed(tab): | |
| 31 return tab.EvaluateJavaScript('domAutomationController._succeeded') | |
| 32 | |
| 33 class GpuRasterizationValidator(cloud_storage_test_base.ValidatorBase): | |
| 34 def CustomizeBrowserOptions(self, options): | |
| 35 # --test-type=gpu is used only to suppress the "Google API Keys are missing" | |
| 36 # infobar, which causes flakiness in tests. | |
| 37 options.AppendExtraBrowserArgs(['--force-gpu-rasterization', | |
| 38 '--test-type=gpu']) | |
| 39 | |
| 40 def ValidateAndMeasurePage(self, page, tab, results): | |
| 41 if not _DidTestSucceed(tab): | |
| 42 raise legacy_page_test.Failure('Page indicated a failure') | |
| 43 | |
| 44 if not hasattr(page, 'expectations') or not page.expectations: | |
| 45 raise legacy_page_test.Failure('Expectations not specified') | |
| 46 | |
| 47 if not tab.screenshot_supported: | |
| 48 raise legacy_page_test.Failure( | |
| 49 'Browser does not support screenshot capture') | |
| 50 | |
| 51 screenshot = tab.Screenshot() | |
| 52 if screenshot is None: | |
| 53 raise legacy_page_test.Failure('Could not capture screenshot') | |
| 54 | |
| 55 device_pixel_ratio = tab.EvaluateJavaScript('window.devicePixelRatio') | |
| 56 if hasattr(page, 'test_rect'): | |
| 57 test_rect = [int(x * device_pixel_ratio) for x in page.test_rect] | |
| 58 screenshot = image_util.Crop(screenshot, test_rect[0], test_rect[1], | |
| 59 test_rect[2], test_rect[3]) | |
| 60 | |
| 61 self._ValidateScreenshotSamples( | |
| 62 tab, | |
| 63 page.display_name, | |
| 64 screenshot, | |
| 65 page.expectations, | |
| 66 device_pixel_ratio) | |
| 67 | |
| 68 | |
| 69 class GpuRasterization(cloud_storage_test_base.CloudStorageTestBase): | |
| 70 """Tests that GPU rasterization produces valid content""" | |
| 71 test = GpuRasterizationValidator | |
| 72 | |
| 73 def __init__(self, max_failures=None): | |
| 74 super(GpuRasterization, self).__init__(max_failures=max_failures) | |
| 75 | |
| 76 @classmethod | |
| 77 def Name(cls): | |
| 78 return 'gpu_rasterization' | |
| 79 | |
| 80 def CreateStorySet(self, options): | |
| 81 story_set = page_sets.GpuRasterizationTestsStorySet(self.GetExpectations()) | |
| 82 for page in story_set: | |
| 83 page.script_to_evaluate_on_commit = test_harness_script | |
| 84 return story_set | |
| 85 | |
| 86 def _CreateExpectations(self): | |
| 87 return gpu_rasterization_expectations.GpuRasterizationExpectations() | |
| OLD | NEW |