Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/test/data/webui/cr_elements/cr_lazy_render_tests.js

Issue 2341923005: MD WebUI: Make cr-lazy-render get() synchronous (Closed)
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 suite('cr-lazy-render', function() { 5 suite('cr-lazy-render', function() {
6 var lazy;
7 var bind;
6 8
7 suiteSetup(function() { 9 suiteSetup(function() {
8 return PolymerTest.importHtml( 10 return PolymerTest.importHtml(
9 'chrome://resources/polymer/v1_0/paper-checkbox/paper-checkbox.html'); 11 'chrome://resources/polymer/v1_0/paper-checkbox/paper-checkbox.html');
10 }); 12 });
11 13
12 setup(function() { 14 setup(function() {
13 PolymerTest.clearBody(); 15 PolymerTest.clearBody();
14 var template = 16 var template =
15 '<template is="dom-bind" id="bind">' + 17 '<template is="dom-bind" id="bind">' +
16 ' <template is="cr-lazy-render" id="lazy">' + 18 ' <template is="cr-lazy-render" id="lazy">' +
17 ' <h1>' + 19 ' <h1>' +
18 ' <paper-checkbox checked="{{checked}}"></paper-checkbox>' + 20 ' <paper-checkbox checked="{{checked}}"></paper-checkbox>' +
19 ' {{name}}' + 21 ' {{name}}' +
20 ' </h1>' + 22 ' </h1>' +
21 ' </template>' + 23 ' </template>' +
22 '</template>'; 24 '</template>';
23 document.body.innerHTML = template; 25 document.body.innerHTML = template;
26 lazy = document.getElementById('lazy');
27 bind = document.getElementById('bind');
24 }); 28 });
25 29
26 test('stamps after get()', function() { 30 test('stamps after get()', function() {
27 var lazy = document.getElementById('lazy');
28
29 assertFalse(!!document.body.querySelector('h1')); 31 assertFalse(!!document.body.querySelector('h1'));
30 assertFalse(!!lazy.getIfExists()); 32 assertFalse(!!lazy.getIfExists());
31 33
32 return lazy.get().then(function(inner) { 34 var inner = lazy.get();
33 assertEquals('H1', inner.nodeName); 35 assertEquals('H1', inner.nodeName);
34 assertEquals(inner, document.body.querySelector('h1')); 36 assertEquals(inner, document.body.querySelector('h1'));
35 });
36 }); 37 });
37 38
38 test('one-way binding works', function() { 39 test('one-way binding works', function() {
39 var bind = document.getElementById('bind');
40 bind.name = 'Wings'; 40 bind.name = 'Wings';
41 var lazy = document.getElementById('lazy');
42 41
43 return lazy.get().then(function(inner) { 42 var inner = lazy.get();
44 assertNotEquals(-1, inner.textContent.indexOf('Wings')); 43 assertNotEquals(-1, inner.textContent.indexOf('Wings'));
45 bind.name = 'DC'; 44 bind.name = 'DC';
46 assertNotEquals(-1, inner.textContent.indexOf('DC')); 45 assertNotEquals(-1, inner.textContent.indexOf('DC'));
47 });
48 }); 46 });
49 47
50 test('two-way binding works', function() { 48 test('two-way binding works', function() {
51 var bind = document.getElementById('bind');
52 bind.checked = true; 49 bind.checked = true;
53 50
54 var lazy = document.getElementById('lazy'); 51 var inner = lazy.get();
55 52 var checkbox = document.querySelector('paper-checkbox');
56 return lazy.get().then(function(inner) { 53 assertTrue(checkbox.checked);
57 var checkbox = document.querySelector('paper-checkbox'); 54 MockInteractions.tap(checkbox);
58 assertTrue(checkbox.checked); 55 assertFalse(checkbox.checked);
59 MockInteractions.tap(checkbox); 56 assertFalse(bind.checked);
60 assertFalse(checkbox.checked);
61 assertFalse(bind.checked);
62 });
63 }); 57 });
64 }); 58 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698