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

Side by Side Diff: third_party/WebKit/LayoutTests/animations/responsive/resources/responsive-test.js

Issue 1444233002: Change responsive-test.js neutral keyframe format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_responsiveHarnessWebAnimations
Patch Set: ebased Created 5 years, 1 month 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
« no previous file with comments | « third_party/WebKit/LayoutTests/animations/responsive/line-height-responsive.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /* 5 /*
6 Exported function: 6 Exported function:
7 assertResponsive 7 assertResponsive
8 8
9 Call signature: 9 Call signature:
10 assertResponsive({ 10 assertResponsive({
11 property: <CSS Property>, 11 property: <CSS Property>,
12 from: ?<CSS Value>, 12 ?from: <CSS Value>,
13 to: ?<CSS Value>, 13 ?to: <CSS Value>,
14 configurations: [{ 14 configurations: [{
15 state: { 15 state: {
16 ?underlying: <CSS Value>, 16 ?underlying: <CSS Value>,
17 ?inherited: <CSS Value>, 17 ?inherited: <CSS Value>,
18 }, 18 },
19 expect: [ 19 expect: [
20 { at: <Float>, is: <CSS Value> } 20 { at: <Float>, is: <CSS Value> }
21 ], 21 ],
22 }], 22 }],
23 }) 23 })
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 console.assert(targets.every(function(target) { return target.parentElement === parent; })); 83 console.assert(targets.every(function(target) { return target.parentElement === parent; }));
84 parent.style[property] = state.inherited; 84 parent.style[property] = state.inherited;
85 } 85 }
86 if (state.underlying) { 86 if (state.underlying) {
87 for (var target of targets) { 87 for (var target of targets) {
88 target.style[property] = state.underlying; 88 target.style[property] = state.underlying;
89 } 89 }
90 } 90 }
91 } 91 }
92 92
93 function createKeyframes(property, from, to) { 93 function keyframeText(options, keyframeName) {
94 return [ 94 return (keyframeName in options) ? `[${options[keyframeName]}]` : 'neutral';
95 {[property]: from}, 95 }
96 {[property]: to}, 96
97 ]; 97 function createKeyframes(options) {
98 var keyframes = [];
99 if ('from' in options) {
100 keyframes.push({
101 offset: 0,
102 [options.property]: options.from,
103 });
104 }
105 if ('to' in options) {
106 keyframes.push({
107 offset: 1,
108 [options.property]: options.to,
109 });
110 }
111 return keyframes;
98 } 112 }
99 113
100 function startPausedAnimations(targets, keyframes, fractions) { 114 function startPausedAnimations(targets, keyframes, fractions) {
101 console.assert(targets.length == fractions.length); 115 console.assert(targets.length == fractions.length);
102 for (var i = 0; i < targets.length; i++) { 116 for (var i = 0; i < targets.length; i++) {
103 var target = targets[i]; 117 var target = targets[i];
104 var fraction = fractions[i]; 118 var fraction = fractions[i];
105 console.assert(fraction >= 0 && fraction < 1); 119 console.assert(fraction >= 0 && fraction < 1);
106 var animation = target.animate(keyframes, 1); 120 var animation = target.animate(keyframes, 1);
107 animation.currentTime = fraction; 121 animation.currentTime = fraction;
108 animation.pause(); 122 animation.pause();
109 } 123 }
110 } 124 }
111 125
112 function runPendingResponsiveTests() { 126 function runPendingResponsiveTests() {
113 var stateTransitionTests = []; 127 var stateTransitionTests = [];
114 pendingResponsiveTests.forEach(function(options) { 128 pendingResponsiveTests.forEach(function(options) {
115 var property = options.property; 129 var property = options.property;
116 var from = options.from; 130 var from = options.from;
117 var to = options.to; 131 var to = options.to;
118 var keyframes = createKeyframes(property, from, to); 132 var keyframes = createKeyframes(options);
133 var fromText = keyframeText(options, 'from');
134 var toText = keyframeText(options, 'to');
119 135
120 var stateTransitions = createStateTransitions(options.configurations); 136 var stateTransitions = createStateTransitions(options.configurations);
121 stateTransitions.forEach(function(stateTransition) { 137 stateTransitions.forEach(function(stateTransition) {
122 var before = stateTransition.before; 138 var before = stateTransition.before;
123 var after = stateTransition.after; 139 var after = stateTransition.after;
124 var container = createElement('div', document.body); 140 var container = createElement('div', document.body);
125 var targets = createTargets(after.expect.length, container); 141 var targets = createTargets(after.expect.length, container);
126 142
127 setState(targets, property, before.state); 143 setState(targets, property, before.state);
128 startPausedAnimations(targets, keyframes, after.expect.map(function(expect ation) { return expectation.at; })); 144 startPausedAnimations(targets, keyframes, after.expect.map(function(expect ation) { return expectation.at; }));
129 stateTransitionTests.push({ 145 stateTransitionTests.push({
130 applyStateTransition() { 146 applyStateTransition() {
131 setState(targets, property, after.state); 147 setState(targets, property, after.state);
132 }, 148 },
133 assert() { 149 assert() {
134 for (var i = 0; i < targets.length; i++) { 150 for (var i = 0; i < targets.length; i++) {
135 var target = targets[i]; 151 var target = targets[i];
136 var expectation = after.expect[i]; 152 var expectation = after.expect[i];
137 var actual = getComputedStyle(target)[property]; 153 var actual = getComputedStyle(target)[property];
138 test(function() { 154 test(function() {
139 assert_equals(actual, expectation.is); 155 assert_equals(actual, expectation.is);
140 }, `Animation on property <${property}> from [${from}] to [${to}] wi th ${JSON.stringify(before.state)} changed to ${JSON.stringify(after.state)} at (${expectation.at}) is [${expectation.is}]`); 156 }, `Animation on property <${property}> from ${fromText} to ${toText } with ${JSON.stringify(before.state)} changed to ${JSON.stringify(after.state)} at (${expectation.at}) is [${expectation.is}]`);
141 } 157 }
142 }, 158 },
143 }); 159 });
144 }); 160 });
145 }); 161 });
146 162
147 // Separate style modification from measurement as different phases to avoid a style recalc storm. 163 // Separate style modification from measurement as different phases to avoid a style recalc storm.
148 for (var stateTransitionTest of stateTransitionTests) { 164 for (var stateTransitionTest of stateTransitionTests) {
149 stateTransitionTest.applyStateTransition(); 165 stateTransitionTest.applyStateTransition();
150 } 166 }
(...skipping 18 matching lines...) Expand all
169 requestAnimationFrame(function() { 185 requestAnimationFrame(function() {
170 runPendingResponsiveTests(); 186 runPendingResponsiveTests();
171 asyncHandle.done() 187 asyncHandle.done()
172 }); 188 });
173 }); 189 });
174 190
175 191
176 window.assertResponsive = assertResponsive; 192 window.assertResponsive = assertResponsive;
177 193
178 })(); 194 })();
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/animations/responsive/line-height-responsive.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698