Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / webgl_conformance.py
blobcb2d6ad0f7fbf427c3734601ef328abff84beec6
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.
4 import json
5 import optparse
6 import os
7 import sys
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"""
23 var testHarness = {};
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;
37 if(!success) {
38 testHarness._failures++;
39 if(msg) {
40 testHarness.log(msg);
44 testHarness.notifyFinished = function(url) {
45 testHarness._finished = true;
47 testHarness.navigateToPage = function(src) {
48 var testFrame = document.getElementById("test-frame");
49 testFrame.src = src;
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);
59 """
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):
68 def __init__(self):
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
102 @classmethod
103 def AddTestCommandLineArgs(cls, group):
104 group.add_option('--webgl-conformance-version',
105 help='Version of the WebGL conformance tests to run.',
106 default='1.0.3')
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',
114 serving_dirs=[''],
115 file_path=conformance_path)
117 for test in tests:
118 ps.AddPage(WebglConformancePage(ps, test))
120 return ps
122 def CreateExpectations(self, page_set):
123 return webgl_conformance_expectations.WebGLConformanceExpectations()
125 @staticmethod
126 def _ParseTests(path, version=None):
127 test_paths = []
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:
136 for line in f:
137 line = line.strip()
139 if not line:
140 continue
142 if line.startswith('//') or line.startswith('#'):
143 continue
145 line_tokens = line.split(' ')
147 i = 0
148 min_version = None
149 while i < len(line_tokens):
150 token = line_tokens[i]
151 if token == '--min-version':
152 i += 1
153 min_version = line_tokens[i]
154 i += 1
156 if version and min_version and version < min_version:
157 continue
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)
165 else:
166 test = os.path.join(current_dir, test_name)
167 test_paths.append(test)
169 return test_paths