1 # Copyright 2013 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 import hardware_accelerated_feature_expectations
as expectations
6 from telemetry
import benchmark
7 from telemetry
.page
import page
as page_module
8 from telemetry
.page
import page_set
9 from telemetry
.page
import page_test
11 test_harness_script
= r
"""
12 function VerifyHardwareAccelerated(feature) {
14 var list = document.querySelector('.feature-status-list');
15 for (var i=0; i < list.childElementCount; i++) {
16 var span_list = list.children[i].getElementsByTagName('span');
17 var feature_str = span_list[0].textContent;
18 var value_str = span_list[1].textContent;
19 if ((feature_str == feature) &&
20 (value_str == 'Hardware accelerated')) {
28 class _HardwareAcceleratedFeatureValidator(page_test
.PageTest
):
29 def ValidateAndMeasurePage(self
, page
, tab
, results
):
30 feature
= page
.feature
31 if not tab
.EvaluateJavaScript('VerifyHardwareAccelerated("%s")' % feature
):
32 print 'Test failed. Printing page contents:'
33 print tab
.EvaluateJavaScript('document.body.innerHTML')
34 raise page_test
.Failure('%s not hardware accelerated' % feature
)
36 def safe_feature_name(feature
):
37 return feature
.lower().replace(' ', '_')
39 class ChromeGpuPage(page_module
.Page
):
40 def __init__(self
, page_set
, feature
):
41 super(ChromeGpuPage
, self
).__init
__(
42 url
='chrome://gpu', page_set
=page_set
, base_dir
=page_set
.base_dir
,
43 name
=('HardwareAcceleratedFeature.%s_accelerated' %
44 safe_feature_name(feature
)))
45 self
.feature
= feature
46 self
.script_to_evaluate_on_commit
= test_harness_script
48 class HardwareAcceleratedFeature(benchmark
.Benchmark
):
49 """Tests GPU acceleration is reported as active for various features"""
50 test
= _HardwareAcceleratedFeatureValidator
52 def CreateExpectations(self
):
53 return expectations
.HardwareAcceleratedFeatureExpectations()
55 def CreatePageSet(self
, options
):
56 features
= ['WebGL', 'Canvas']
58 ps
= page_set
.PageSet(user_agent_type
='desktop', file_path
='')
60 for feature
in features
:
61 ps
.AddPage(ChromeGpuPage(page_set
=ps
, feature
=feature
))