1 <!DOCTYPE html> 2 <!-- 3 Copyright (c) 2014 The Chromium Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style license that can be 5 found in the LICENSE file. 6 --> 7 <link rel="import" href="/ui/base/container_that_decorates_its_children.html"> 8 <script> 9 'use strict'; 10 11 tr.b.unittest.testSuite(function() { // @suppress longLineCheck 12 13 function createChild() { 14 var span = document.createElement('span'); 15 span.decorated = false; 16 return span; 17 } 18 19 /** 20 * @constructor 21 */ 22 var SimpleContainer = tr.ui.b.define( 23 'simple-container', tr.ui.b.ContainerThatDecoratesItsChildren); 24 25 SimpleContainer.prototype = { 26 __proto__: tr.ui.b.ContainerThatDecoratesItsChildren.prototype, 27 28 decorateChild_: function(child) { 29 assert.isFalse(child.decorated); 30 child.decorated = true; 31 }, 32 33 undecorateChild_: function(child) { 34 assert.isTrue(child.decorated); 35 child.decorated = false; 36 } 37 }; 38 39 test('add', function() { 40 var container = new SimpleContainer(); 41 container.appendChild(createChild()); 42 container.appendChild(createChild()); 43 container.appendChild(createChild()); 44 assert.isTrue(container.children[0].decorated); 45 assert.isTrue(container.children[1].decorated); 46 assert.isTrue(container.children[2].decorated); 47 }); 48 49 test('clearUsingTextContent', function() { 50 var c0 = createChild(); 51 var container = new SimpleContainer(); 52 container.appendChild(c0); 53 container.textContent = ''; 54 assert.isFalse(c0.decorated); 55 }); 56 57 test('clear', function() { 58 var c0 = createChild(); 59 var container = new SimpleContainer(); 60 container.appendChild(c0); 61 container.clear(); 62 assert.isFalse(c0.decorated); 63 }); 64 65 test('insertNewBefore', function() { 66 var c0 = createChild(); 67 var c1 = createChild(); 68 var container = new SimpleContainer(); 69 container.appendChild(c1); 70 container.insertBefore(c0, c1); 71 assert.isTrue(c0.decorated); 72 assert.isTrue(c1.decorated); 73 }); 74 75 test('insertExistingBefore', function() { 76 var c0 = createChild(); 77 var c1 = createChild(); 78 var container = new SimpleContainer(); 79 container.appendChild(c1); 80 container.appendChild(c0); 81 container.insertBefore(c0, c1); 82 assert.isTrue(c0.decorated); 83 assert.isTrue(c1.decorated); 84 }); 85 86 test('testReplace', function() { 87 var c0 = createChild(); 88 var c1 = createChild(); 89 var container = new SimpleContainer(); 90 container.appendChild(c0); 91 container.replaceChild(c1, c0); 92 assert.isFalse(c0.decorated); 93 assert.isTrue(c1.decorated); 94 }); 95 96 }); 97 </script> 98