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 5import cloud_storage_test_base 6import optparse 7import page_sets 8 9 10test_harness_script = r""" 11 var domAutomationController = {}; 12 domAutomationController._succeeded = false; 13 domAutomationController._finished = false; 14 15 domAutomationController.setAutomationId = function(id) {} 16 domAutomationController.send = function(msg) { 17 domAutomationController._finished = true; 18 if (msg.toLowerCase() == "success") 19 domAutomationController._succeeded = true; 20 else 21 domAutomationController._succeeded = false; 22 } 23 24 window.domAutomationController = domAutomationController; 25""" 26 27def _DidTestSucceed(tab): 28 return tab.EvaluateJavaScript('domAutomationController._succeeded') 29 30class _GpuRasterizationValidator(cloud_storage_test_base.ValidatorBase): 31 def CustomizeBrowserOptions(self, options): 32 options.AppendExtraBrowserArgs(['--enable-threaded-compositing', 33 '--enable-impl-side-painting', 34 '--force-gpu-rasterization', 35 '--enable-gpu-benchmarking']) 36 37 def ValidateAndMeasurePage(self, page, tab, results): 38 if not _DidTestSucceed(tab): 39 raise page_test.Failure('Page indicated a failure') 40 41 if not hasattr(page, 'expectations') or not page.expectations: 42 raise page_test.Failure('Expectations not specified') 43 44 if not tab.screenshot_supported: 45 raise page_test.Failure('Browser does not support screenshot capture') 46 47 screenshot = tab.Screenshot() 48 if not screenshot: 49 raise page_test.Failure('Could not capture screenshot') 50 51 device_pixel_ratio = tab.EvaluateJavaScript('window.devicePixelRatio') 52 if hasattr(page, 'test_rect'): 53 test_rect = [int(x * device_pixel_ratio) for x in page.test_rect] 54 screenshot = screenshot.Crop( 55 test_rect[0], test_rect[1], 56 test_rect[2], test_rect[3]) 57 58 self._ValidateScreenshotSamples( 59 page.display_name, 60 screenshot, 61 page.expectations, 62 device_pixel_ratio) 63 64 65class GpuRasterization(cloud_storage_test_base.TestBase): 66 """Tests that GPU rasterization produces valid content""" 67 test = _GpuRasterizationValidator 68 69 def CreatePageSet(self, options): 70 page_set = page_sets.GpuRasterizationTestsPageSet() 71 for page in page_set.pages: 72 page.script_to_evaluate_on_commit = test_harness_script 73 return page_set 74