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

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: Created 5 years, 4 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 CompositedAnimationTest {
4 constructor(disableThreadedAnimation) {
5 this.disableThreadedAnimation = disableThreadedAnimation;
6 this.tests = [];
7 this.next_id = 1;
8
9 if (window.internals) {
10 internals.disableThreadedAnimation(disableThreadedAnimation);
11 }
12
13 this.createStyles();
14 this.createStaticElements();
15 }
16
17 createStyles() {
18 var item = document.createElement('style');
19 item.type = 'text/css';
20 item.innerHTML = '.item {\
21 width: 20px;\
22 height: 20px;\
23 position: relative;\
24 background: black;\
25 }';
26
27 var marker = document.createElement('style');
28 marker.type = 'text/css';
29 marker.innerHTML = '.marker {\
30 width: 5px;\
31 height: 5px;\
32 display: inline-block;\
33 background: orange;\
34 margin: 15px;\
35 }';
36
37 document.head.appendChild(item);
38 document.head.appendChild(marker);
39 }
40
41 createStaticElements() {
42 var error = document.createElement("span");
43 error.id = 'error';
44 error.style.color = 'red';
45 document.body.appendChild(error);
46
47 var wrapper = document.createElement("div");
48 wrapper.id = 'wrapper';
49 document.body.appendChild(wrapper);
50 }
51
52 createTestElements() {
53 this.tests.forEach(function(test) {
54 var testWrapper = document.createElement("div");
55 wrapper.appendChild(testWrapper);
56
57 test.data.stamps.forEach(function(stamp) {
58 var element = document.createElement("div");
59 element.className = "item";
60 element.style.backgroundColor = test.data.color;
61
62 if (!testWrapper.hasChildNodes())
63 element.style.clear = "left";
64
65 if (test.data.vertical == null || !test.data.vertical)
dstockwell 2015/08/06 00:23:19 These seem fairly arbitrary inputs to provide to t
loyso (OOO) 2015/09/14 06:19:07 Yeah. WIP, I'll add it in a special Patch Set.
loyso (OOO) 2015/09/15 07:50:52 Done. Note that I want to keep tests grouped so al
66 element.style.float = "left";
67
68 if (test.data.margin)
69 element.style.margin = test.data.margin + 'px';
70
71 if (test.data.divSize) {
72 element.style.width = test.data.divSize + 'px';
73 element.style.height = test.data.divSize + 'px';
74 }
75
76 if (test.data.marker == null || test.data.marker) {
77 var content = document.createElement("div");
78 content.className = "marker";
79 if (test.data.divSize) {
80 content.style.margin = (test.data.divSize - 5) + 'px';
81 }
82 element.appendChild(content);
83 }
84
85 var id = this.next_id++;
86 element.id = id;
87
88 testWrapper.appendChild(element);
89
90 test.instances.push({
91 element: element,
92 animation: null,
93 id: id
94 });
95 }.bind(this));
96 }.bind(this));
97
98 if (window.internals)
99 internals.forceCompositingUpdate(document);
dstockwell 2015/08/06 00:23:19 // why
loyso (OOO) 2015/09/14 06:19:07 Done.
100 }
101
102 startAnimations() {
103 // Taken from cubic_bezier.cc:
104 var kBezierEpsilon = 1e-7;
105 // Reverse the blink::accuracyForDuration function to calculate duration
106 // from epsilon:
107 var duration = 1000 * 1.0 / (kBezierEpsilon * 200.0);
Ian Vollick 2015/08/05 13:58:46 nit: isn't this just 5.0/kBezierEpsilon?
loyso (OOO) 2015/09/14 06:19:07 This is a reverse for the mentioned function: //
108 // TODO(loyso): Duration mustn't affect cc/blink consistency.
109 // duration = 5000;
Ian Vollick 2015/08/05 13:58:46 What's with this commented-out line? Leftover from
loyso (OOO) 2015/09/14 06:19:07 Yep. If you don't adjust the duration then it beco
110 this.tests.forEach(function(test) {
111 for (var i = 0; i < test.instances.length; i++) {
112 var stamp = test.data.stamps[i];
113 var instance = test.instances[i];
114 instance.animation = instance.element.animate(test.data.keyframes, {
115 duration: duration,
116 iterations: Infinity,
117 delay: -duration * stamp.at,
Ian Vollick 2015/08/05 13:58:46 Ah, so these tests work by getting the animation t
loyso (OOO) 2015/08/06 06:44:18 Yes, exactly. This is special "paused mode" where
118 easing: test.data.easing
119 });
120 }
121 });
122
123 if (window.internals) {
124 internals.pauseAnimations(0);
dstockwell 2015/08/06 00:23:19 Doesn't this get called before we start the compos
loyso (OOO) 2015/08/06 06:44:18 Internals::pauseAnimations calls updateAllLifecycl
125 }
126 }
127
128 assertRunningThread() {
Ian Vollick 2015/08/05 13:58:46 nit: assertAnimationsRunningOnCompositorThread, or
loyso (OOO) 2015/09/14 06:19:07 Done.
129 this.tests.forEach(function(test) {
130 test.instances.forEach(function(instance) {
131 var composited = internals.isCompositedAnimation(instance.animation);
132 if (composited != !this.disableThreadedAnimation)
133 error.textContent += `Animation ${instance.id} ${composited ? 'is' : ' is not'} running on the compositor.`;
134 }.bind(this));
135 }.bind(this));
136 }
137
138 layoutAndPaint() {
139 if (window.testRunner) {
140 testRunner.waitUntilDone();
141 testRunner.layoutAndPaintAsyncThen(function() {
142 if (window.internals) {
143 this.assertRunningThread();
144 }
145 testRunner.notifyDone();
146 }.bind(this));
147 }
148 }
149
150 registerTestData(testData) {
151 this.tests.push({
152 data: testData,
153 instances: []
154 });
155 }
156
157 registerTestsData(testsData) {
158 testsData.forEach(function(test) {
159 this.registerTestData(test);
160 }.bind(this));
161 }
162
163 run() {
164 this.createTestElements();
165 this.startAnimations();
166 this.layoutAndPaint();
167 }
168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698