[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / hardware_accelerated_feature.py
blobe4b2dea69a3a088a3bc199bcd9c70ede2d7de78a
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 gpu_test_base
5 import hardware_accelerated_feature_expectations as expectations
7 from telemetry.page import page_test
8 from telemetry.story import story_set as story_set_module
10 test_harness_script = r"""
11 function VerifyHardwareAccelerated(feature) {
12 feature += ': '
13 var list = document.querySelector('.feature-status-list');
14 for (var i=0; i < list.childElementCount; i++) {
15 var span_list = list.children[i].getElementsByTagName('span');
16 var feature_str = span_list[0].textContent;
17 var value_str = span_list[1].textContent;
18 if ((feature_str == feature) &&
19 (value_str == 'Hardware accelerated')) {
20 return true;
23 return false;
25 """;
27 class HardwareAcceleratedFeatureValidator(gpu_test_base.ValidatorBase):
28 def ValidateAndMeasurePageInner(self, page, tab, results):
29 feature = page.feature
30 if not tab.EvaluateJavaScript('VerifyHardwareAccelerated("%s")' % feature):
31 print 'Test failed. Printing page contents:'
32 print tab.EvaluateJavaScript('document.body.innerHTML')
33 raise page_test.Failure('%s not hardware accelerated' % feature)
35 def safe_feature_name(feature):
36 return feature.lower().replace(' ', '_')
38 class ChromeGpuPage(gpu_test_base.PageBase):
39 def __init__(self, story_set, feature, expectations):
40 super(ChromeGpuPage, self).__init__(
41 url='chrome://gpu', page_set=story_set, base_dir=story_set.base_dir,
42 name=('HardwareAcceleratedFeature.%s_accelerated' %
43 safe_feature_name(feature)),
44 expectations=expectations)
45 self.feature = feature
46 self.script_to_evaluate_on_commit = test_harness_script
48 class HardwareAcceleratedFeature(gpu_test_base.TestBase):
49 """Tests GPU acceleration is reported as active for various features"""
50 test = HardwareAcceleratedFeatureValidator
52 @classmethod
53 def Name(cls):
54 return 'hardware_accelerated_feature'
56 def _CreateExpectations(self):
57 return expectations.HardwareAcceleratedFeatureExpectations()
59 def CreateStorySet(self, options):
60 features = ['WebGL', 'Canvas']
62 ps = story_set_module.StorySet()
64 for feature in features:
65 ps.AddStory(ChromeGpuPage(story_set=ps, feature=feature,
66 expectations=self.GetExpectations()))
67 return ps