OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 suite('cr-lazy-render', function() { |
| 6 |
| 7 suiteSetup(function() { |
| 8 return PolymerTest.importHtml( |
| 9 'chrome://resources/polymer/v1_0/paper-checkbox/paper-checkbox.html'); |
| 10 }); |
| 11 |
| 12 setup(function() { |
| 13 PolymerTest.clearBody(); |
| 14 var template = |
| 15 '<template is="dom-bind" id="bind">' + |
| 16 ' <template is="cr-lazy-render" id="lazy">' + |
| 17 ' <h1>' + |
| 18 ' <paper-checkbox checked="{{checked}}"></paper-checkbox>' + |
| 19 ' {{name}}' + |
| 20 ' </h1>' + |
| 21 ' </template>' + |
| 22 '</template>'; |
| 23 document.body.innerHTML = template; |
| 24 }); |
| 25 |
| 26 test('stamps after get()', function() { |
| 27 var lazy = document.getElementById('lazy'); |
| 28 |
| 29 assertFalse(!!document.body.querySelector('h1')); |
| 30 assertFalse(!!lazy.getIfExists()); |
| 31 |
| 32 return lazy.get().then(function(inner) { |
| 33 assertEquals('H1', inner.nodeName); |
| 34 assertEquals(inner, document.body.querySelector('h1')); |
| 35 }); |
| 36 }); |
| 37 |
| 38 test('one-way binding works', function() { |
| 39 var bind = document.getElementById('bind'); |
| 40 bind.name = 'Wings'; |
| 41 var lazy = document.getElementById('lazy'); |
| 42 |
| 43 return lazy.get().then(function(inner) { |
| 44 assertNotEquals(-1, inner.textContent.indexOf('Wings')); |
| 45 bind.name = 'DC'; |
| 46 assertNotEquals(-1, inner.textContent.indexOf('DC')); |
| 47 }); |
| 48 }); |
| 49 |
| 50 test('two-way binding works', function() { |
| 51 var bind = document.getElementById('bind'); |
| 52 bind.checked = true; |
| 53 |
| 54 var lazy = document.getElementById('lazy'); |
| 55 |
| 56 return lazy.get().then(function(inner) { |
| 57 var checkbox = document.querySelector('paper-checkbox'); |
| 58 assertTrue(checkbox.checked); |
| 59 MockInteractions.tap(checkbox); |
| 60 assertFalse(checkbox.checked); |
| 61 assertFalse(bind.checked); |
| 62 }); |
| 63 }); |
| 64 }); |
OLD | NEW |