1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
#!/usr/bin/python2.4
# Copyright 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Runs JavaScript unit tests in Selenium.
NOTE: If you manually write a test in python (vs using the generic test)
The name of the screenshots must match the name of the test not including
the suffix. In otherwords, if your test is called TestSampleCustomCameraMedium
then your screenshots need to be named customcamera1, customcamera2 etc.
This is so when it comes time to compare screenshots we can figure out which
reference images require a corresponding screenshot. In other words if
TestSampleCustomCameraMedium is run then we know that any reference file
named customcamera1_reference.png requires that there be a corresponding
screenshot.
"""
import selenium_utilities
class JavaScriptUnitTests(selenium_utilities.SeleniumTestCase):
"""Runs the JavaScript unit tests for the sample utilities."""
def __init__(self, name, session, browser, path_to_html, test_type=None,
sample_path=None, options=None):
selenium_utilities.SeleniumTestCase.__init__(
self, name, session, browser, path_to_html, test_type, sample_path,
options)
def GenericTest(self):
"""Generically test a sample.
Each sample is expected to have a global variable called g_testResult
That starts undefined and is set to true or false when the test is finished.
"""
self.RunGenericTest(
"/tests/selenium/tests/",
"typeof(window.g_testResult) != 'undefined'",
"window.g_testResult")
def TestStressDrawShapes(self):
"""Tries to draw a large number of shapes for stress testing."""
# Alias for the selenium session
s = self.session
s.open(self.GetURL("/tests/selenium/tests/drawshapes.html"))
# Allow a limited time for the plugin to initialize.
s.wait_for_condition("typeof(window.g_client) != 'undefined';", 20000)
# Sanity checks.
self.assertEqual("Drawshape stress test for O3D", s.get_title())
self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))
# Check assets for base o3d setup:
# 2 nodes in scene graph
# Root node and g_parent_transform node
self.assertEqual(
"2",
s.get_eval("window.g_client.root.getTransformsInTree().length"))
# There are 8 nodes in the render graph.
# 1 root render node
# 1 viewport
# 1 clear buffer
# 1 tree traversal
# 2 draw passes
# 2 StateSets
self.assertEqual(
"8",
s.get_eval("window.g_client.renderGraphRoot."
"getRenderNodesInTree().length"))
# Draw 5 triangles
s.type("numShapes", "5")
s.click("btnTri")
# 5 more primitives should get created
# (1 for the parent transform)
s.wait_for_condition(
"window.g_client."
"getObjectsByClassName('o3d.Shape').length == 5",
5000)
# 5 more primitives nodes should get created
self.assertEqual(
"5",
s.get_eval("window.g_client."
"getObjectsByClassName('o3d.Primitive').length"))
# Draw more triangles
s.type("numShapes", "8")
for i in range(1, 10):
s.click("btnTri")
s.wait_for_condition(
"window.g_client."
"getObjectsByClassName('o3d.Shape').length == %d" % (5 + i * 8),
5000)
self.assertEqual(
str(5 + i * 8),
s.get_eval("window.g_client."
"getObjectsByClassName('o3d.Primitive').length"))
# Clear triangles, reset pack.
s.click("btnClear")
# Check assets for base o3d setup again.
self.assertEqual(
"2",
s.get_eval("window.g_client.root.getTransformsInTree().length"))
self.assertEqual(
"8",
s.get_eval("window.g_client.renderGraphRoot."
"getRenderNodesInTree().length"))
# Now draw lines
s.type("numShapes", "5")
s.click("btnLines")
# 5 more shapes should get created
# (1 for the parent transform)
s.wait_for_condition(
"window.g_client."
"getObjectsByClassName('o3d.Shape').length == 5",
5000)
# 5 more primitives and drawelements should get created
self.assertEqual(
"5",
s.get_eval("window.g_client."
"getObjectsByClassName('o3d.Primitive').length"))
self.assertEqual(
"5",
s.get_eval("window.g_client."
"getObjectsByClassName('o3d.DrawElement').length"))
# Draw more lines
s.type("numShapes", "11")
for i in range(1, 10):
s.click("btnLines")
s.wait_for_condition(
"window.g_client."
"getObjectsByClassName('o3d.Shape').length == %d" % (5 + i * 11),
5000)
self.assertEqual(
str(5 + i * 11),
s.get_eval("window.g_client."
"getObjectsByClassName('o3d.Primitive').length"))
# Clear triangles, reset pack.
s.click("btnClear")
# Check assets for base o3d setup again.
self.assertEqual(
"2",
s.get_eval("window.g_client.root.getTransformsInTree().length"))
self.assertEqual(
"8",
s.get_eval("window.g_client.renderGraphRoot."
"getRenderNodesInTree().length"))
# Now draw 1000 triangles
s.type("numShapes", "1000")
s.click("btnTri")
# 30 seconds to draw 1000 triangle shapes
s.wait_for_condition(
"window.g_client."
"getObjectsByClassName('o3d.Shape').length == 1000",
30000)
# Assert number of primitives
self.assertEqual(
"1000",
s.get_eval("window.g_client."
"getObjectsByClassName('o3d.Primitive').length"))
# Clear triangles, reset pack.
s.click("btnClear")
def TestStressMultiWindow(self):
"""Opens 5 windows of simpletexture.html."""
# Alias for the selenium session
s = self.session
# Save the titles of windows so we can reset the current window.
# Note: docs of selenium are out of date. We should be able to use ids or
# names in select_window below but all of those methods failed.
old = s.get_all_window_titles()
for i in range(1, 5):
s.open_window(
self.GetURL("/samples/simpletexture.html"),
"o3dstress_window%d" % i)
for i in range(1, 5):
s.select_window("o3dstress_window%d" % i)
# Allow a limited time for the plugin to initialize.
s.wait_for_condition("typeof(window.g_client) != 'undefined';", 30000)
# Sanity checks.
self.assertEqual("Tutorial B3: Textures", s.get_title())
self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))
for i in range(1, 5):
s.select_window("o3dstress_window%d" % i)
s.close()
# make the old window the current window so the next test will run.
s.select_window(old[0])
def TestStressCullingZSort(self):
"""Checks culling and zsorting work."""
# Alias for the selenium session
s = self.session
s.open(self.GetURL("/tests/selenium/tests/culling-zsort-test.html"))
# Allow a limited time for the plugin to initialize.
s.wait_for_condition("typeof(window.g_client) != 'undefined';", 20000)
# Sanity checks.
self.assertEqual("Culling and ZSorting Test.", s.get_title())
self.assertEqual("null", s.get_eval("window.undefined_symbol_xxxyyy"))
s.wait_for_condition("window.g_client != null", 10000)
# Wait for all instances to be created.
s.wait_for_condition(
"window.g_totalDrawElementsElement.innerHTML == '2'",
40000)
# Stop animation
s.run_script("g_timeMult = 0")
s.run_script("g_client.renderMode = g_o3d.Client.RENDERMODE_ON_DEMAND")
s.run_script("var g_rendered = false")
new_data = []
culling_reference_data = [[1793, 4472, 3780, 2, 4844, 213, 4631],
[1793, 6011, 3854, 2, 7734, 337, 7397],
[1793, 3014, 2416, 2, 3400, 121, 3279],
[1793, 2501, 2408, 2, 2420, 162, 2258],
[1793, 2933, 2914, 2, 2746, 182, 2564],
[1793, 2825, 2848, 2, 2604, 171, 2433],
[1793, 2933, 2790, 2, 2870, 155, 2715],
[1793, 4337, 3004, 2, 5360, 237, 5123]]
# Take screenshots
for clock in range(0, 8):
s.run_script("window.g_clock = " + str(clock * 3.14159 * 2.5 + 0.5))
self.assertTrue(
selenium_utilities.TakeScreenShot(s, self.browser, "window.g_client",
"cullingzsort" + str(clock)))
s.run_script("g_framesRendered = 0")
while int(s.get_eval("window.g_framesRendered")) < 3:
s.run_script("window.g_client.render()")
data = [s.get_eval("window.g_totalTransformsElement.innerHTML"),
s.get_eval("window.g_transformsProcessedElement.innerHTML"),
s.get_eval("window.g_transformsCulledElement.innerHTML"),
s.get_eval("window.g_totalDrawElementsElement.innerHTML"),
s.get_eval("window.g_drawElementsProcessedElement.innerHTML"),
s.get_eval("window.g_drawElementsCulledElement.innerHTML"),
s.get_eval("window.g_drawElementsRenderedElement.innerHTML")]
new_data.append(data)
print ", ".join(data)
# check the results
for clock in range(0, 8):
for ii in range(0, 7):
# comment out the following line and add a "pass" line if you need new
# culling reference data.
self.assertEqual(int(new_data[clock][ii]),
culling_reference_data[clock][ii])
if __name__ == "__main__":
pass
|