Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame^] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <meta charset='utf-8'> |
| 4 | <head> |
| 5 | <script src="../dist/dialog-polyfill.js"></script> |
| 6 | <link rel="stylesheet" type="text/css" href="../dist/dialog-polyfill.css"> |
| 7 | <style> |
| 8 | body { |
| 9 | height: 10000px; |
| 10 | } |
| 11 | dialog { |
| 12 | width: 100px; |
| 13 | } |
| 14 | #console { |
| 15 | position: fixed; |
| 16 | } |
| 17 | #ruler { |
| 18 | position: absolute; |
| 19 | left: 0; |
| 20 | width: 100%; |
| 21 | } |
| 22 | </style> |
| 23 | </head> |
| 24 | <body> |
| 25 | <p>Test that dialog is recentered if reopened. The test passes if you see a |
| 26 | box in the center of the screen.</p> |
| 27 | <div id="ruler"></div> |
| 28 | <div id="console"></div> |
| 29 | <dialog></dialog> |
| 30 | <script> |
| 31 | function writeToConsole(s) { |
| 32 | var console = document.getElementById('console'); |
| 33 | var span = document.createElement('span'); |
| 34 | span.textContent = s; |
| 35 | console.appendChild(span); |
| 36 | console.appendChild(document.createElement('br')); |
| 37 | } |
| 38 | |
| 39 | function windowWidthMinusScrollbar() { |
| 40 | return document.getElementById('ruler').offsetWidth; |
| 41 | } |
| 42 | |
| 43 | function checkCentered(dialog) { |
| 44 | var expectedTop = (window.innerHeight - dialog.offsetHeight) / 2; |
| 45 | var expectedLeft = (windowWidthMinusScrollbar() - dialog.offsetWidth) / 2; |
| 46 | var rect = dialog.getBoundingClientRect(); |
| 47 | if (rect.top == expectedTop && rect.left == expectedLeft) { |
| 48 | writeToConsole('SUCCESS'); |
| 49 | } else { |
| 50 | writeToConsole('FAIL: expected dialog top,left to be ' + |
| 51 | expectedTop + ',' + expectedLeft + ' and was actually ' + |
| 52 | rect.top + ',' + rect.left); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | var dialog = document.querySelector('dialog'); |
| 57 | dialogPolyfill.registerDialog(dialog); |
| 58 | dialog.show(); |
| 59 | dialog.close(); |
| 60 | window.scrollTo(0, 500); |
| 61 | dialog.show(); |
| 62 | checkCentered(dialog); |
| 63 | </script> |
| 64 | </body> |
| 65 | </html> |