blob: 0eaff606339b0b02c122c0da0e8e884b1e7455e4 [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</head>
8<body>
9<p>Test that dialog is centered in the viewport. The test passes if you see a
10box in the center of the screen.</p>
11<div id="console"></div>
12<dialog>Hello</dialog>
13<script>
14function 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
22function 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
35var dialog = document.querySelector('dialog');
36dialogPolyfill.registerDialog(dialog);
37dialog.show();
38checkCentered(dialog);
39</script>
40</body>
41</html>