OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright 2012 Google Inc. All Rights Reserved. | |
3 | |
4 Licensed under the Apache License, Version 2.0 (the "License"); | |
5 you may not use this file except in compliance with the License. | |
6 You may obtain a copy of the License at | |
7 | |
8 http://www.apache.org/licenses/LICENSE-2.0 | |
9 | |
10 Unless required by applicable law or agreed to in writing, software | |
11 distributed under the License is distributed on an "AS IS" BASIS, | |
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 See the License for the specific language governing permissions and | |
14 limitations under the License. | |
15 --> | |
16 <style> | |
17 iframe { | |
18 width: 100%; | |
19 height: 600px; | |
20 } | |
21 .textBox { | |
22 width:800px; | |
23 height:200px; | |
24 } | |
25 input#iframeSrc { | |
26 width: 200px; | |
27 } | |
28 </style> | |
29 | |
30 <input type="text" id="iframeSrc"> | |
31 <button id="load-button" onclick="loadFile()">Load</button><br> | |
32 <iframe id="frame" src=""></iframe> | |
33 <div id="userOptions"> | |
34 <input type="number" id="interval" value=1> Interval <br> | |
35 Objects and properties | |
36 <button id="generate-button" onclick="startGeneratingExpectations()">Generate<
/button><br> | |
37 <textarea id = "obProp" class = textBox></textarea> <br> | |
38 </div> | |
39 <div> Outputted Checks </div> | |
40 <pre id = "checks"></pre> | |
41 | |
42 <script src="../web-animations.js"></script> | |
43 <script> | |
44 "use strict"; | |
45 | |
46 function detectFeatures() { | |
47 var style = document.createElement('style'); | |
48 style.textContent = '' + | |
49 'dummyRuleForTesting {' + | |
50 'width: calc(0px);' + | |
51 'width: -webkit-calc(0px); }'; | |
52 document.head.appendChild(style); | |
53 var transformCandidates = [ | |
54 'transform', | |
55 'webkitTransform', | |
56 'msTransform' | |
57 ]; | |
58 var transformProperty = transformCandidates.filter(function(property) { | |
59 return property in style.sheet.cssRules[0].style; | |
60 })[0]; | |
61 var calcFunction = style.sheet.cssRules[0].style.width.split('(')[0]; | |
62 document.head.removeChild(style); | |
63 return { | |
64 transformProperty: transformProperty, | |
65 calcFunction: calcFunction | |
66 }; | |
67 } | |
68 | |
69 var features = detectFeatures(); | |
70 | |
71 var testCurrentTime; | |
72 var testLength = 0; | |
73 var lastRun = false; | |
74 var frameTime = 100; | |
75 var checks = []; | |
76 var interval; | |
77 | |
78 document.getElementById("iframeSrc").value = window.location.search.substring(1)
|| "testcases/auto-test-calc.html"; | |
79 document.getElementById("interval").value = "1"; | |
80 document.getElementById("obProp").value = ".anim, width"; | |
81 | |
82 | |
83 function ToCheck(object, initSelctor, properties){ | |
84 this.object = object; | |
85 this.initSelctor = initSelctor; | |
86 this.properties = properties; | |
87 } | |
88 | |
89 function getEndTime(timeline) { | |
90 var players = timeline.getCurrentPlayers(); | |
91 | |
92 var endTime = 0; | |
93 players.forEach(function(player) { | |
94 endTime = Math.max(endTime, player.source.endTime); | |
95 }); | |
96 return endTime; | |
97 } | |
98 | |
99 function loadFile(mode, callback) { | |
100 if (typeof mode == 'undefined') { | |
101 mode = ''; | |
102 } | |
103 | |
104 var file = document.getElementById("iframeSrc").value; | |
105 | |
106 var iframe = document.getElementById("frame"); | |
107 // We want the frame to always reload even if the src is the same, hence we | |
108 // force it to null and then to the value we want. | |
109 iframe.onload = function() { | |
110 iframe.onload = callback; | |
111 iframe.src = file + '#' + mode; | |
112 }; | |
113 iframe.src = ''; | |
114 } | |
115 | |
116 function startGeneratingExpectations() { | |
117 var obProp = document.getElementById("obProp").value; | |
118 | |
119 var output = document.getElementById("checks"); | |
120 output.innerHTML = ""; | |
121 | |
122 loadFile("message", function () { | |
123 findElementsToCheck(obProp); | |
124 | |
125 output.innerHTML += "timing_test(function() {\n"; | |
126 var testWindow = document.getElementById("frame").contentWindow; | |
127 var interval = parseFloat(document.getElementById("interval").value); | |
128 | |
129 var endTime = Infinity; | |
130 | |
131 var t = 0; | |
132 while(t <= endTime) { | |
133 if (typeof testWindow.testharness_timeline == 'undefined') { | |
134 alert("Your page doesn't contain testharness_timline, can not generate
anything!"); | |
135 return; | |
136 } | |
137 | |
138 testWindow.testharness_timeline.setTime(t); | |
139 | |
140 // Update the endTime as it can change dependent on the running animations | |
141 // and modifications to them. | |
142 endTime = getEndTime(testWindow.window.document.timeline); | |
143 | |
144 generate(t); | |
145 t += interval; | |
146 } | |
147 | |
148 output.innerHTML += '}, "Auto generated tests");\n'; | |
149 }); | |
150 } | |
151 | |
152 function findElementsToCheck(rawString){ | |
153 // Put all checks into checkStack | |
154 checks = []; | |
155 rawString = rawString.split("\n"); | |
156 | |
157 for (var x in rawString){ | |
158 rawString[x] = rawString[x].replace(/\s/g, ""); | |
159 rawString[x] = rawString[x].split(","); | |
160 if (rawString[x][0].length == 0) | |
161 continue; | |
162 var object = window.frames[0].document.querySelectorAll(rawString[x][0]); | |
163 var prop = []; | |
164 for (var i = 1; i < rawString[x].length; i++){ | |
165 prop.push(rawString[x][i]); | |
166 } | |
167 checks.push(new ToCheck(object, rawString[x][0], prop)); | |
168 } | |
169 } | |
170 | |
171 function generate(time){ | |
172 console.log("Generating checks for t=", time); | |
173 | |
174 // Produce checks at this time | |
175 var outputText = " at(" + time + ", function() {\n"; | |
176 for (var x in checks){ | |
177 var propslist = []; | |
178 for (var i = 0; i < checks[x].object.length; i++){ | |
179 var propsPrint = "{"; | |
180 for (var j in checks[x].properties){ | |
181 var p = checks[x].properties[j]; | |
182 var isSVG = _WebAnimationsTestingUtilities._propertyIsSVGAttrib(p, check
s[x].object[i]); | |
183 | |
184 if(isSVG) var props = checks[x].object[i].attributes; | |
185 else var props = checks[x].object[i].currentStyle || | |
186 getComputedStyle(checks[x].object[i], null); | |
187 | |
188 if (p == 'ctm') { | |
189 var ctm = checks[x].object[i].getCTM(); | |
190 var value = '{' + ctm.a + ', ' + ctm.b + ', ' + ctm.c + ', ' + ctm.d +
', ' + ctm.e + ', ' + ctm.f + '}' | |
191 } else if (p == 'transform') { | |
192 var value = props[features.transformProperty]; | |
193 } else { | |
194 var value = isSVG ? props[p].value : props[p]; | |
195 } | |
196 console.log("Node:", checks[x].object[i].cloneNode(), "Property:", check
s[x].properties[j], "Value:", value); | |
197 | |
198 value = value.replace(/[-+]?[0-9]+\.?[0-9]*(?:[eE][-+]?[0-9]+)?/g, funct
ion(v) { | |
199 v = Number(v); | |
200 if (Math.abs(v) < 1e-10) { | |
201 v = 0; | |
202 } | |
203 return ("" + v.toPrecision(4)).replace(/\.?0+$/, ''); | |
204 }); | |
205 | |
206 propsPrint += "'"+ p + "':'" + value + "'"; | |
207 if (j < checks[x].properties.length -1) propsPrint += ","; | |
208 } | |
209 propsPrint += "}"; | |
210 propslist.push(propsPrint); | |
211 } | |
212 outputText += printCheck(checks[x].initSelctor, i, propslist, time); | |
213 } | |
214 outputText += ' });'; | |
215 var output = document.getElementById("checks"); | |
216 output.innerHTML += outputText + "<br>"; | |
217 } | |
218 | |
219 function printCheck(object, number, properties, time){ | |
220 | |
221 var newCheck = ' assert_styles("' + object + '",'; | |
222 | |
223 // If all the properties are the same for every object, just pass the list. | |
224 var allsame = properties.every(function(x) { return x === properties[0] }); | |
225 if (allsame) { | |
226 newCheck += properties[0] + ");\n"; | |
227 | |
228 } else { | |
229 // Otherwise give a list with each | |
230 | |
231 newCheck += " [\n"; | |
232 for (var j in properties) { | |
233 newCheck += ' ' + properties[j] + ",\n"; | |
234 } | |
235 newCheck += " ]);\n"; | |
236 } | |
237 | |
238 return newCheck; | |
239 } | |
240 </script> | |
OLD | NEW |