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"""
76 test
= WebglConformanceValidator
79 def AddTestCommandLineOptions(parser
):
80 group
= optparse
.OptionGroup(parser
, 'WebGL conformance options')
81 group
.add_option('--webgl-conformance-version',
82 help='Version of the WebGL conformance tests to run.',
84 parser
.add_option_group(group
)
86 def CreatePageSet(self
, options
):
87 tests
= self
._ParseTests
('00_test_list.txt',
88 options
.webgl_conformance_version
)
91 'description': 'Executes WebGL conformance tests',
92 'user_agent_type': 'desktop',
93 'serving_dirs': [ '' ],
97 pages
= page_set_dict
['pages']
101 'name': 'WebglConformance.%s' %
102 test
.replace('/', '_').replace('-', '_').
103 replace('\\', '_').rpartition('.')[0].replace('.', '_'),
104 'url': 'file://' + test
,
105 'script_to_evaluate_on_commit': conformance_harness_script
,
107 {'action': 'navigate'},
110 'javascript': 'webglTestHarness._finished',
116 return page_set
.PageSet
.FromDict(page_set_dict
, conformance_path
)
118 def CreateExpectations(self
, page_set
):
119 return webgl_conformance_expectations
.WebGLConformanceExpectations()
122 def _ParseTests(path
, version
=None):
124 current_dir
= os
.path
.dirname(path
)
125 full_path
= os
.path
.normpath(os
.path
.join(conformance_path
, path
))
127 if not os
.path
.exists(full_path
):
128 raise Exception('The WebGL conformance test path specified ' +
129 'does not exist: ' + full_path
)
131 with
open(full_path
, 'r') as f
:
138 if line
.startswith('//') or line
.startswith('#'):
141 line_tokens
= line
.split(' ')
145 while i
< len(line_tokens
):
146 token
= line_tokens
[i
]
147 if token
== '--min-version':
149 min_version
= line_tokens
[i
]
152 if version
and min_version
and version
< min_version
:
155 test_name
= line_tokens
[-1]
157 if '.txt' in test_name
:
158 include_path
= os
.path
.join(current_dir
, test_name
)
159 test_paths
+= WebglConformance
._ParseTests
(
160 include_path
, version
)
162 test
= os
.path
.join(current_dir
, test_name
)
163 test_paths
.append(test
)