blob: 5d09f21031409efdcb9aa5039f007d47334ff5fd [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<!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>
8body {
9 height: 10000px;
10}
11dialog {
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
26box in the center of the screen.</p>
27<div id="ruler"></div>
28<div id="console"></div>
29<dialog></dialog>
30<script>
31function 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
39function windowWidthMinusScrollbar() {
40 return document.getElementById('ruler').offsetWidth;
41}
42
43function 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
56var dialog = document.querySelector('dialog');
57dialogPolyfill.registerDialog(dialog);
58dialog.show();
59dialog.close();
60window.scrollTo(0, 500);
61dialog.show();
62checkCentered(dialog);
63</script>
64</body>
65</html>