Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / webgl_conformance.py
blobaf58a8c105889a1e19989d08dbc219921a6c7527
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 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"""
20 var testHarness = {};
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;
34 if(!success) {
35 testHarness._failures++;
36 if(msg) {
37 testHarness.log(msg);
41 testHarness.notifyFinished = function() {
42 testHarness._finished = true;
44 testHarness.navigateToPage = function(src) {
45 var testFrame = document.getElementById("test-frame");
46 testFrame.src = src;
49 window.webglTestHarness = testHarness;
50 window.parent.webglTestHarness = testHarness;
51 window.console.log = testHarness.log;
52 """
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):
61 def __init__(self):
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 enabled = False
76 test = WebglConformanceValidator
78 @staticmethod
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.',
83 default='1.0.1')
84 parser.add_option_group(group)
86 def CreatePageSet(self, options):
87 tests = self._ParseTests('00_test_list.txt',
88 options.webgl_conformance_version)
90 page_set_dict = {
91 'description': 'Executes WebGL conformance tests',
92 'user_agent_type': 'desktop',
93 'serving_dirs': [ '' ],
94 'pages': []
97 pages = page_set_dict['pages']
99 for test in tests:
100 pages.append({
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,
106 'navigate_steps': [
107 {'action': 'navigate'},
109 'action': 'wait',
110 'javascript': 'webglTestHarness._finished',
111 'timeout': 120
116 return page_set.PageSet.FromDict(page_set_dict, conformance_path)
118 def CreateExpectations(self, page_set):
119 return webgl_conformance_expectations.WebGLConformanceExpectations()
121 @staticmethod
122 def _ParseTests(path, version=None):
123 test_paths = []
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:
132 for line in f:
133 line = line.strip()
135 if not line:
136 continue
138 if line.startswith('//') or line.startswith('#'):
139 continue
141 line_tokens = line.split(' ')
143 i = 0
144 min_version = None
145 while i < len(line_tokens):
146 token = line_tokens[i]
147 if token == '--min-version':
148 i += 1
149 min_version = line_tokens[i]
150 i += 1
152 if version and min_version and version < min_version:
153 continue
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)
161 else:
162 test = os.path.join(current_dir, test_name)
163 test_paths.append(test)
165 return test_paths