OLD | NEW |
(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 expectFalse(true, 'Animation fired finish event before resolving promise'); |
| 42 }; |
| 43 |
| 44 var onCancelUnexpectedly = function() { |
| 45 expectFalse(true, 'Animation should have finished, but fired cancel event'); |
| 46 }; |
| 47 |
| 48 // Register mocha tests. |
| 49 suite('settings.animation.Animation', function() { |
| 50 |
| 51 var div; |
| 52 var keyframes; |
| 53 var options; |
| 54 |
| 55 setup(function() { |
| 56 keyframes = [{ |
| 57 height: '100px', |
| 58 easing: 'ease-in', |
| 59 }, { |
| 60 height: '200px', |
| 61 }]; |
| 62 |
| 63 options = { |
| 64 duration: 1000, |
| 65 // Use fill: both so we can test the animation start and end states. |
| 66 fill: 'both', |
| 67 }; |
| 68 |
| 69 div = document.createElement('div'); |
| 70 document.body.appendChild(div); |
| 71 }); |
| 72 |
| 73 teardown(function() { |
| 74 div.remove(); |
| 75 }); |
| 76 |
| 77 test('Animation plays', function(done) { |
| 78 var animation = new Animation(div, keyframes, options); |
| 79 animation.addEventListener('cancel', onCancelUnexpectedly); |
| 80 animation.addEventListener('finish', onFinishBeforePromise); |
| 81 |
| 82 requestAnimationFrame(function() { |
| 83 expectEquals(100, div.clientHeight); |
| 84 |
| 85 animation.finished.then(function() { |
| 86 expectEquals(200, div.clientHeight); |
| 87 animation.removeEventListener('finish', onFinishBeforePromise); |
| 88 animation.addEventListener('finish', function() { |
| 89 done(); |
| 90 }); |
| 91 }); |
| 92 }); |
| 93 }); |
| 94 |
| 95 test('Animation finishes', function(done) { |
| 96 // Absurdly large finite value to ensure we call finish() before the |
| 97 // animation finishes automatically. |
| 98 options.duration = Number.MAX_VALUE; |
| 99 var animation = new Animation(div, keyframes, options); |
| 100 animation.addEventListener('cancel', onCancelUnexpectedly); |
| 101 animation.addEventListener('finish', onFinishBeforePromise); |
| 102 |
| 103 // TODO(michaelpg): rAF seems more appropriate, but crbug.com/620160. |
| 104 setTimeout(function() { |
| 105 expectEquals(100, div.clientHeight); |
| 106 |
| 107 animation.finish(); |
| 108 |
| 109 // The promise should resolve before the finish event is scheduled. |
| 110 animation.finished.then(function() { |
| 111 expectEquals(200, div.clientHeight); |
| 112 animation.removeEventListener('finish', onFinishBeforePromise); |
| 113 animation.addEventListener('finish', function() { |
| 114 done(); |
| 115 }); |
| 116 }); |
| 117 }); |
| 118 }); |
| 119 |
| 120 test('Animation cancels', function(done) { |
| 121 // Absurdly large finite value to ensure we call cancel() before the |
| 122 // animation finishes automatically. |
| 123 options.duration = Number.MAX_VALUE; |
| 124 var animation = new Animation(div, keyframes, options); |
| 125 animation.addEventListener('cancel', onCancelUnexpectedly); |
| 126 animation.addEventListener('finish', onFinishBeforePromise); |
| 127 |
| 128 // TODO(michaelpg): rAF seems more appropriate, but crbug.com/620160. |
| 129 setTimeout(function() { |
| 130 expectEquals(100, div.clientHeight); |
| 131 |
| 132 animation.cancel(); |
| 133 |
| 134 // The promise should resolve before the finish event is scheduled. |
| 135 animation.finished.catch(function() { |
| 136 expectEquals(0, div.clientHeight); |
| 137 animation.removeEventListener('cancel', onCancelUnexpectedly); |
| 138 animation.addEventListener('cancel', function() { |
| 139 done(); |
| 140 }); |
| 141 }); |
| 142 }); |
| 143 }); |
| 144 }); |
| 145 |
| 146 // Run all registered tests. |
| 147 mocha.run(); |
| 148 }); |
OLD | NEW |