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 | </head> |
| 8 | <body> |
| 9 | <p>Test that dialog is centered in the viewport. The test passes if you see a |
| 10 | box in the center of the screen.</p> |
| 11 | <div id="console"></div> |
| 12 | <dialog>Hello</dialog> |
| 13 | <script> |
| 14 | function writeToConsole(s) { |
| 15 | var console = document.getElementById('console'); |
| 16 | var span = document.createElement('span'); |
| 17 | span.textContent = s; |
| 18 | console.appendChild(span); |
| 19 | console.appendChild(document.createElement('br')); |
| 20 | } |
| 21 | |
| 22 | function checkCentered(dialog) { |
| 23 | var expectedTop = (window.innerHeight - dialog.offsetHeight) / 2; |
| 24 | var expectedLeft = (window.innerWidth - dialog.offsetWidth) / 2; |
| 25 | var rect = dialog.getBoundingClientRect(); |
| 26 | if (rect.top == expectedTop && rect.left == expectedLeft) { |
| 27 | writeToConsole('SUCCESS'); |
| 28 | } else { |
| 29 | writeToConsole('FAIL: expected dialog top,left to be ' + |
| 30 | expectedTop + ',' + expectedLeft + ' and was actually ' + |
| 31 | rect.top + ',' + rect.left); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | var dialog = document.querySelector('dialog'); |
| 36 | dialogPolyfill.registerDialog(dialog); |
| 37 | dialog.show(); |
| 38 | checkCentered(dialog); |
| 39 | </script> |
| 40 | </body> |
| 41 | </html> |