OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright 2013 Google Inc. All Rights Reserved. |
| 3 |
| 4 Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 you may not use this file except in compliance with the License. |
| 6 You may obtain a copy of the License at |
| 7 |
| 8 http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
| 10 Unless required by applicable law or agreed to in writing, software |
| 11 distributed under the License is distributed on an "AS IS" BASIS, |
| 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 See the License for the specific language governing permissions and |
| 14 limitations under the License. |
| 15 --> |
| 16 |
| 17 <!DOCTYPE html><meta charset="UTF-8"> |
| 18 <div id="anim"></div> |
| 19 |
| 20 <script src="../bootstrap.js"></script> |
| 21 <script> |
| 22 "use strict"; |
| 23 |
| 24 var elem = document.getElementById("anim"); |
| 25 var animFunc = {left: "100px"}; |
| 26 |
| 27 // Test that Animation is constructed with no parent. |
| 28 var child = new Animation(elem, animFunc, 1); |
| 29 test(function() {assert_equals(child.parent, null)}, |
| 30 "Child should have no parent"); |
| 31 |
| 32 // Test that group is constructed with zero children. |
| 33 var parent = new ParGroup(); |
| 34 test(function() {assert_equals(parent.children.length, 0)}, |
| 35 "Parent should have zero children"); |
| 36 |
| 37 // Test that updates are made to child when constructing parent. |
| 38 var parent = new ParGroup([child]); |
| 39 test(function() {assert_equals(child.parent, parent)}, |
| 40 "Parent's constructor, Child's parent should be set to parent"); |
| 41 test(function() {assert_equals(parent.children.length, 1)}, |
| 42 "Parent's constructor, Parent should have 1 child"); |
| 43 test(function() {assert_equals(parent.children[0], child)}, |
| 44 "Parent's constructor, Parent should have correct child"); |
| 45 |
| 46 // Test that updates are made to previous and new parent when using append(). |
| 47 var newParent = new ParGroup(); |
| 48 newParent.append(child); |
| 49 test(function() {assert_equals(child.parent, newParent)}, |
| 50 "With .append, child's parent should be updated to new parent"); |
| 51 test(function() {assert_equals(parent.children.length, 0)}, |
| 52 "With .append, Previous parent should no longer have children"); |
| 53 test(function() {assert_equals(newParent.children.length, 1)}, |
| 54 "With .append, New parent should now have 1 child"); |
| 55 test(function() {assert_equals(newParent.children[0], child)}, |
| 56 "With .append, New parent should now have correct child"); |
| 57 |
| 58 // Test that calling append() with an existing child causes that child to be mov
ed |
| 59 // to the end of the list of children. |
| 60 var sibling = new Animation(elem, animFunc, 1.0); |
| 61 var seqGroup = new SeqGroup([child, sibling]); |
| 62 test(function() {assert_equals(seqGroup.children.length, 2)}, |
| 63 "Moved child, new seqGroup.children.length"); |
| 64 test(function() {assert_equals(seqGroup.children[0], child)}, |
| 65 "Moved child, new seqGroup's first child should be 'child'"); |
| 66 test(function() {assert_equals(seqGroup.children[1], sibling)}, |
| 67 "Moved child, Second child should be 'sibling'"); |
| 68 test(function() {assert_equals(child.startTime, 0.0)}, |
| 69 "Moved child, start time of 'child' == 0.0"); |
| 70 test(function() {assert_equals(sibling.startTime, 1.0)}, |
| 71 "Moved child, start time of 'sibling' == 1.0"); |
| 72 seqGroup.append(seqGroup.children[0]); |
| 73 test(function() {assert_equals(seqGroup.children.length, 2)}, |
| 74 "After .append, seqGroup.children.length"); |
| 75 test(function() {assert_equals(seqGroup.children[0], sibling)}, |
| 76 "After .append, First child should be 'sibling'"); |
| 77 test(function() {assert_equals(seqGroup.children[1], child)}, |
| 78 "After .append, Second child should be 'child'"); |
| 79 test(function() {assert_equals(sibling.startTime, 0.0)}, |
| 80 "After .append, Start time of 'sibling'"); |
| 81 test(function() {assert_equals(child.startTime, 1.0)}, |
| 82 "After.append, Start time of 'child'"); |
| 83 |
| 84 // Test that setting TimedItem.parent is ignored. |
| 85 test(function() { |
| 86 assert_throws(new TypeError(), function() { |
| 87 child.parent = null; |
| 88 }); |
| 89 assert_equals(child.parent, seqGroup); |
| 90 }, "TimedItem.parent should be read-only"); |
| 91 test(function() {assert_equals(seqGroup.children.length, 2)}, |
| 92 "seqGroup.children.length"); |
| 93 test(function() {assert_equals(seqGroup.children[0], sibling)}, |
| 94 "First child should be 'sibling'"); |
| 95 test(function() {assert_equals(seqGroup.children[1], child)}, |
| 96 "Second child should be 'child'"); |
| 97 test(function() {assert_equals(sibling.startTime, 0.0)}, |
| 98 "Start time of 'sibling'"); |
| 99 test(function() {assert_equals(child.startTime, 1.0)}, |
| 100 "Start time of 'child'"); |
| 101 |
| 102 // Test that TimedItem.clear() updates both parent and children. |
| 103 seqGroup.clear(); |
| 104 test(function() {assert_equals(seqGroup.children.length, 0)}, |
| 105 "Parent's children should be cleared"); |
| 106 test(function() {assert_equals(child.parent, null)}, |
| 107 "Child's parent should be cleared"); |
| 108 test(function() {assert_equals(sibling.parent, null)}, |
| 109 "Sibling's parent should be cleared"); |
| 110 |
| 111 </script> |
OLD | NEW |