Chromium Code Reviews| OLD | NEW |
|---|---|
| 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-dialog', function() { | 5 suite('cr-dialog', function() { |
| 6 setup(function() { | 6 setup(function() { |
| 7 PolymerTest.clearBody(); | 7 PolymerTest.clearBody(); |
| 8 }); | 8 }); |
| 9 | 9 |
| 10 test('focuses title on show', function() { | 10 test('focuses title on show', function() { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 document.body.innerHTML = ` | 113 document.body.innerHTML = ` |
| 114 <dialog is="cr-dialog" show-scroll-borders> | 114 <dialog is="cr-dialog" show-scroll-borders> |
| 115 <div class="title">title</div> | 115 <div class="title">title</div> |
| 116 <div class="body">body</div> | 116 <div class="body">body</div> |
| 117 </dialog>`; | 117 </dialog>`; |
| 118 | 118 |
| 119 var dialog = document.body.querySelector('dialog'); | 119 var dialog = document.body.querySelector('dialog'); |
| 120 var bodyContainer = dialog.$$('.body-container'); | 120 var bodyContainer = dialog.$$('.body-container'); |
| 121 assertTrue(!!bodyContainer); | 121 assertTrue(!!bodyContainer); |
| 122 | 122 |
| 123 dialog.showModal(); // Attach the dialog for the first time here. | |
| 124 | |
| 123 var observerCount = 0; | 125 var observerCount = 0; |
| 124 | 126 |
| 125 // Needs to setup the observer before attaching, since InteractionObserver | 127 // Needs to setup the observer before attaching, since InteractionObserver |
| 126 // calls callback before MutationObserver does. | 128 // calls callback before MutationObserver does. |
| 127 var observer = new MutationObserver(function() { | 129 var observer = new MutationObserver(function(changes) { |
| 130 if (changes[0].attributeName != | |
| 131 'class') // Only care about class mutations | |
|
dpapad
2017/04/05 23:56:10
Formatting seems a bit off here. Can we move the c
scottchen
2017/04/06 01:11:13
Done.
| |
| 132 return; | |
| 133 | |
| 128 observerCount++; | 134 observerCount++; |
| 129 if (observerCount == 1) { // Triggered when scrolled to bottom. | 135 if (observerCount == 1) { // Triggered when scrolled to bottom. |
| 136 console.log(bodyContainer.classList[0]); | |
|
dpapad
2017/04/05 23:56:10
Remove console.log.
scottchen
2017/04/06 01:11:13
Done.
| |
| 130 assertFalse(bodyContainer.classList.contains('bottom-scrollable')); | 137 assertFalse(bodyContainer.classList.contains('bottom-scrollable')); |
| 138 assertTrue(bodyContainer.classList.contains('top-scrollable')); | |
| 131 bodyContainer.scrollTop = 0; | 139 bodyContainer.scrollTop = 0; |
| 132 } else if (observerCount == 2) { // Triggered when scrolled back to top. | 140 } else if (observerCount == 2) { // Triggered when scrolled back to top. |
|
dpapad
2017/04/05 23:56:10
Is there a way to test the case where both top and
| |
| 133 assertTrue(bodyContainer.classList.contains('bottom-scrollable')); | 141 assertTrue(bodyContainer.classList.contains('bottom-scrollable')); |
| 142 assertFalse(bodyContainer.classList.contains('top-scrollable')); | |
| 134 observer.disconnect(); | 143 observer.disconnect(); |
| 135 done(); | 144 done(); |
| 136 } | 145 } |
| 137 }); | 146 }); |
| 138 observer.observe(bodyContainer, {attributes: true}); | 147 observer.observe(bodyContainer, {attributes: true}); |
| 139 | 148 |
| 140 // Height is normally set via CSS, but mixin doesn't work with innerHTML. | 149 // Height is normally set via CSS, but mixin doesn't work with innerHTML. |
| 141 bodyContainer.style.height = '1px'; | 150 bodyContainer.style.height = '1px'; |
| 142 bodyContainer.scrollTop = 100; | 151 bodyContainer.scrollTop = 100; |
| 143 dialog.showModal(); // Attach the dialog for the first time here. | |
| 144 }); | 152 }); |
| 145 }); | 153 }); |
| OLD | NEW |