| Index: chrome/test/data/webui/settings/transition_browsertest.js
|
| diff --git a/chrome/test/data/webui/settings/transition_browsertest.js b/chrome/test/data/webui/settings/transition_browsertest.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c346a86ba85bee1572dd45f00870b600497f7502
|
| --- /dev/null
|
| +++ b/chrome/test/data/webui/settings/transition_browsertest.js
|
| @@ -0,0 +1,217 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +/** @fileoverview Tests for settings.animation. */
|
| +
|
| +/** @const {string} Path to root from chrome/test/data/webui/settings/. */
|
| +var ROOT_PATH = '../../../../../';
|
| +
|
| +/**
|
| + * @constructor
|
| + * @extends testing.Test
|
| +*/
|
| +function SettingsTransitionBrowserTest() {}
|
| +
|
| +SettingsTransitionBrowserTest.prototype = {
|
| + __proto__: testing.Test.prototype,
|
| +
|
| + /** @override */
|
| + browsePreload: 'chrome://md-settings/animation/transition.html',
|
| +
|
| + /** @override */
|
| + extraLibraries: [
|
| + ROOT_PATH + 'ui/webui/resources/js/cr.js',
|
| + ROOT_PATH + 'ui/webui/resources/js/cr/event_target.js',
|
| + ROOT_PATH + 'chrome/browser/resources/settings/animation/animation.js',
|
| + ROOT_PATH + 'third_party/mocha/mocha.js',
|
| + '../mocha_adapter.js',
|
| + ],
|
| +
|
| + /** @override */
|
| + isAsync: true,
|
| +
|
| + /** @override */
|
| + runAccessibilityChecks: false,
|
| +};
|
| +
|
| +TEST_F('SettingsTransitionBrowserTest', 'Transition', function() {
|
| + var self = this;
|
| +
|
| + var MockTransition = function() {
|
| + this.cleanedUp = false;
|
| + this.resolver = new PromiseResolver();
|
| + this.finished = this.resolver.promise;
|
| +
|
| + this.setUp();
|
| + };
|
| +
|
| + MockTransition.prototype = {
|
| + __proto__: settings.animation.Transition.prototype,
|
| +
|
| + finish: function() {
|
| + this.resolver.resolve();
|
| + },
|
| +
|
| + cancel: function() {
|
| + this.resolver.reject();
|
| + },
|
| +
|
| + cleanUp: function() {
|
| + expectFalse(this.cleanedUp);
|
| + this.cleanedUp = true;
|
| + },
|
| + };
|
| +
|
| + var MockAnimatedTransition = function(el, duration) {
|
| + this.cleanedUp = false;
|
| + this.animation_ = new settings.animation.Animation(
|
| + el,
|
| + [{
|
| + height: '100px',
|
| + }, {
|
| + height: '200px',
|
| + }], {
|
| + duration: duration,
|
| + fill: 'forwards'
|
| + });
|
| + this.finished = this.animation_.finished;
|
| +
|
| + this.setUp();
|
| + };
|
| +
|
| + MockAnimatedTransition.prototype = {
|
| + __proto__: MockTransition.prototype,
|
| +
|
| + finish: function() {
|
| + if (this.done_)
|
| + return;
|
| + this.done_ = true;
|
| + this.animation_.finish();
|
| + },
|
| +
|
| + cancel: function() {
|
| + if (this.done_)
|
| + return;
|
| + this.done_ = true;
|
| + this.animation_.cancel();
|
| + },
|
| + };
|
| +
|
| + suite('settings.animation.Transition', function() {
|
| + var div;
|
| + var transition;
|
| +
|
| + setup(function() {
|
| + div = document.createElement('div');
|
| + document.body.appendChild(div);
|
| + });
|
| +
|
| + teardown(function() {
|
| + div.remove();
|
| + });
|
| +
|
| + suite('transition completes itself', function() {
|
| + setup(function() {
|
| + transition = new MockAnimatedTransition(div, 1000);
|
| + expectEquals(100, div.clientHeight);
|
| + });
|
| +
|
| + test('transition finishes', function() {
|
| + return transition.finished.then(function() {
|
| + expectEquals(200, div.clientHeight);
|
| + expectTrue(transition.cleanedUp);
|
| +
|
| + // These should be no-ops.
|
| + transition.finish();
|
| + transition.cancel();
|
| + });
|
| + });
|
| + });
|
| +
|
| + suite('cancel/finish', function() {
|
| + setup(function() {
|
| + transition = new MockAnimatedTransition(div, Number.MAX_VALUE);
|
| + expectEquals(100, div.clientHeight);
|
| + });
|
| +
|
| + test('finish', function() {
|
| + transition.finish();
|
| +
|
| + return transition.finished.then(function() {
|
| + expectEquals(200, div.clientHeight);
|
| + expectTrue(transition.cleanedUp);
|
| + });
|
| + });
|
| +
|
| + test('cancel', function() {
|
| + transition.cancel();
|
| +
|
| + return transition.finished.then(function() {
|
| + assertNotReached('Transition promise should be rejected');
|
| + }, function() {
|
| + expectEquals(0, div.clientHeight);
|
| + expectTrue(transition.cleanedUp);
|
| + });
|
| + });
|
| +
|
| + test('finish/cancel after finishing is no-op', function() {
|
| + transition.finish();
|
| +
|
| + // Nothing should happen.
|
| + transition.finish();
|
| + transition.cancel();
|
| +
|
| + // Verify the promise is still resolved.
|
| + return transition.finished.then(function() {
|
| + expectEquals(200, div.clientHeight);
|
| + expectTrue(transition.cleanedUp);
|
| + });
|
| + });
|
| +
|
| + test('finish/cancel after canceling is no-op', function() {
|
| + transition.cancel();
|
| +
|
| + // Nothing should happen.
|
| + transition.cancel();
|
| + transition.finish();
|
| +
|
| + // Verify the promise is still rejected.
|
| + return transition.finished.then(function() {
|
| + assertNotReached('Transition promise should be rejected');
|
| + }, function() {
|
| + expectEquals(0, div.clientHeight);
|
| + expectTrue(transition.cleanedUp);
|
| + });
|
| + });
|
| + });
|
| + });
|
| +
|
| + suite('settings.animation.ImmediateTransition', function() {
|
| + test('finishes automatically', function() {
|
| + var transition = new settings.animation.ImmediateTransition();
|
| +
|
| + return transition.finished;
|
| + });
|
| +
|
| + test('cannot be canceled', function() {
|
| + var transition = new settings.animation.ImmediateTransition();
|
| + transition.cancel();
|
| +
|
| + // Still resolves successfully.
|
| + return transition.finished;
|
| + });
|
| +
|
| + test('inherited functions are no-ops', function() {
|
| + var transition = new settings.animation.ImmediateTransition();
|
| + transition.finish();
|
| + transition.cancel();
|
| + transition.cleanUp();
|
| +
|
| + return transition.finished;
|
| + });
|
| + });
|
| +
|
| + // Run all registered tests.
|
| + mocha.run();
|
| +});
|
|
|