OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <link href="resources/dialog-layout.css" rel="stylesheet"> | |
3 <script src="../../../resources/js-test.js"></script> | |
4 <dialog id="dialog">It is my dialog.</dialog> | |
5 <div id="absolute-div"> | |
6 <div id="relative-div"></div> | |
7 </div> | |
8 <script> | |
9 description('Tests layout of absolutely positioned modal dialogs.'); | |
10 | |
11 function checkCentered(dialog) { | |
12 centeredTop = (window.innerHeight - dialog.offsetHeight) / 2; | |
13 shouldBe('dialog.getBoundingClientRect().top', 'centeredTop'); | |
14 } | |
15 | |
16 function reset() { | |
17 if (dialog.open) | |
18 dialog.close(); | |
19 dialog.remove(); | |
20 document.body.appendChild(dialog); | |
21 window.scroll(0, 500); | |
22 } | |
23 | |
24 dialog = document.querySelector('#dialog'); | |
25 absoluteContainer = document.querySelector('#absolute-div'); | |
26 relativeContainer = document.querySelector('#relative-div'); | |
27 reset(); | |
28 | |
29 (function() { | |
30 debug('<br>showModal() should center in the viewport.'); | |
31 | |
32 dialog.showModal(); | |
33 checkCentered(dialog); | |
34 reset(); | |
35 }()); | |
36 | |
37 (function() { | |
38 debug('<br>The dialog is a positioned element, so the top and bottom should
not have style auto.'); | |
39 | |
40 dialog.style.height = '20px'; | |
41 dialog.showModal(); | |
42 shouldBeEqualToString('window.getComputedStyle(dialog).top', '790px'); | |
43 shouldBeEqualToString('window.getComputedStyle(dialog).bottom', '-210px'); | |
44 | |
45 dialog.style.height = 'auto'; | |
46 reset(); | |
47 }()); | |
48 | |
49 (function() { | |
50 debug('<br>Dialog should be recentered if showModal() is called after close(
).'), | |
51 | |
52 dialog.showModal(); | |
53 dialog.close(); | |
54 window.scroll(0, 2 * window.scrollY); | |
55 dialog.showModal(); | |
56 checkCentered(dialog); | |
57 reset(); | |
58 }()); | |
59 | |
60 (function() { | |
61 debug('<br>Dialog should not recenter on relayout.'); | |
62 | |
63 dialog.showModal(); | |
64 expectedTop = dialog.getBoundingClientRect().top; | |
65 window.scroll(0, window.scrollY * 2); | |
66 document.body.offsetHeight; | |
67 window.scroll(0, window.scrollY / 2); | |
68 shouldBe('dialog.getBoundingClientRect().top', 'expectedTop'); | |
69 reset(); | |
70 }()); | |
71 | |
72 (function() { | |
73 debug('<br>A tall dialog should be positioned at the top of the viewport.'); | |
74 | |
75 dialog.style.height = '20000px'; | |
76 dialog.showModal(); | |
77 shouldBe('dialog.getBoundingClientRect().top', '0'); | |
78 | |
79 dialog.style.height = 'auto'; | |
80 reset(); | |
81 }()); | |
82 | |
83 (function() { | |
84 debug('<br>The dialog should be centered regardless of the presence of a hor
izontal scrollbar.'); | |
85 | |
86 document.body.style.width = '4000px'; | |
87 dialog.showModal(); | |
88 checkCentered(dialog); | |
89 | |
90 document.body.style.width = 'auto'; | |
91 reset(); | |
92 }()); | |
93 | |
94 (function() { | |
95 debug('<br>Centering should work when dialog is inside positioned containers
.'); | |
96 | |
97 dialog.remove(); | |
98 absoluteContainer.appendChild(dialog); | |
99 dialog.showModal(); | |
100 checkCentered(dialog); | |
101 dialog.close(); | |
102 | |
103 dialog.remove(); | |
104 relativeContainer.appendChild(dialog); | |
105 dialog.showModal(); | |
106 checkCentered(dialog); | |
107 | |
108 reset(); | |
109 }()); | |
110 | |
111 (function() { | |
112 debug('<br>A centered dialog\'s position should survive becoming display:non
e temporarily.'); | |
113 | |
114 dialog.showModal(); | |
115 expectedTop = dialog.getBoundingClientRect().top; | |
116 relativeContainer.style.display = 'none'; | |
117 relativeContainer.style.display = 'block'; | |
118 shouldBe('dialog.getBoundingClientRect().top', 'expectedTop'); | |
119 | |
120 reset(); | |
121 }()); | |
122 | |
123 (function() { | |
124 debug('<br>Dialog should lose centering when removed from the document.'); | |
125 | |
126 dialog.showModal(); | |
127 dialog.remove(); | |
128 relativeContainer.appendChild(dialog); | |
129 shouldBe('dialog.getBoundingClientRect().top', 'relativeContainer.getBoundin
gClientRect().top'); | |
130 | |
131 reset(); | |
132 }()); | |
133 | |
134 (function() { | |
135 debug('<br>Dialog\'s specified position should survive after close() and sho
wModal().'); | |
136 | |
137 dialog.showModal(); | |
138 dialog.style.top = '0px'; | |
139 expectedTop = dialog.getBoundingClientRect().top; | |
140 dialog.close(); | |
141 dialog.showModal(); | |
142 shouldBe('dialog.getBoundingClientRect().top', 'expectedTop'); | |
143 | |
144 dialog.style.top = 'auto'; | |
145 reset(); | |
146 }()); | |
147 | |
148 (function() { | |
149 debug('<br>Dialog should be recentered if showModal() is called after removi
ng \'open\'.'); | |
150 | |
151 dialog.showModal(); | |
152 dialog.removeAttribute('open'); | |
153 window.scroll(0, window.scrollY * 2); | |
154 dialog.showModal(); | |
155 checkCentered(dialog); | |
156 | |
157 reset(); | |
158 }()); | |
159 | |
160 (function() { | |
161 debug('<br>Dialog should not be centered if showModal() was called when an a
ncestor had display \'none\'.'); | |
162 | |
163 dialog.remove(); | |
164 absoluteContainer.appendChild(dialog); | |
165 absoluteContainer.style.display = 'none'; | |
166 dialog.showModal(); | |
167 absoluteContainer.style.display = 'block'; | |
168 // Since dialog's containing block is the ICB, it's statically positioned af
ter <body>. | |
169 shouldBe('dialog.getBoundingClientRect().top', 'document.body.getBoundingCli
entRect().bottom'); | |
170 reset(); | |
171 }()); | |
172 | |
173 (function() { | |
174 debug('<br>A dialog with specified \'top\' should be positioned as usual'); | |
175 offset = 50; | |
176 dialog.style.top = offset + 'px'; | |
177 dialog.showModal(); | |
178 shouldBe('dialog.getBoundingClientRect().top + window.scrollY', 'offset'); | |
179 dialog.style.top = 'auto'; | |
180 reset(); | |
181 }()); | |
182 | |
183 (function() { | |
184 debug('<br>A dialog with specified \'bottom\' should be positioned as usual'
); | |
185 offset = 50; | |
186 dialog.style.bottom = offset + 'px'; | |
187 dialog.showModal(); | |
188 shouldBe('dialog.getBoundingClientRect().bottom + window.scrollY', 'window.i
nnerHeight - offset'); | |
189 dialog.style.bottom = 'auto'; | |
190 reset(); | |
191 }()); | |
192 </script> | |
OLD | NEW |