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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/webui/mocha_adapter.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/settings/animation_browsertest.js
diff --git a/chrome/test/data/webui/settings/animation_browsertest.js b/chrome/test/data/webui/settings/animation_browsertest.js
new file mode 100644
index 0000000000000000000000000000000000000000..5ee559a6e9d5e763f7b8f352e8a491f9b9bc0afa
--- /dev/null
+++ b/chrome/test/data/webui/settings/animation_browsertest.js
@@ -0,0 +1,147 @@
+// 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 SettingsAnimationBrowserTest() {}
+
+SettingsAnimationBrowserTest.prototype = {
+ __proto__: testing.Test.prototype,
+
+ /** @override */
+ browsePreload: 'chrome://md-settings/animation/animation.html',
+
+ /** @override */
+ extraLibraries: [
+ ROOT_PATH + 'third_party/mocha/mocha.js',
+ '../mocha_adapter.js',
+ ],
+
+ /** @override */
+ isAsync: true,
+
+ /** @override */
+ runAccessibilityChecks: false,
+};
+
+TEST_F('SettingsAnimationBrowserTest', 'Animation', function() {
+ var self = this;
+
+ var Animation = settings.animation.Animation;
+
+ var onFinishBeforePromise = function() {
+ assertNotReached('Animation fired finish event before resolving promise');
+ };
+
+ var onCancelUnexpectedly = function() {
+ assertNotReached('Animation should have finished, but fired cancel event');
+ };
+
+ // Register mocha tests.
+ suite('settings.animation.Animation', function() {
+ var div;
+ var keyframes;
+ var options;
+
+ setup(function() {
+ keyframes = [{
+ height: '100px',
+ easing: 'ease-in',
+ }, {
+ height: '200px',
+ }];
+
+ options = {
+ duration: 1000,
+ // Use fill: both so we can test the animation start and end states.
+ fill: 'both',
+ };
+
+ div = document.createElement('div');
+ document.body.appendChild(div);
+ });
+
+ teardown(function() {
+ div.remove();
+ });
+
+ test('Animation plays', function(done) {
+ var animation = new Animation(div, keyframes, options);
+ animation.addEventListener('cancel', onCancelUnexpectedly);
+ animation.addEventListener('finish', onFinishBeforePromise);
+
+ requestAnimationFrame(function() {
+ expectEquals(100, div.clientHeight);
+
+ animation.finished.then(function() {
+ expectEquals(200, div.clientHeight);
+ animation.removeEventListener('finish', onFinishBeforePromise);
+ animation.addEventListener('finish', function() {
+ done();
+ });
+ });
+ });
+ });
+
+ test('Animation finishes', function(done) {
+ // Absurdly large finite value to ensure we call finish() before the
+ // animation finishes automatically.
+ options.duration = Number.MAX_VALUE;
+ var animation = new Animation(div, keyframes, options);
+ animation.addEventListener('cancel', onCancelUnexpectedly);
+ animation.addEventListener('finish', onFinishBeforePromise);
+
+ // TODO(michaelpg): rAF seems more appropriate, but crbug.com/620160.
+ setTimeout(function() {
+ expectEquals(100, div.clientHeight);
+
+ animation.finish();
+
+ // The promise should resolve before the finish event is scheduled.
+ animation.finished.then(function() {
+ expectEquals(200, div.clientHeight);
+ animation.removeEventListener('finish', onFinishBeforePromise);
+ animation.addEventListener('finish', function() {
+ done();
+ });
+ });
+ });
+ });
+
+ test('Animation cancels', function(done) {
+ // Absurdly large finite value to ensure we call cancel() before the
+ // animation finishes automatically.
+ options.duration = Number.MAX_VALUE;
+ var animation = new Animation(div, keyframes, options);
+ animation.addEventListener('cancel', onCancelUnexpectedly);
+ animation.addEventListener('finish', onFinishBeforePromise);
+
+ // TODO(michaelpg): rAF seems more appropriate, but crbug.com/620160.
+ setTimeout(function() {
+ expectEquals(100, div.clientHeight);
+
+ animation.cancel();
+
+ // The promise should resolve before the finish event is scheduled.
+ animation.finished.catch(function() {
+ expectEquals(0, div.clientHeight);
+ animation.removeEventListener('cancel', onCancelUnexpectedly);
+ animation.addEventListener('cancel', function() {
+ done();
+ });
+ });
+ });
+ });
+ });
+
+ // Run all registered tests.
+ mocha.run();
+});
« 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