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

Side by Side Diff: LayoutTests/animations/resources/composited-animation-test.js

Issue 1270303002: Composited Animations: Introduce pixel-ref layout tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@disable
Patch Set: Use CSS styles instead of custom flags. Created 5 years, 3 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
OLDNEW
(Empty)
1 'use strict';
2
3 class CompositedAnimationTestCommon {
4 constructor(disableThreadedAnimation) {
5 this.disableThreadedAnimation = disableThreadedAnimation;
6 this.tests = [];
7 this.next_sample_id = 1;
8
9 this.createStyles();
10 this.createStaticElements();
11 }
12
13 createStyles() {
14 var item = document.createElement('style');
15 item.type = 'text/css';
16 item.textContent = `.item {
17 width: 20px;
18 height: 20px;
19 position: relative;
20 background: black;
21 float: left;
22 }`;
23
24 var marker = document.createElement('style');
25 marker.type = 'text/css';
26 marker.textContent = `.marker {
27 width: 5px;
28 height: 5px;
29 display: inline-block;
30 background: orange;
31 margin: 15px;
32 }`;
33
34 document.head.appendChild(item);
35 document.head.appendChild(marker);
36 }
37
38 createStaticElements() {
39 var error = document.createElement("span");
40 error.id = 'error';
41 error.style.color = 'red';
42 document.body.appendChild(error);
43
44 var wrapper = document.createElement("div");
45 wrapper.id = 'wrapper';
46 document.body.appendChild(wrapper);
47 }
48
49 createTestElements() {
50 var testId = 1;
51
52 this.tests.forEach(function(test) {
53 var testWrapper = document.createElement("div");
54 wrapper.appendChild(testWrapper);
55
56 // Create custom styles for this test case.
57 if (test.data.style) {
58 var styleForSamples = document.createElement('style');
59 styleForSamples.type = 'text/css';
60 styleForSamples.textContent = '.test' + testId + ' {' + test.data.style + '}';
61 document.head.appendChild(styleForSamples);
62 }
63 if (test.data.markerStyle && test.data.markerStyle != '') {
64 var styleForMarkers = document.createElement('style');
65 styleForMarkers.type = 'text/css';
66 styleForMarkers.textContent = '.testMarker' + testId + ' {' + test.data. markerStyle + '}';
67 document.head.appendChild(styleForMarkers);
68 }
69
70 test.data.samples.forEach(function(sample) {
71 var element = document.createElement("div");
72
73 if (!testWrapper.hasChildNodes())
74 element.style.clear = "left";
75
76 if (test.data.markerStyle == null || test.data.markerStyle != '') {
77 var content = document.createElement("div");
78 content.classList.add('marker', 'testMarker' + testId);
79 element.appendChild(content);
80 }
81
82 element.classList.add('item', 'test' + testId);
83
84 var sample_id = this.next_sample_id++;
85 element.id = sample_id;
86
87 testWrapper.appendChild(element);
88
89 test.instances.push({
90 element: element,
91 animation: null,
92 id: sample_id
93 });
94 }.bind(this));
95
96 testId++;
97 }.bind(this));
98
99 // Update all lifecycle phases to propagate all the objects to
100 // the compositor and to clear all the dirty flags.
101 if (window.internals)
102 internals.forceCompositingUpdate(document);
103 }
104
105 startAnimations() {
106 // We want to achieve desired accuracy for splines using a specific duration .
107 // TODO(loyso): Duration mustn't affect cc/blink consistency.
108 // Taken from cubic_bezier.cc:
109 var kBezierEpsilon = 1e-7;
110 // Reverse the blink::accuracyForDuration function to calculate duration
111 // from epsilon:
112 var duration = 1000 * 1.0 / (kBezierEpsilon * 200.0);
113
114 this.tests.forEach(function(test) {
115 for (var i = 0; i < test.instances.length; i++) {
116 var sample = test.data.samples[i];
117 var instance = test.instances[i];
118
119 // Use negative animation delays to specify sampled time for each animat ion.
120 instance.animation = instance.element.animate(test.data.keyframes, {
121 duration: duration,
122 iterations: Infinity,
123 delay: -duration * sample.at,
124 easing: test.data.easing
125 });
126
127 if (window.internals && this.disableThreadedAnimation) {
128 internals.disableCompositedAnimation(instance.animation);
129 }
130 }
131 }.bind(this));
132
133 if (window.internals) {
134 internals.pauseAnimations(0);
135 }
136 }
137
138 assertAnimationsRunningOnCompositorThread() {
139 this.tests.forEach(function(test) {
140 test.instances.forEach(function(instance) {
141 var composited = internals.isCompositedAnimation(instance.animation);
142 if (composited != !this.disableThreadedAnimation)
143 error.textContent += `Animation ${instance.id} ${composited ? 'is' : ' is not'} running on the compositor.`;
144 }.bind(this));
145 }.bind(this));
146 }
147
148 layoutAndPaint() {
149 if (window.testRunner) {
150 testRunner.waitUntilDone();
151 testRunner.layoutAndPaintAsyncThen(function() {
152 if (window.internals) {
153 this.assertAnimationsRunningOnCompositorThread();
154 }
155 testRunner.notifyDone();
156 }.bind(this));
157 }
158 }
159
160 registerTestData(testData) {
161 this.tests.push({
162 data: testData,
163 instances: []
164 });
165 }
166
167 registerTestsData(testsData) {
168 testsData.forEach(function(test) {
169 this.registerTestData(test);
170 }.bind(this));
171 }
172
173 run() {
174 this.createTestElements();
175 this.startAnimations();
176 this.layoutAndPaint();
177 }
178 }
179
180
181 class CompositedAnimationTest extends CompositedAnimationTestCommon {
182 constructor() {
183 var disableThreadedAnimation = false;
184 super(disableThreadedAnimation)
185 }
186 }
187
188
189 class CompositedAnimationTestExpected extends CompositedAnimationTestCommon {
190 constructor() {
191 var disableThreadedAnimation = true;
192 super(disableThreadedAnimation)
193 }
194 }
195
196
197 var getLinearSamples = function(n, start, end) {
198 var arr = [];
199 var spread = end - start;
200 for (var i=0; i<=n; i++) {
201 arr.push(i * spread / n + start);
202 }
203 return arr.map(function(t) { return { at: t }});
204 }
OLDNEW
« no previous file with comments | « LayoutTests/VirtualTestSuites ('k') | LayoutTests/animations/resources/composited-animations-data/rotate-zero-degrees.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698