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
10 test_harness_script
= r
"""
11 var domAutomationController = {};
12 domAutomationController._succeeded = false;
13 domAutomationController._finished = false;
15 domAutomationController.setAutomationId = function(id) {}
16 domAutomationController.send = function(msg) {
17 domAutomationController._finished = true;
18 if (msg.toLowerCase() == "success")
19 domAutomationController._succeeded = true;
21 domAutomationController._succeeded = false;
24 window.domAutomationController = domAutomationController;
27 def _DidTestSucceed(tab
):
28 return tab
.EvaluateJavaScript('domAutomationController._succeeded')
30 class _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'])
37 def ValidateAndMeasurePage(self
, page
, tab
, results
):
38 if not _DidTestSucceed(tab
):
39 raise page_test
.Failure('Page indicated a failure')
41 if not hasattr(page
, 'expectations') or not page
.expectations
:
42 raise page_test
.Failure('Expectations not specified')
44 if not tab
.screenshot_supported
:
45 raise page_test
.Failure('Browser does not support screenshot capture')
47 screenshot
= tab
.Screenshot()
49 raise page_test
.Failure('Could not capture screenshot')
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])
58 self
._ValidateScreenshotSamples
(
65 class GpuRasterization(cloud_storage_test_base
.TestBase
):
66 """Tests that GPU rasterization produces valid content"""
67 test
= _GpuRasterizationValidator
68 page_set
= page_sets
.GpuRasterizationTestsPageSet
70 def CreatePageSet(self
, options
):
71 page_set
= super(GpuRasterization
, self
).CreatePageSet(options
)
72 for page
in page_set
.pages
:
73 page
.script_to_evaluate_on_commit
= test_harness_script