OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <link href="resources/dialog-layout.css" rel="stylesheet"> |
| 3 <script src="../../../resources/js-test.js"></script> |
| 4 <dialog id="dialog">It is my dialog.</dialog> |
| 5 <div id="absolute-div"> |
| 6 <div id="relative-div"></div> |
| 7 </div> |
| 8 <script> |
| 9 description('Tests layout of absolutely positioned modal dialogs.'); |
| 10 |
| 11 function checkCentered(dialog) { |
| 12 centeredTop = (window.innerHeight - dialog.offsetHeight) / 2; |
| 13 shouldBe('dialog.getBoundingClientRect().top', 'centeredTop'); |
| 14 } |
| 15 |
| 16 function reset() { |
| 17 if (dialog.open) |
| 18 dialog.close(); |
| 19 dialog.remove(); |
| 20 document.body.appendChild(dialog); |
| 21 window.scroll(0, 500); |
| 22 } |
| 23 |
| 24 dialog = document.querySelector('#dialog'); |
| 25 absoluteContainer = document.querySelector('#absolute-div'); |
| 26 relativeContainer = document.querySelector('#relative-div'); |
| 27 reset(); |
| 28 |
| 29 (function() { |
| 30 debug('<br>showModal() should center in the viewport.'); |
| 31 |
| 32 dialog.showModal(); |
| 33 checkCentered(dialog); |
| 34 reset(); |
| 35 }()); |
| 36 |
| 37 (function() { |
| 38 debug('<br>The computed top and bottom of a centered dialog should still hav
e position auto.'); |
| 39 |
| 40 dialog.showModal(); |
| 41 shouldBeEqualToString('window.getComputedStyle(dialog).top', 'auto'); |
| 42 shouldBeEqualToString('window.getComputedStyle(dialog).bottom', 'auto'); |
| 43 reset(); |
| 44 }()); |
| 45 |
| 46 (function() { |
| 47 debug('<br>Dialog should be recentered if showModal() is called after close(
).'), |
| 48 |
| 49 dialog.showModal(); |
| 50 dialog.close(); |
| 51 window.scroll(0, 2 * window.scrollY); |
| 52 dialog.showModal(); |
| 53 checkCentered(dialog); |
| 54 reset(); |
| 55 }()); |
| 56 |
| 57 (function() { |
| 58 debug('<br>Dialog should not recenter on relayout.'); |
| 59 |
| 60 dialog.showModal(); |
| 61 expectedTop = dialog.getBoundingClientRect().top; |
| 62 window.scroll(0, window.scrollY * 2); |
| 63 document.body.offsetHeight; |
| 64 window.scroll(0, window.scrollY / 2); |
| 65 shouldBe('dialog.getBoundingClientRect().top', 'expectedTop'); |
| 66 reset(); |
| 67 }()); |
| 68 |
| 69 (function() { |
| 70 debug('<br>A tall dialog should be positioned at the top of the viewport.'); |
| 71 |
| 72 dialog.style.height = '20000px'; |
| 73 dialog.showModal(); |
| 74 shouldBe('dialog.getBoundingClientRect().top', '0'); |
| 75 |
| 76 dialog.style.height = 'auto'; |
| 77 reset(); |
| 78 }()); |
| 79 |
| 80 (function() { |
| 81 debug('<br>The dialog should be centered regardless of the presence of a hor
izontal scrollbar.'); |
| 82 |
| 83 document.body.style.width = '4000px'; |
| 84 dialog.showModal(); |
| 85 checkCentered(dialog); |
| 86 |
| 87 document.body.style.width = 'auto'; |
| 88 reset(); |
| 89 }()); |
| 90 |
| 91 (function() { |
| 92 debug('<br>Centering should work when dialog is inside positioned containers
.'); |
| 93 |
| 94 dialog.remove(); |
| 95 absoluteContainer.appendChild(dialog); |
| 96 dialog.showModal(); |
| 97 checkCentered(dialog); |
| 98 dialog.close(); |
| 99 |
| 100 dialog.remove(); |
| 101 relativeContainer.appendChild(dialog); |
| 102 dialog.showModal(); |
| 103 checkCentered(dialog); |
| 104 |
| 105 reset(); |
| 106 }()); |
| 107 |
| 108 (function() { |
| 109 debug('<br>A centered dialog\'s position should survive becoming display:non
e temporarily.'); |
| 110 |
| 111 dialog.showModal(); |
| 112 expectedTop = dialog.getBoundingClientRect().top; |
| 113 relativeContainer.style.display = 'none'; |
| 114 relativeContainer.style.display = 'block'; |
| 115 shouldBe('dialog.getBoundingClientRect().top', 'expectedTop'); |
| 116 |
| 117 reset(); |
| 118 }()); |
| 119 |
| 120 (function() { |
| 121 debug('<br>Dialog should lose centering when removed from the document.'); |
| 122 |
| 123 dialog.showModal(); |
| 124 dialog.remove(); |
| 125 relativeContainer.appendChild(dialog); |
| 126 shouldBe('dialog.getBoundingClientRect().top', 'relativeContainer.getBoundin
gClientRect().top'); |
| 127 |
| 128 reset(); |
| 129 }()); |
| 130 |
| 131 (function() { |
| 132 debug('<br>Dialog\'s specified position should survive after close() and sho
wModal().'); |
| 133 |
| 134 dialog.showModal(); |
| 135 dialog.style.top = '0px'; |
| 136 expectedTop = dialog.getBoundingClientRect().top; |
| 137 dialog.close(); |
| 138 dialog.showModal(); |
| 139 shouldBe('dialog.getBoundingClientRect().top', 'expectedTop'); |
| 140 |
| 141 dialog.style.top = 'auto'; |
| 142 reset(); |
| 143 }()); |
| 144 |
| 145 (function() { |
| 146 debug('<br>Dialog should be recentered if showModal() is called after removi
ng \'open\'.'); |
| 147 |
| 148 dialog.showModal(); |
| 149 dialog.removeAttribute('open'); |
| 150 window.scroll(0, window.scrollY * 2); |
| 151 dialog.showModal(); |
| 152 checkCentered(dialog); |
| 153 |
| 154 reset(); |
| 155 }()); |
| 156 |
| 157 (function() { |
| 158 debug('<br>Dialog should not be centered if showModal() was called when an a
ncestor had display \'none\'.'); |
| 159 |
| 160 dialog.remove(); |
| 161 absoluteContainer.appendChild(dialog); |
| 162 absoluteContainer.style.display = 'none'; |
| 163 dialog.showModal(); |
| 164 absoluteContainer.style.display = 'block'; |
| 165 // Since dialog's containing block is the ICB, it's statically positioned af
ter <body>. |
| 166 shouldBe('dialog.getBoundingClientRect().top', 'document.body.getBoundingCli
entRect().bottom'); |
| 167 reset(); |
| 168 }()); |
| 169 |
| 170 (function() { |
| 171 debug('<br>A dialog with specified \'top\' should be positioned as usual'); |
| 172 offset = 50; |
| 173 dialog.style.top = offset + 'px'; |
| 174 dialog.showModal(); |
| 175 shouldBe('dialog.getBoundingClientRect().top + window.scrollY', 'offset'); |
| 176 dialog.style.top = 'auto'; |
| 177 reset(); |
| 178 }()); |
| 179 |
| 180 (function() { |
| 181 debug('<br>A dialog with specified \'bottom\' should be positioned as usual'
); |
| 182 offset = 50; |
| 183 dialog.style.bottom = offset + 'px'; |
| 184 dialog.showModal(); |
| 185 shouldBe('dialog.getBoundingClientRect().bottom + window.scrollY', 'window.i
nnerHeight - offset'); |
| 186 dialog.style.bottom = 'auto'; |
| 187 reset(); |
| 188 }()); |
| 189 </script> |
OLD | NEW |