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.
7 <link rel="import" href="/tvcm/utils.html">
8 <polymer-element name="instantiate-template-polymer-element-test">
18 <template id="instantiate-template-polymer-test">
19 <instantiate-template-polymer-element-test>
20 </instantiate-template-polymer-element-test>
23 <template id="multiple-template-test">
25 <instantiate-template-polymer-element-test>
26 </instantiate-template-polymer-element-test>
27 <span test-attribute='TestAttribute'>Foo</span>
29 <instantiate-template-polymer-element-test>
30 </instantiate-template-polymer-element-test>
35 tvcm.unittest.testSuite(function() {
36 var THIS_DOC = document._currentScript.ownerDocument;
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));
46 test('getUsingPath', function() {
47 var z = tvcm.getUsingPath('x.y.z', {'x': {'y': {'z': 3}}});
50 var w = tvcm.getUsingPath('x.w', {'x': {'y': {'z': 3}}});
51 assertEquals(undefined, w);
54 test('instantiateTemplatePolymer', function() {
55 var e = tvcm.instantiateTemplate(
56 '#instantiate-template-polymer-test',
58 assertEquals(e.children.length, 1);
59 assertEquals(e.children[0].testProperty, 'Test');
62 test('instantiateTemplateMultipleTemplates', function() {
63 var outerElement = tvcm.instantiateTemplate(
64 '#multiple-template-test',
66 assertEquals(2, outerElement.children.length);
67 assertEquals('Test', outerElement.children[1].testProperty);
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);
75 innerElement.children[1].getAttribute('test-attribute'));
76 assertEquals('Foo', innerElement.children[1].textContent);