[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / gpu_rasterization.py
blobe12be1294852f9bd269a731c6898470586884a47
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.
5 import cloud_storage_test_base
6 import gpu_rasterization_expectations
7 import optparse
8 import page_sets
10 from telemetry.util import image_util
13 test_harness_script = r"""
14 var domAutomationController = {};
15 domAutomationController._succeeded = false;
16 domAutomationController._finished = false;
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;
27 window.domAutomationController = domAutomationController;
28 """
30 def _DidTestSucceed(tab):
31 return tab.EvaluateJavaScript('domAutomationController._succeeded')
33 class GpuRasterizationValidator(cloud_storage_test_base.ValidatorBase):
34 def CustomizeBrowserOptions(self, options):
35 options.AppendExtraBrowserArgs(['--enable-threaded-compositing',
36 '--enable-impl-side-painting',
37 '--force-gpu-rasterization',
38 '--enable-gpu-benchmarking'])
40 def ValidateAndMeasurePageInner(self, page, tab, results):
41 if not _DidTestSucceed(tab):
42 raise page_test.Failure('Page indicated a failure')
44 if not hasattr(page, 'expectations') or not page.expectations:
45 raise page_test.Failure('Expectations not specified')
47 if not tab.screenshot_supported:
48 raise page_test.Failure('Browser does not support screenshot capture')
50 screenshot = tab.Screenshot()
51 if screenshot is None:
52 raise page_test.Failure('Could not capture screenshot')
54 device_pixel_ratio = tab.EvaluateJavaScript('window.devicePixelRatio')
55 if hasattr(page, 'test_rect'):
56 test_rect = [int(x * device_pixel_ratio) for x in page.test_rect]
57 screenshot = image_util.Crop(screenshot, test_rect[0], test_rect[1],
58 test_rect[2], test_rect[3])
60 self._ValidateScreenshotSamples(
61 page.display_name,
62 screenshot,
63 page.expectations,
64 device_pixel_ratio)
67 class GpuRasterization(cloud_storage_test_base.TestBase):
68 """Tests that GPU rasterization produces valid content"""
69 test = GpuRasterizationValidator
71 @classmethod
72 def Name(cls):
73 return 'gpu_rasterization'
75 def CreateStorySet(self, options):
76 story_set = page_sets.GpuRasterizationTestsStorySet(self.GetExpectations())
77 for page in story_set:
78 page.script_to_evaluate_on_commit = test_harness_script
79 return story_set
81 def _CreateExpectations(self):
82 return gpu_rasterization_expectations.GpuRasterizationExpectations()