2 <link href=
"resources/dialog-layout.css" rel=
"stylesheet">
8 <script src=
"../../../resources/js-test.js"></script>
9 <dialog id=
"dialog">It is my dialog.
</dialog>
10 <div id=
"absolute-div">
11 <div id=
"relative-div"></div>
14 description('Tests layout of fixed positioned dialogs.');
16 function checkCentered(dialog
) {
17 centeredTop
= (window
.innerHeight
- dialog
.offsetHeight
) / 2;
18 shouldBe('dialog.getBoundingClientRect().top', 'centeredTop');
25 document
.body
.appendChild(dialog
);
26 window
.scroll(0, 500);
29 dialog
= document
.querySelector('#dialog');
30 absoluteContainer
= document
.querySelector('#absolute-div');
31 relativeContainer
= document
.querySelector('#relative-div');
35 debug('<br>showModal() should center in the viewport.');
38 checkCentered(dialog
);
43 debug('<br>The computed top and bottom of a centered dialog should still have position auto.');
46 shouldBeEqualToString('window.getComputedStyle(dialog).top', 'auto');
47 shouldBeEqualToString('window.getComputedStyle(dialog).bottom', 'auto');
52 debug('<br>The dialog shold stay centered on scroll.'),
55 window
.scroll(0, 2 * window
.scrollY
);
56 checkCentered(dialog
);
61 debug('<br>A tall dialog should be positioned at the top of the viewport.');
63 dialog
.style
.height
= '20000px';
65 shouldBe('dialog.getBoundingClientRect().top', '0');
67 dialog
.style
.height
= 'auto';
72 debug('<br>The dialog should be centered regardless of the presence of a horizontal scrollbar.');
74 document
.body
.style
.width
= '4000px';
76 checkCentered(dialog
);
78 document
.body
.style
.width
= 'auto';
83 debug('<br>Centering should work when dialog is inside positioned containers.');
86 absoluteContainer
.appendChild(dialog
);
88 checkCentered(dialog
);
92 relativeContainer
.appendChild(dialog
);
94 checkCentered(dialog
);
100 debug('<br>A centered dialog\'s position should survive becoming display:none temporarily.');
103 expectedTop
= dialog
.getBoundingClientRect().top
;
104 relativeContainer
.style
.display
= 'none';
105 relativeContainer
.style
.display
= 'block';
106 shouldBe('dialog.getBoundingClientRect().top', 'expectedTop');
112 debug('<br>Dialog should lose centering when removed from the document.');
116 relativeContainer
.appendChild(dialog
);
117 shouldBe('dialog.getBoundingClientRect().top', '0');
123 debug('<br>Dialog\'s specified position should survive after close() and showModal().');
126 dialog
.style
.top
= '0px';
127 expectedTop
= dialog
.getBoundingClientRect().top
;
130 shouldBe('dialog.getBoundingClientRect().top', 'expectedTop');
132 dialog
.style
.top
= 'auto';
137 debug('<br>Dialog should not be centered if showModal() was called when an ancestor had display \'none\'.');
140 absoluteContainer
.appendChild(dialog
);
141 absoluteContainer
.style
.display
= 'none';
143 absoluteContainer
.style
.display
= 'block';
144 shouldBe('dialog.getBoundingClientRect().top', '0');
150 debug('<br>A dialog with specified \'top\' should be positioned as usual');
152 dialog
.style
.top
= offset
+ 'px';
154 shouldBe('dialog.getBoundingClientRect().top', 'offset');