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.reportResults(null, false, message);
57 testHarness.notifyFinished(null);
61 def _DidWebGLTestSucceed(tab
):
62 return tab
.EvaluateJavaScript('webglTestHarness._allTestSucceeded')
64 def _WebGLTestMessages(tab
):
65 return tab
.EvaluateJavaScript('webglTestHarness._messages')
67 class WebglConformanceValidator(page_test
.PageTest
):
69 super(WebglConformanceValidator
, self
).__init
__(attempts
=1, max_failures
=10)
71 def ValidateAndMeasurePage(self
, page
, tab
, results
):
72 if not _DidWebGLTestSucceed(tab
):
73 raise page_test
.Failure(_WebGLTestMessages(tab
))
75 def CustomizeBrowserOptions(self
, options
):
76 options
.AppendExtraBrowserArgs([
77 '--disable-gesture-requirement-for-media-playback',
78 '--disable-domain-blocking-for-3d-apis',
79 '--disable-gpu-process-crash-limit'
83 class WebglConformancePage(page_module
.Page
):
84 def __init__(self
, page_set
, test
):
85 super(WebglConformancePage
, self
).__init
__(
86 url
='file://' + test
, page_set
=page_set
, base_dir
=page_set
.base_dir
,
87 name
=('WebglConformance.%s' %
88 test
.replace('/', '_').replace('-', '_').
89 replace('\\', '_').rpartition('.')[0].replace('.', '_')))
90 self
.script_to_evaluate_on_commit
= conformance_harness_script
92 def RunNavigateSteps(self
, action_runner
):
93 action_runner
.NavigateToPage(self
)
94 action_runner
.WaitForJavaScriptCondition(
95 'webglTestHarness._finished', timeout_in_seconds
=180)
98 class WebglConformance(benchmark_module
.Benchmark
):
99 """Conformance with Khronos WebGL Conformance Tests"""
100 test
= WebglConformanceValidator
103 def AddTestCommandLineArgs(cls
, group
):
104 group
.add_option('--webgl-conformance-version',
105 help='Version of the WebGL conformance tests to run.',
108 def CreatePageSet(self
, options
):
109 tests
= self
._ParseTests
('00_test_list.txt',
110 options
.webgl_conformance_version
)
112 ps
= page_set
.PageSet(
113 user_agent_type
='desktop',
115 file_path
=conformance_path
)
118 ps
.AddPage(WebglConformancePage(ps
, test
))
122 def CreateExpectations(self
, page_set
):
123 return webgl_conformance_expectations
.WebGLConformanceExpectations()
126 def _ParseTests(path
, version
=None):
128 current_dir
= os
.path
.dirname(path
)
129 full_path
= os
.path
.normpath(os
.path
.join(conformance_path
, path
))
131 if not os
.path
.exists(full_path
):
132 raise Exception('The WebGL conformance test path specified ' +
133 'does not exist: ' + full_path
)
135 with
open(full_path
, 'r') as f
:
142 if line
.startswith('//') or line
.startswith('#'):
145 line_tokens
= line
.split(' ')
149 while i
< len(line_tokens
):
150 token
= line_tokens
[i
]
151 if token
== '--min-version':
153 min_version
= line_tokens
[i
]
156 if version
and min_version
and version
< min_version
:
159 test_name
= line_tokens
[-1]
161 if '.txt' in test_name
:
162 include_path
= os
.path
.join(current_dir
, test_name
)
163 test_paths
+= WebglConformance
._ParseTests
(
164 include_path
, version
)
166 test
= os
.path
.join(current_dir
, test_name
)
167 test_paths
.append(test
)