1 // Copyright (c) 2013 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.
7 base.require('ui.container_that_decorates_its_children');
9 base.unittest.testSuite('ui.container_that_decorates_its_children', function() { // @suppress longLineCheck
11 function createChild() {
12 var span = document.createElement('span');
13 span.decorated = false;
20 var SimpleContainer = ui.define('simple-container',
21 ui.ContainerThatDecoratesItsChildren);
23 SimpleContainer.prototype = {
24 __proto__: ui.ContainerThatDecoratesItsChildren.prototype,
26 decorateChild_: function(child) {
27 assertFalse(child.decorated);
28 child.decorated = true;
31 undecorateChild_: function(child) {
32 assertTrue(child.decorated);
33 child.decorated = false;
37 test('add', function() {
38 var container = new SimpleContainer();
39 container.appendChild(createChild());
40 container.appendChild(createChild());
41 container.appendChild(createChild());
42 assertTrue(container.children[0].decorated);
43 assertTrue(container.children[1].decorated);
44 assertTrue(container.children[2].decorated);
47 test('clearUsingTextContent', function() {
48 var c0 = createChild();
49 var container = new SimpleContainer();
50 container.appendChild(c0);
51 container.textContent = '';
52 assertFalse(c0.decorated);
55 test('clear', function() {
56 var c0 = createChild();
57 var container = new SimpleContainer();
58 container.appendChild(c0);
60 assertFalse(c0.decorated);
63 test('insertNewBefore', function() {
64 var c0 = createChild();
65 var c1 = createChild();
66 var container = new SimpleContainer();
67 container.appendChild(c1);
68 container.insertBefore(c0, c1);
69 assertTrue(c0.decorated);
70 assertTrue(c1.decorated);
73 test('insertExistingBefore', function() {
74 var c0 = createChild();
75 var c1 = createChild();
76 var container = new SimpleContainer();
77 container.appendChild(c1);
78 container.appendChild(c0);
79 container.insertBefore(c0, c1);
80 assertTrue(c0.decorated);
81 assertTrue(c1.decorated);
84 test('testReplace', function() {
85 var c0 = createChild();
86 var c1 = createChild();
87 var container = new SimpleContainer();
88 container.appendChild(c0);
89 container.replaceChild(c1, c0);
90 assertFalse(c0.decorated);
91 assertTrue(c1.decorated);