| <!DOCTYPE html> |
| <html> |
| <style> |
| body { |
| height: 10000px; |
| } |
| |
| dialog { |
| padding: 0; |
| height: 50px; |
| width: 50px; |
| } |
| |
| #console { |
| position: fixed; |
| } |
| </style> |
| <body> |
| <dialog id="top-dialog"></dialog> |
| <dialog id="first-middle-dialog"></dialog> |
| <dialog id="second-middle-dialog" style="left: 100px"></dialog> |
| <dialog id="bottom-dialog"></dialog> |
| </body> |
| <script src="../../resources/js-test.js"></script> |
| <script> |
| debug('Test that multiple dialogs are centered properly.'); |
| |
| function expectedTop(dialog) { |
| return Math.floor((document.documentElement.clientHeight - dialog.offsetHeight) / 2); |
| } |
| |
| function showAndTest(id) { |
| debug('showing ' + id); |
| dialog = document.getElementById(id); |
| dialog.showModal(); |
| shouldBe('dialog.offsetTop', 'expectedTop(dialog)'); |
| } |
| |
| showAndTest('top-dialog'); |
| |
| window.scroll(0, 100); |
| showAndTest('first-middle-dialog'); |
| showAndTest('second-middle-dialog'); |
| |
| window.scroll(0, 200); |
| showAndTest('bottom-dialog'); |
| </script> |
| </html> |