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 function pressEnter(element) { | 6 function pressEnter(element) { |
7 MockInteractions.keyEventOn(element, 'keypress', 13, undefined, 'Enter'); | 7 MockInteractions.keyEventOn(element, 'keypress', 13, undefined, 'Enter'); |
8 } | 8 } |
9 | 9 |
10 setup(function() { | 10 setup(function() { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 document.body.innerHTML = ` | 149 document.body.innerHTML = ` |
150 <dialog is="cr-dialog" show-scroll-borders> | 150 <dialog is="cr-dialog" show-scroll-borders> |
151 <div class="title">title</div> | 151 <div class="title">title</div> |
152 <div class="body">body</div> | 152 <div class="body">body</div> |
153 </dialog>`; | 153 </dialog>`; |
154 | 154 |
155 var dialog = document.body.querySelector('dialog'); | 155 var dialog = document.body.querySelector('dialog'); |
156 var bodyContainer = dialog.$$('.body-container'); | 156 var bodyContainer = dialog.$$('.body-container'); |
157 assertTrue(!!bodyContainer); | 157 assertTrue(!!bodyContainer); |
158 | 158 |
| 159 dialog.showModal(); // Attach the dialog for the first time here. |
| 160 |
159 var observerCount = 0; | 161 var observerCount = 0; |
160 | 162 |
161 // Needs to setup the observer before attaching, since InteractionObserver | 163 // Needs to setup the observer before attaching, since InteractionObserver |
162 // calls callback before MutationObserver does. | 164 // calls callback before MutationObserver does. |
163 var observer = new MutationObserver(function() { | 165 var observer = new MutationObserver(function(changes) { |
| 166 // Only care about class mutations. |
| 167 if (changes[0].attributeName != 'class') |
| 168 return; |
| 169 |
164 observerCount++; | 170 observerCount++; |
165 if (observerCount == 1) { // Triggered when scrolled to bottom. | 171 switch (observerCount) { |
166 assertFalse(bodyContainer.classList.contains('bottom-scrollable')); | 172 case 1: // Triggered when scrolled to bottom. |
167 bodyContainer.scrollTop = 0; | 173 assertFalse(bodyContainer.classList.contains('bottom-scrollable')); |
168 } else if (observerCount == 2) { // Triggered when scrolled back to top. | 174 assertTrue(bodyContainer.classList.contains('top-scrollable')); |
169 assertTrue(bodyContainer.classList.contains('bottom-scrollable')); | 175 bodyContainer.scrollTop = 0; |
170 observer.disconnect(); | 176 break; |
171 done(); | 177 case 2: // Triggered when scrolled back to top. |
| 178 assertTrue(bodyContainer.classList.contains('bottom-scrollable')); |
| 179 assertFalse(bodyContainer.classList.contains('top-scrollable')); |
| 180 bodyContainer.scrollTop = 2; |
| 181 break; |
| 182 case 3: // Triggered when finally scrolling to middle. |
| 183 assertTrue(bodyContainer.classList.contains('bottom-scrollable')); |
| 184 assertTrue(bodyContainer.classList.contains('top-scrollable')); |
| 185 observer.disconnect(); |
| 186 done(); |
| 187 break; |
172 } | 188 } |
173 }); | 189 }); |
174 observer.observe(bodyContainer, {attributes: true}); | 190 observer.observe(bodyContainer, {attributes: true}); |
175 | 191 |
176 // Height is normally set via CSS, but mixin doesn't work with innerHTML. | 192 // Height is normally set via CSS, but mixin doesn't work with innerHTML. |
177 bodyContainer.style.height = '1px'; | 193 bodyContainer.style.height = '1px'; |
178 bodyContainer.scrollTop = 100; | 194 bodyContainer.scrollTop = 100; |
179 dialog.showModal(); // Attach the dialog for the first time here. | |
180 }); | 195 }); |
181 }); | 196 }); |
OLD | NEW |