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 test as test_module
12 from telemetry.core import util
13 from telemetry.page import page_set
14 from telemetry.page import page_test
16 conformance_path = os.path.join(
17 util.GetChromiumSrcDir(), 'third_party', 'webgl_conformance')
19 conformance_harness_script = r"""
21 testHarness._allTestSucceeded = true;
22 testHarness._messages = '';
23 testHarness._failures = 0;
24 testHarness._finished = false;
25 testHarness._originalLog = window.console.log;
27 testHarness.log = function(msg) {
28 testHarness._messages += msg + "\n";
29 testHarness._originalLog.apply(window.console, [msg]);
32 testHarness.reportResults = function(success, msg) {
33 testHarness._allTestSucceeded = testHarness._allTestSucceeded && !!success;
35 testHarness._failures++;
41 testHarness.notifyFinished = function() {
42 testHarness._finished = true;
44 testHarness.navigateToPage = function(src) {
45 var testFrame = document.getElementById("test-frame");
49 window.webglTestHarness = testHarness;
50 window.parent.webglTestHarness = testHarness;
51 window.console.log = testHarness.log;
54 def _DidWebGLTestSucceed(tab):
55 return tab.EvaluateJavaScript('webglTestHarness._allTestSucceeded')
57 def _WebGLTestMessages(tab):
58 return tab.EvaluateJavaScript('webglTestHarness._messages')
60 class WebglConformanceValidator(page_test.PageTest):
62 super(WebglConformanceValidator, self).__init__('ValidatePage')
64 def ValidatePage(self, page, tab, results):
65 if not _DidWebGLTestSucceed(tab):
66 raise page_test.Failure(_WebGLTestMessages(tab))
68 def CustomizeBrowserOptions(self, options):
69 options.AppendExtraBrowserArgs(
70 '--disable-gesture-requirement-for-media-playback')
73 class WebglConformance(test_module.Test):
74 """Conformance with Khronos WebGL Conformance Tests"""
75 test = WebglConformanceValidator
78 def AddTestCommandLineOptions(parser):
79 group = optparse.OptionGroup(parser, 'WebGL conformance options')
80 group.add_option('--webgl-conformance-version',
81 help='Version of the WebGL conformance tests to run.',
83 parser.add_option_group(group)
85 def CreatePageSet(self, options):
86 tests = self._ParseTests('00_test_list.txt',
87 options.webgl_conformance_version)
90 'description': 'Executes WebGL conformance tests',
91 'user_agent_type': 'desktop',
92 'serving_dirs': [ '' ],
96 pages = page_set_dict['pages']
100 'name': 'WebglConformance.%s' %
101 test.replace('/', '_').replace('-', '_').
102 replace('\\', '_').rpartition('.')[0].replace('.', '_'),
103 'url': 'file://' + test,
104 'script_to_evaluate_on_commit': conformance_harness_script,
106 {'action': 'navigate'},
109 'javascript': 'webglTestHarness._finished',
115 return page_set.PageSet.FromDict(page_set_dict, conformance_path)
117 def CreateExpectations(self, page_set):
118 return webgl_conformance_expectations.WebGLConformanceExpectations()
121 def _ParseTests(path, version=None):
123 current_dir = os.path.dirname(path)
124 full_path = os.path.normpath(os.path.join(conformance_path, path))
126 if not os.path.exists(full_path):
127 raise Exception('The WebGL conformance test path specified ' +
128 'does not exist: ' + full_path)
130 with open(full_path, 'r') as f:
137 if line.startswith('//') or line.startswith('#'):
140 line_tokens = line.split(' ')
144 while i < len(line_tokens):
145 token = line_tokens[i]
146 if token == '--min-version':
148 min_version = line_tokens[i]
151 if version and min_version and version < min_version:
154 test_name = line_tokens[-1]
156 if '.txt' in test_name:
157 include_path = os.path.join(current_dir, test_name)
158 test_paths += WebglConformance._ParseTests(
159 include_path, version)
161 test = os.path.join(current_dir, test_name)
162 test_paths.append(test)