Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / src / tvcm / utils_test.html
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="/tvcm/utils.html">
8 <polymer-element name="instantiate-template-polymer-element-test">
9   <template></template>
10   <script>
11   'use strict';
12   Polymer({
13     testProperty: 'Test'
14   });
15   </script>
16 </polymer-element>
17
18 <template id="instantiate-template-polymer-test">
19   <instantiate-template-polymer-element-test>
20   </instantiate-template-polymer-element-test>
21 </template>
22
23 <template id="multiple-template-test">
24   <template>
25     <instantiate-template-polymer-element-test>
26     </instantiate-template-polymer-element-test>
27     <span test-attribute='TestAttribute'>Foo</span>
28   </template>
29   <instantiate-template-polymer-element-test>
30   </instantiate-template-polymer-element-test>
31 </template>
32 <script>
33 'use strict';
34
35 tvcm.unittest.testSuite(function() {
36   var THIS_DOC = document._currentScript.ownerDocument;
37
38   test('clamping', function() {
39     assertEquals(2, tvcm.clamp(2, 1, 3));
40     assertEquals(1, tvcm.clamp(1, 1, 3));
41     assertEquals(1, tvcm.clamp(0, 1, 3));
42     assertEquals(3, tvcm.clamp(3, 1, 3));
43     assertEquals(3, tvcm.clamp(4, 1, 3));
44   });
45
46   test('getUsingPath', function() {
47     var z = tvcm.getUsingPath('x.y.z', {'x': {'y': {'z': 3}}});
48     assertEquals(3, z);
49
50     var w = tvcm.getUsingPath('x.w', {'x': {'y': {'z': 3}}});
51     assertEquals(undefined, w);
52   });
53
54   test('instantiateTemplatePolymer', function() {
55     var e = tvcm.instantiateTemplate(
56                 '#instantiate-template-polymer-test',
57                 THIS_DOC);
58     assertEquals(e.children.length, 1);
59     assertEquals(e.children[0].testProperty, 'Test');
60   });
61
62   test('instantiateTemplateMultipleTemplates', function() {
63     var outerElement = tvcm.instantiateTemplate(
64                            '#multiple-template-test',
65                            THIS_DOC);
66     assertEquals(2, outerElement.children.length);
67     assertEquals('Test', outerElement.children[1].testProperty);
68
69     // Make sure we can still instantiate inner templates, if we need them.
70     var innerElement = outerElement.children[0].createInstance();
71     assertEquals(2, innerElement.children.length);
72     assertEquals('Test', innerElement.children[0].testProperty);
73     assertEquals(
74         'TestAttribute',
75         innerElement.children[1].getAttribute('test-attribute'));
76     assertEquals('Foo', innerElement.children[1].textContent);
77   });
78 });
79 </script>