Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: pkg/polymer/lib/elements/web-animations-js/test/test-generator.html

Issue 175443005: [polymer] import all elements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updated from bower Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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>
43 "use strict";
44
45 function detectFeatures() {
46 var style = document.createElement('style');
47 style.textContent = '' +
48 'dummyRuleForTesting {' +
49 'width: calc(0px);' +
50 'width: -webkit-calc(0px); }';
51 document.head.appendChild(style);
52 var transformCandidates = [
53 'transform',
54 'webkitTransform',
55 'msTransform'
56 ];
57 var transformProperty = transformCandidates.filter(function(property) {
58 return property in style.sheet.cssRules[0].style;
59 })[0];
60 var calcFunction = style.sheet.cssRules[0].style.width.split('(')[0];
61 document.head.removeChild(style);
62 return {
63 transformProperty: transformProperty,
64 calcFunction: calcFunction
65 };
66 }
67
68 var features = detectFeatures();
69
70 var testCurrentTime;
71 var testLength = 0;
72 var lastRun = false;
73 var frameTime = 100;
74 var checks = [];
75 var interval;
76
77 document.getElementById("iframeSrc").value = window.location.search.substring(1) || "testcases/auto-test-calc.html";
78 document.getElementById("interval").value = "1";
79 document.getElementById("obProp").value = ".anim, width";
80
81
82 function ToCheck(object, initSelctor, properties){
83 this.object = object;
84 this.initSelctor = initSelctor;
85 this.properties = properties;
86 }
87
88 function getEndTime(timeline) {
89 var players = timeline.getCurrentPlayers();
90
91 var endTime = 0;
92 players.forEach(function(player) {
93 endTime = Math.max(endTime, player.source.endTime);
94 });
95 return endTime;
96 }
97
98 function loadFile(mode, callback) {
99 if (typeof mode == 'undefined') {
100 mode = '';
101 }
102
103 var file = document.getElementById("iframeSrc").value;
104
105 var iframe = document.getElementById("frame");
106 // We want the frame to always reload even if the src is the same, hence we
107 // force it to null and then to the value we want.
108 iframe.onload = function() {
109 iframe.onload = callback;
110 iframe.src = file + '#' + mode;
111 };
112 iframe.src = '';
113 }
114
115 function startGeneratingExpectations() {
116 var obProp = document.getElementById("obProp").value;
117
118 var output = document.getElementById("checks");
119 output.innerHTML = "";
120
121 loadFile("message", function () {
122 findElementsToCheck(obProp);
123
124 output.innerHTML += "timing_test(function() {\n";
125 var testWindow = document.getElementById("frame").contentWindow;
126 var interval = parseFloat(document.getElementById("interval").value);
127
128 var endTime = Infinity;
129
130 var t = 0;
131 while(t <= endTime) {
132 if (typeof testWindow.testharness_timeline == 'undefined') {
133 alert("Your page doesn't contain testharness_timline, can not generate anything!");
134 return;
135 }
136
137 testWindow.testharness_timeline.setTime(t * 1000.0);
138
139 // Update the endTime as it can change dependent on the running animations
140 // and modifications to them.
141 endTime = getEndTime(testWindow.window.document.timeline);
142
143 generate(t);
144 t += interval;
145 }
146
147 output.innerHTML += '}, "Auto generated tests");\n';
148 });
149 }
150
151 function findElementsToCheck(rawString){
152 // Put all checks into checkStack
153 checks = [];
154 rawString = rawString.split("\n");
155
156 for (var x in rawString){
157 rawString[x] = rawString[x].replace(/\s/g, "");
158 rawString[x] = rawString[x].split(",");
159 if (rawString[x][0].length == 0)
160 continue;
161 var object = window.frames[0].document.querySelectorAll(rawString[x][0]);
162 var prop = [];
163 for (var i = 1; i < rawString[x].length; i++){
164 prop.push(rawString[x][i]);
165 }
166 checks.push(new ToCheck(object, rawString[x][0], prop));
167 }
168 }
169
170 var svgProperties = {
171 'cx': 1,
172 'width': 1,
173 'x': 1,
174 'y': 1,
175 };
176
177 var propertyIsSVGAttrib = function(property, target) {
178 return target.namespaceURI == 'http://www.w3.org/2000/svg' &&
179 property in svgProperties;
180 };
181
182 function generate(time){
183 console.log("Generating checks for t=", time);
184
185 // Produce checks at this time
186 var outputText = " at(" + time + ", function() {\n";
187 for (var x in checks){
188 var propslist = [];
189 for (var i = 0; i < checks[x].object.length; i++){
190 var propsPrint = "{";
191 for (var j in checks[x].properties){
192 var p = checks[x].properties[j];
193 var isSVG = propertyIsSVGAttrib(p, checks[x].object[i]);
194
195 if(isSVG) var props = checks[x].object[i].attributes;
196 else var props = checks[x].object[i].currentStyle ||
197 getComputedStyle(checks[x].object[i], null);
198
199 if (p == 'ctm') {
200 var ctm = checks[x].object[i].getCTM();
201 var value = '{' + ctm.a + ', ' + ctm.b + ', ' + ctm.c + ', ' + ctm.d + ', ' + ctm.e + ', ' + ctm.f + '}'
202 } else if (p == 'transform') {
203 var value = props[features.transformProperty];
204 } else {
205 var value = isSVG ? props[p].value : props[p];
206 }
207 console.log("Node:", checks[x].object[i].cloneNode(), "Property:", check s[x].properties[j], "Value:", value);
208
209 value = value.replace(/[-+]?[0-9]+\.?[0-9]*(?:[eE][-+]?[0-9]+)?/g, funct ion(v) {
210 v = Number(v);
211 if (Math.abs(v) < 1e-10) {
212 v = 0;
213 }
214 return ("" + v.toPrecision(4)).replace(/\.?0+$/, '');
215 });
216
217 propsPrint += "'"+ p + "':'" + value + "'";
218 if (j < checks[x].properties.length -1) propsPrint += ",";
219 }
220 propsPrint += "}";
221 propslist.push(propsPrint);
222 }
223 outputText += printCheck(checks[x].initSelctor, i, propslist, time);
224 }
225 outputText += ' });';
226 var output = document.getElementById("checks");
227 output.innerHTML += outputText + "<br>";
228 }
229
230 function printCheck(object, number, properties, time){
231
232 var newCheck = ' assert_styles("' + object + '",';
233
234 // If all the properties are the same for every object, just pass the list.
235 var allsame = properties.every(function(x) { return x === properties[0] });
236 if (allsame) {
237 newCheck += properties[0] + ");\n";
238
239 } else {
240 // Otherwise give a list with each
241
242 newCheck += " [\n";
243 for (var j in properties) {
244 newCheck += ' ' + properties[j] + ",\n";
245 }
246 newCheck += " ]);\n";
247 }
248
249 return newCheck;
250 }
251 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698