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 SettingsTransitionBrowserTest() {} |
| 15 |
| 16 SettingsTransitionBrowserTest.prototype = { |
| 17 __proto__: testing.Test.prototype, |
| 18 |
| 19 /** @override */ |
| 20 browsePreload: 'chrome://md-settings/animation/transition.html', |
| 21 |
| 22 /** @override */ |
| 23 extraLibraries: [ |
| 24 ROOT_PATH + 'ui/webui/resources/js/cr.js', |
| 25 ROOT_PATH + 'ui/webui/resources/js/cr/event_target.js', |
| 26 ROOT_PATH + 'chrome/browser/resources/settings/animation/animation.js', |
| 27 ROOT_PATH + 'third_party/mocha/mocha.js', |
| 28 '../mocha_adapter.js', |
| 29 ], |
| 30 |
| 31 /** @override */ |
| 32 isAsync: true, |
| 33 |
| 34 /** @override */ |
| 35 runAccessibilityChecks: false, |
| 36 }; |
| 37 |
| 38 TEST_F('SettingsTransitionBrowserTest', 'Transition', function() { |
| 39 var self = this; |
| 40 |
| 41 var MockTransition = function() { |
| 42 this.cleanedUp = false; |
| 43 this.resolver = new PromiseResolver(); |
| 44 this.finished = this.resolver.promise; |
| 45 |
| 46 this.setUp(); |
| 47 }; |
| 48 |
| 49 MockTransition.prototype = { |
| 50 __proto__: settings.animation.Transition.prototype, |
| 51 |
| 52 finish: function() { |
| 53 this.resolver.resolve(); |
| 54 }, |
| 55 |
| 56 cancel: function() { |
| 57 this.resolver.reject(); |
| 58 }, |
| 59 |
| 60 cleanUp: function() { |
| 61 expectFalse(this.cleanedUp); |
| 62 this.cleanedUp = true; |
| 63 }, |
| 64 }; |
| 65 |
| 66 var MockAnimatedTransition = function(el, duration) { |
| 67 this.cleanedUp = false; |
| 68 this.animation_ = new settings.animation.Animation( |
| 69 el, |
| 70 [{ |
| 71 height: '100px', |
| 72 }, { |
| 73 height: '200px', |
| 74 }], { |
| 75 duration: duration, |
| 76 fill: 'forwards' |
| 77 }); |
| 78 this.finished = this.animation_.finished; |
| 79 |
| 80 this.setUp(); |
| 81 }; |
| 82 |
| 83 MockAnimatedTransition.prototype = { |
| 84 __proto__: MockTransition.prototype, |
| 85 |
| 86 finish: function() { |
| 87 if (this.done_) |
| 88 return; |
| 89 this.done_ = true; |
| 90 this.animation_.finish(); |
| 91 }, |
| 92 |
| 93 cancel: function() { |
| 94 if (this.done_) |
| 95 return; |
| 96 this.done_ = true; |
| 97 this.animation_.cancel(); |
| 98 }, |
| 99 }; |
| 100 |
| 101 suite('settings.animation.Transition', function() { |
| 102 var div; |
| 103 var transition; |
| 104 |
| 105 setup(function() { |
| 106 div = document.createElement('div'); |
| 107 document.body.appendChild(div); |
| 108 }); |
| 109 |
| 110 teardown(function() { |
| 111 div.remove(); |
| 112 }); |
| 113 |
| 114 suite('transition completes itself', function() { |
| 115 setup(function() { |
| 116 transition = new MockAnimatedTransition(div, 1000); |
| 117 expectEquals(100, div.clientHeight); |
| 118 }); |
| 119 |
| 120 test('transition finishes', function() { |
| 121 return transition.finished.then(function() { |
| 122 expectEquals(200, div.clientHeight); |
| 123 expectTrue(transition.cleanedUp); |
| 124 |
| 125 // These should be no-ops. |
| 126 transition.finish(); |
| 127 transition.cancel(); |
| 128 }); |
| 129 }); |
| 130 }); |
| 131 |
| 132 suite('cancel/finish', function() { |
| 133 setup(function() { |
| 134 transition = new MockAnimatedTransition(div, Number.MAX_VALUE); |
| 135 expectEquals(100, div.clientHeight); |
| 136 }); |
| 137 |
| 138 test('finish', function() { |
| 139 transition.finish(); |
| 140 |
| 141 return transition.finished.then(function() { |
| 142 expectEquals(200, div.clientHeight); |
| 143 expectTrue(transition.cleanedUp); |
| 144 }); |
| 145 }); |
| 146 |
| 147 test('cancel', function() { |
| 148 transition.cancel(); |
| 149 |
| 150 return transition.finished.then(function() { |
| 151 assertNotReached('Transition promise should be rejected'); |
| 152 }, function() { |
| 153 expectEquals(0, div.clientHeight); |
| 154 expectTrue(transition.cleanedUp); |
| 155 }); |
| 156 }); |
| 157 |
| 158 test('finish/cancel after finishing is no-op', function() { |
| 159 transition.finish(); |
| 160 |
| 161 // Nothing should happen. |
| 162 transition.finish(); |
| 163 transition.cancel(); |
| 164 |
| 165 // Verify the promise is still resolved. |
| 166 return transition.finished.then(function() { |
| 167 expectEquals(200, div.clientHeight); |
| 168 expectTrue(transition.cleanedUp); |
| 169 }); |
| 170 }); |
| 171 |
| 172 test('finish/cancel after canceling is no-op', function() { |
| 173 transition.cancel(); |
| 174 |
| 175 // Nothing should happen. |
| 176 transition.cancel(); |
| 177 transition.finish(); |
| 178 |
| 179 // Verify the promise is still rejected. |
| 180 return transition.finished.then(function() { |
| 181 assertNotReached('Transition promise should be rejected'); |
| 182 }, function() { |
| 183 expectEquals(0, div.clientHeight); |
| 184 expectTrue(transition.cleanedUp); |
| 185 }); |
| 186 }); |
| 187 }); |
| 188 }); |
| 189 |
| 190 suite('settings.animation.ImmediateTransition', function() { |
| 191 test('finishes automatically', function() { |
| 192 var transition = new settings.animation.ImmediateTransition(); |
| 193 |
| 194 return transition.finished; |
| 195 }); |
| 196 |
| 197 test('cannot be canceled', function() { |
| 198 var transition = new settings.animation.ImmediateTransition(); |
| 199 transition.cancel(); |
| 200 |
| 201 // Still resolves successfully. |
| 202 return transition.finished; |
| 203 }); |
| 204 |
| 205 test('inherited functions are no-ops', function() { |
| 206 var transition = new settings.animation.ImmediateTransition(); |
| 207 transition.finish(); |
| 208 transition.cancel(); |
| 209 transition.cleanUp(); |
| 210 |
| 211 return transition.finished; |
| 212 }); |
| 213 }); |
| 214 |
| 215 // Run all registered tests. |
| 216 mocha.run(); |
| 217 }); |
OLD | NEW |