Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / src / ui / container_that_decorates_its_children_test.js
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.
4
5 'use strict';
6
7 base.require('ui.container_that_decorates_its_children');
8
9 base.unittest.testSuite('ui.container_that_decorates_its_children', function() { // @suppress longLineCheck
10
11   function createChild() {
12     var span = document.createElement('span');
13     span.decorated = false;
14     return span;
15   }
16
17   /**
18    * @constructor
19    */
20   var SimpleContainer = ui.define('simple-container',
21                                   ui.ContainerThatDecoratesItsChildren);
22
23   SimpleContainer.prototype = {
24     __proto__: ui.ContainerThatDecoratesItsChildren.prototype,
25
26     decorateChild_: function(child) {
27       assertFalse(child.decorated);
28       child.decorated = true;
29     },
30
31     undecorateChild_: function(child) {
32       assertTrue(child.decorated);
33       child.decorated = false;
34     }
35   };
36
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);
45   });
46
47   test('clearUsingTextContent', function() {
48     var c0 = createChild();
49     var container = new SimpleContainer();
50     container.appendChild(c0);
51     container.textContent = '';
52     assertFalse(c0.decorated);
53   });
54
55   test('clear', function() {
56     var c0 = createChild();
57     var container = new SimpleContainer();
58     container.appendChild(c0);
59     container.clear();
60     assertFalse(c0.decorated);
61   });
62
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);
71   });
72
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);
82   });
83
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);
92   });
93
94 });