1 # Copyright (c) 2012 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.
9 import webgl_conformance_expectations
11 from telemetry import benchmark as benchmark_module
12 from telemetry.core import util
13 from telemetry.page import page_set
14 from telemetry.page import page as page_module
15 from telemetry.page import page_test
18 conformance_path = os.path.join(
19 util.GetChromiumSrcDir(),
20 'third_party', 'webgl', 'src', 'sdk', 'tests')
22 conformance_harness_script = r"""
24 testHarness._allTestSucceeded = true;
25 testHarness._messages = '';
26 testHarness._failures = 0;
27 testHarness._finished = false;
28 testHarness._originalLog = window.console.log;
30 testHarness.log = function(msg) {
31 testHarness._messages += msg + "\n";
32 testHarness._originalLog.apply(window.console, [msg]);
35 testHarness.reportResults = function(url, success, msg) {
36 testHarness._allTestSucceeded = testHarness._allTestSucceeded && !!success;
38 testHarness._failures++;
44 testHarness.notifyFinished = function(url) {
45 testHarness._finished = true;
47 testHarness.navigateToPage = function(src) {
48 var testFrame = document.getElementById("test-frame");
52 window.webglTestHarness = testHarness;
53 window.parent.webglTestHarness = testHarness;
54 window.console.log = testHarness.log;
55 window.onerror = function(message, url, line) {
56 testHarness._failures++;
58 testHarness.log(message);
60 testHarness.notifyFinished(null);
64 def _DidWebGLTestSucceed(tab):
65 return tab.EvaluateJavaScript('webglTestHarness._allTestSucceeded')
67 def _WebGLTestMessages(tab):
68 return tab.EvaluateJavaScript('webglTestHarness._messages')
70 class WebglConformanceValidator(page_test.PageTest):
72 super(WebglConformanceValidator, self).__init__(attempts=1, max_failures=10)
74 def ValidateAndMeasurePage(self, page, tab, results):
75 if not _DidWebGLTestSucceed(tab):
76 raise page_test.Failure(_WebGLTestMessages(tab))
78 def CustomizeBrowserOptions(self, options):
79 options.AppendExtraBrowserArgs([
80 '--disable-gesture-requirement-for-media-playback',
81 '--disable-domain-blocking-for-3d-apis',
82 '--disable-gpu-process-crash-limit'
86 class WebglConformancePage(page_module.Page):
87 def __init__(self, page_set, test):
88 super(WebglConformancePage, self).__init__(
89 url='file://' + test, page_set=page_set, base_dir=page_set.base_dir,
90 name=('WebglConformance.%s' %
91 test.replace('/', '_').replace('-', '_').
92 replace('\\', '_').rpartition('.')[0].replace('.', '_')))
93 self.script_to_evaluate_on_commit = conformance_harness_script
95 def RunNavigateSteps(self, action_runner):
96 action_runner.NavigateToPage(self)
97 action_runner.WaitForJavaScriptCondition(
98 'webglTestHarness._finished', timeout_in_seconds=120)
101 class WebglConformance(benchmark_module.Benchmark):
102 """Conformance with Khronos WebGL Conformance Tests"""
103 test = WebglConformanceValidator
106 def AddTestCommandLineArgs(cls, group):
107 group.add_option('--webgl-conformance-version',
108 help='Version of the WebGL conformance tests to run.',
111 def CreatePageSet(self, options):
112 tests = self._ParseTests('00_test_list.txt',
113 options.webgl_conformance_version)
115 ps = page_set.PageSet(
116 user_agent_type='desktop',
118 file_path=conformance_path)
121 ps.AddPage(WebglConformancePage(ps, test))
125 def CreateExpectations(self, page_set):
126 return webgl_conformance_expectations.WebGLConformanceExpectations()
129 def _ParseTests(path, version=None):
131 current_dir = os.path.dirname(path)
132 full_path = os.path.normpath(os.path.join(conformance_path, path))
134 if not os.path.exists(full_path):
135 raise Exception('The WebGL conformance test path specified ' +
136 'does not exist: ' + full_path)
138 with open(full_path, 'r') as f:
145 if line.startswith('//') or line.startswith('#'):
148 line_tokens = line.split(' ')
152 while i < len(line_tokens):
153 token = line_tokens[i]
154 if token == '--min-version':
156 min_version = line_tokens[i]
159 if version and min_version and version < min_version:
162 test_name = line_tokens[-1]
164 if '.txt' in test_name:
165 include_path = os.path.join(current_dir, test_name)
166 test_paths += WebglConformance._ParseTests(
167 include_path, version)
169 test = os.path.join(current_dir, test_name)
170 test_paths.append(test)