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

Side by Side Diff: chrome/test/data/webui/settings/animation_browsertest.js

Issue 2072643002: MD Settings: animation interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase why not Created 4 years, 5 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
« no previous file with comments | « chrome/test/data/webui/mocha_adapter.js ('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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /** @fileoverview Tests for settings.animation. */
6
7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */
8 var ROOT_PATH = '../../../../../';
9
10 /**
11 * @constructor
12 * @extends testing.Test
13 */
14 function SettingsAnimationBrowserTest() {}
15
16 SettingsAnimationBrowserTest.prototype = {
17 __proto__: testing.Test.prototype,
18
19 /** @override */
20 browsePreload: 'chrome://md-settings/animation/animation.html',
21
22 /** @override */
23 extraLibraries: [
24 ROOT_PATH + 'third_party/mocha/mocha.js',
25 '../mocha_adapter.js',
26 ],
27
28 /** @override */
29 isAsync: true,
30
31 /** @override */
32 runAccessibilityChecks: false,
33 };
34
35 TEST_F('SettingsAnimationBrowserTest', 'Animation', function() {
36 var self = this;
37
38 var Animation = settings.animation.Animation;
39
40 var onFinishBeforePromise = function() {
41 assertNotReached('Animation fired finish event before resolving promise');
42 };
43
44 var onCancelUnexpectedly = function() {
45 assertNotReached('Animation should have finished, but fired cancel event');
46 };
47
48 // Register mocha tests.
49 suite('settings.animation.Animation', function() {
50 var div;
51 var keyframes;
52 var options;
53
54 setup(function() {
55 keyframes = [{
56 height: '100px',
57 easing: 'ease-in',
58 }, {
59 height: '200px',
60 }];
61
62 options = {
63 duration: 1000,
64 // Use fill: both so we can test the animation start and end states.
65 fill: 'both',
66 };
67
68 div = document.createElement('div');
69 document.body.appendChild(div);
70 });
71
72 teardown(function() {
73 div.remove();
74 });
75
76 test('Animation plays', function(done) {
77 var animation = new Animation(div, keyframes, options);
78 animation.addEventListener('cancel', onCancelUnexpectedly);
79 animation.addEventListener('finish', onFinishBeforePromise);
80
81 requestAnimationFrame(function() {
82 expectEquals(100, div.clientHeight);
83
84 animation.finished.then(function() {
85 expectEquals(200, div.clientHeight);
86 animation.removeEventListener('finish', onFinishBeforePromise);
87 animation.addEventListener('finish', function() {
88 done();
89 });
90 });
91 });
92 });
93
94 test('Animation finishes', function(done) {
95 // Absurdly large finite value to ensure we call finish() before the
96 // animation finishes automatically.
97 options.duration = Number.MAX_VALUE;
98 var animation = new Animation(div, keyframes, options);
99 animation.addEventListener('cancel', onCancelUnexpectedly);
100 animation.addEventListener('finish', onFinishBeforePromise);
101
102 // TODO(michaelpg): rAF seems more appropriate, but crbug.com/620160.
103 setTimeout(function() {
104 expectEquals(100, div.clientHeight);
105
106 animation.finish();
107
108 // The promise should resolve before the finish event is scheduled.
109 animation.finished.then(function() {
110 expectEquals(200, div.clientHeight);
111 animation.removeEventListener('finish', onFinishBeforePromise);
112 animation.addEventListener('finish', function() {
113 done();
114 });
115 });
116 });
117 });
118
119 test('Animation cancels', function(done) {
120 // Absurdly large finite value to ensure we call cancel() before the
121 // animation finishes automatically.
122 options.duration = Number.MAX_VALUE;
123 var animation = new Animation(div, keyframes, options);
124 animation.addEventListener('cancel', onCancelUnexpectedly);
125 animation.addEventListener('finish', onFinishBeforePromise);
126
127 // TODO(michaelpg): rAF seems more appropriate, but crbug.com/620160.
128 setTimeout(function() {
129 expectEquals(100, div.clientHeight);
130
131 animation.cancel();
132
133 // The promise should resolve before the finish event is scheduled.
134 animation.finished.catch(function() {
135 expectEquals(0, div.clientHeight);
136 animation.removeEventListener('cancel', onCancelUnexpectedly);
137 animation.addEventListener('cancel', function() {
138 done();
139 });
140 });
141 });
142 });
143 });
144
145 // Run all registered tests.
146 mocha.run();
147 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/mocha_adapter.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698