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

Unified Diff: pkg/polymer/lib/elements/web-animations-js/test/testcases/test-addeventlistener.html

Issue 175443005: [polymer] import all elements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updated from bower Created 6 years, 10 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
Index: pkg/polymer/lib/elements/web-animations-js/test/testcases/test-addeventlistener.html
diff --git a/pkg/polymer/lib/elements/web-animations-js/test/testcases/test-addeventlistener.html b/pkg/polymer/lib/elements/web-animations-js/test/testcases/test-addeventlistener.html
new file mode 100644
index 0000000000000000000000000000000000000000..c428be23ec5050ce0b424c222511a4828f082040
--- /dev/null
+++ b/pkg/polymer/lib/elements/web-animations-js/test/testcases/test-addeventlistener.html
@@ -0,0 +1,176 @@
+<!--
+Copyright 2013 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<!DOCTYPE html><meta charset="UTF-8">
+<style>
+.target {
+ position: absolute;
+ left: 0px;
+ top: 0px;
+ width: 100px;
+ height: 100px;
+ background-color: green;
+}
+</style>
+<script src="../bootstrap.js"></script>
+<script>
+'use strict';
+
+var effect = { left: '100px' };
+
+var timingInput = {
+ iterations: 2,
+ duration: 0.25,
+};
+
+function createAnimation() {
+ var target = document.createElement('div');
+ target.className = 'target';
+ document.body.appendChild(target);
+ return new Animation(target, effect, timingInput);
+}
+
+
+['start', 'iteration', 'end'].forEach(function (eventType) {
+ var animation;
+
+ animation = createAnimation();
+ var singleEventHandler = false;
+ animation.addEventListener(eventType, function() { singleEventHandler = true; })
+ var testA = async_test('Check ' + eventType + ' event with single handler');
+ animation.addEventListener(eventType, function() {
+ testA.step(function() { assert_true(singleEventHandler); });
+ testA.done();
+ });
+ document.timeline.play(animation);
+
+
+ var animation = createAnimation();
+ var eventHandlingCount = 0;
+ var addMultipleTimes = function() { eventHandlingCount++; };
+ animation.addEventListener(eventType, addMultipleTimes);
+ animation.addEventListener(eventType, addMultipleTimes);
+ var testB = async_test('Check ' + eventType + ' event with single handler added multiple times');
+ animation.addEventListener(eventType, function() {
+ testB.step(function() { assert_equals(eventHandlingCount, 1); });
+ testB.done();
+ });
+ document.timeline.play(animation);
+
+
+ animation = createAnimation();
+ var multiEventHandlerA = false;
+ var multiEventHandlerB = false;
+ var multiEventHandlerC = false;
+ animation.addEventListener(eventType, function() { multiEventHandlerA = true; })
+ animation.addEventListener(eventType, function() { multiEventHandlerB = true; })
+ animation.addEventListener(eventType, function() { multiEventHandlerC = true; })
+ var testC = async_test('Check ' + eventType + ' event with multiple handlers');
+ animation.addEventListener(eventType, function() {
+ testC.step(function() { assert_true(multiEventHandlerA && multiEventHandlerB && multiEventHandlerC); });
+ testC.done();
+ });
+ document.timeline.play(animation);
+
+
+ animation = createAnimation();
+ var retainEventHandler = false;
+ animation.addEventListener(eventType, function() { retainEventHandler = true; });
+ var removeEventHandler = true;
+ var eventHandlerToRemove = function() { removeEventHandler = false; }
+ animation.addEventListener(eventType, eventHandlerToRemove);
+ animation.removeEventListener(eventType, eventHandlerToRemove);
+ var testD = async_test('Check ' + eventType + ' event with event handler removed');
+ animation.addEventListener(eventType, function() {
+ testD.step(function() { assert_true(retainEventHandler && removeEventHandler); });
+ testD.done();
+ });
+ document.timeline.play(animation);
+
+
+ animation = createAnimation();
+ var onEventHandler = false;
+ animation['on' + eventType] = function() { onEventHandler = true; };
+ var testE = async_test('Check on' + eventType + ' handler');
+ animation.addEventListener(eventType, function() {
+ testE.step(function() { assert_true(onEventHandler); });
+ testE.done();
+ });
+ document.timeline.play(animation);
+
+
+ animation = createAnimation();
+ var clearOnEventHandler = true;
+ animation['on' + eventType] = function() { clearOnEventHandler = false; };
+ animation['on' + eventType] = null;
+ var testF = async_test('Check clearing on' + eventType + ' handler');
+ animation.addEventListener(eventType, function() {
+ testF.step(function() { assert_true(clearOnEventHandler); });
+ testF.done();
+ });
+ document.timeline.play(animation);
+
+
+ animation = createAnimation();
+ var onEventOrdering = '';
+ animation.addEventListener(eventType, function() { onEventOrdering += 'a'; });
+ animation['on' + eventType] = function() { onEventOrdering += '!'; };
+ animation.addEventListener(eventType, function() { onEventOrdering += 'b'; });
+ animation['on' + eventType] = function() { onEventOrdering += 'c'; };
+ animation.addEventListener(eventType, function() { onEventOrdering += 'd'; });
+ var testG = async_test('Check on' + eventType + ' handler ordering and overriding');
+ animation.addEventListener(eventType, function() {
+ testG.step(function() { assert_equals(onEventOrdering, 'abcd'); });
+ testG.done();
+ });
+ document.timeline.play(animation);
+
+
+ animation = createAnimation();
+ var onEventOrderingAfterRemoval = '';
+ var eventHandlerToRemoveA = function() { onEventOrderingAfterRemoval += '!'; };
+ var eventHandlerToRemoveB = function() { onEventOrderingAfterRemoval += '!!'; };
+ animation.addEventListener(eventType, function() { onEventOrderingAfterRemoval += 'a'; });
+ animation.addEventListener(eventType, eventHandlerToRemoveA);
+ animation['on' + eventType] = function() { onEventOrderingAfterRemoval += 'b'; };
+ animation.addEventListener(eventType, function() { onEventOrderingAfterRemoval += 'c'; });
+ animation.addEventListener(eventType, eventHandlerToRemoveB);
+ animation.removeEventListener(eventType, eventHandlerToRemoveA);
+ animation.removeEventListener(eventType, eventHandlerToRemoveB);
+ var testH = async_test('Check on' + eventType + ' handler ordering after removal');
+ animation.addEventListener(eventType, function() {
+ testH.step(function() { assert_equals(onEventOrderingAfterRemoval, 'abc'); });
+ testH.done();
+ });
+ document.timeline.play(animation);
+
+
+ animation = createAnimation();
+ var onEventDuplication = 0;
+ var duplicateFunction = function() { onEventDuplication += 1; };
+ animation.addEventListener(eventType, duplicateFunction);
+ animation['on' + eventType] = duplicateFunction;
+ var testI = async_test('Check on' + eventType + ' handler duplication');
+ animation.addEventListener(eventType, function() {
+ testI.step(function() { assert_equals(onEventDuplication, 2); });
+ testI.done();
+ });
+ document.timeline.play(animation);
+});
+
+timing_test(function(){at(1, function(){});}, 'Force testharness to execute to 1 second.');
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698