Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / chrome / test / data / webui / position_util_test.html
blobc8abcc47f86a327b99e033802ab97cc16ce21c01
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <style>
6 html, body {
7 margin: 0;
8 width: 100%;
9 height: 100%;
12 #anchor {
13 position: absolute;
14 width: 10px;
15 height: 10px;
16 background: green;
19 #popup {
20 position: absolute;
21 top: 0;
22 left: 0;
23 width: 100px;
24 height: 100px;
25 background: red;
28 </style>
29 </head>
30 <body>
32 <div id=anchor></div>
33 <div id=popup></div>
35 <script>
37 var anchor = document.getElementById('anchor');
38 var popup = document.getElementById('popup');
39 var anchorParent = anchor.offsetParent;
40 var oldGetBoundingClientRect = anchorParent.getBoundingClientRect;
41 var availRect;
43 function MockRect(w, h) {
44 this.width = w;
45 this.height = h;
46 this.right = this.left + w;
47 this.bottom = this.top + h;
49 MockRect.prototype = {
50 left: 0,
51 top: 0
54 function setUp() {
55 anchor.style.top = '100px';
56 anchor.style.left = '100px';
57 availRect = new MockRect(200, 200);
58 anchorParent.getBoundingClientRect = function() {
59 return availRect;
63 function tearDown() {
64 document.documentElement.dir = 'ltr';
65 anchorParent.getBoundingClientRect = oldGetBoundingClientRect;
68 function testAbovePrimary() {
69 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE);
71 assertEquals('auto', popup.style.top);
72 assertEquals('100px', popup.style.bottom);
74 anchor.style.top = '90px';
75 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE);
76 assertEquals('100px', popup.style.top);
77 assertEquals('auto', popup.style.bottom);
80 function testBelowPrimary() {
81 // ensure enough below
82 anchor.style.top = '90px';
84 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW);
86 assertEquals('100px', popup.style.top);
87 assertEquals('auto', popup.style.bottom);
89 // ensure not enough below
90 anchor.style.top = '100px';
92 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW);
93 assertEquals('auto', popup.style.top);
94 assertEquals('100px', popup.style.bottom);
97 function testBeforePrimary() {
98 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BEFORE);
100 assertEquals('auto', popup.style.left);
101 assertEquals('100px', popup.style.right);
103 anchor.style.left = '90px';
104 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BEFORE);
105 assertEquals('100px', popup.style.left);
106 assertEquals('auto', popup.style.right);
109 function testBeforePrimaryRtl() {
110 document.documentElement.dir = 'rtl';
112 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER);
114 assertEquals('auto', popup.style.left);
115 assertEquals('100px', popup.style.right);
117 anchor.style.left = '90px';
119 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER);
120 assertEquals('100px', popup.style.left);
121 assertEquals('auto', popup.style.right);
124 function testAfterPrimary() {
125 // ensure enough to the right
126 anchor.style.left = '90px';
128 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER);
130 assertEquals('100px', popup.style.left);
131 assertEquals('auto', popup.style.right);
133 // ensure not enough below
134 anchor.style.left = '100px';
136 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER);
137 assertEquals('auto', popup.style.left);
138 assertEquals('100px', popup.style.right);
141 function testAfterPrimaryRtl() {
142 document.documentElement.dir = 'rtl';
144 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER);
146 assertEquals('auto', popup.style.left);
147 assertEquals('100px', popup.style.right);
149 // ensure not enough below
150 anchor.style.left = '90px';
152 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER);
153 assertEquals('100px', popup.style.left);
154 assertEquals('auto', popup.style.right);
157 function testAboveSecondary() {
158 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE);
160 assertEquals('100px', popup.style.left);
161 assertEquals('auto', popup.style.right);
163 anchor.style.left = '110px';
165 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE);
167 assertEquals('auto', popup.style.left);
168 assertEquals('80px', popup.style.right);
171 function testAboveSecondaryRtl() {
172 document.documentElement.dir = 'rtl';
174 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE);
176 assertEquals('auto', popup.style.left);
177 assertEquals('90px', popup.style.right);
179 anchor.style.left = '80px';
181 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE);
183 assertEquals('80px', popup.style.left);
184 assertEquals('auto', popup.style.right);
187 function testAboveSecondarySwappedAlign() {
188 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE, true);
190 assertEquals('auto', popup.style.left);
191 assertEquals('90px', popup.style.right);
193 anchor.style.left = '80px';
195 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE, true);
197 assertEquals('80px', popup.style.left);
198 assertEquals('auto', popup.style.right);
201 function testBelowSecondary() {
202 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW);
204 assertEquals('100px', popup.style.left);
205 assertEquals('auto', popup.style.right);
207 anchor.style.left = '110px';
209 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW);
211 assertEquals('auto', popup.style.left);
212 assertEquals('80px', popup.style.right);
215 function testBelowSecondaryRtl() {
216 document.documentElement.dir = 'rtl';
218 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW);
220 assertEquals('auto', popup.style.left);
221 assertEquals('90px', popup.style.right);
223 anchor.style.left = '80px';
225 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW);
227 assertEquals('80px', popup.style.left);
228 assertEquals('auto', popup.style.right);
231 function testBelowSecondarySwappedAlign() {
232 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW, true);
234 assertEquals('auto', popup.style.left);
235 assertEquals('90px', popup.style.right);
237 anchor.style.left = '80px';
239 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW, true);
241 assertEquals('80px', popup.style.left);
242 assertEquals('auto', popup.style.right);
245 function testBeforeSecondary() {
246 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BEFORE);
248 assertEquals('100px', popup.style.top);
249 assertEquals('auto', popup.style.bottom);
251 anchor.style.top = '110px';
253 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BEFORE);
255 assertEquals('auto', popup.style.top);
256 assertEquals('80px', popup.style.bottom);
259 function testAfterSecondary() {
260 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER);
262 assertEquals('100px', popup.style.top);
263 assertEquals('auto', popup.style.bottom);
265 anchor.style.top = '110px';
267 cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER);
269 assertEquals('auto', popup.style.top);
270 assertEquals('80px', popup.style.bottom);
273 function testPositionAtPoint() {
274 cr.ui.positionPopupAtPoint(100, 100, popup);
276 assertEquals('100px', popup.style.left);
277 assertEquals('100px', popup.style.top);
278 assertEquals('auto', popup.style.right);
279 assertEquals('auto', popup.style.bottom);
281 cr.ui.positionPopupAtPoint(100, 150, popup);
283 assertEquals('100px', popup.style.left);
284 assertEquals('auto', popup.style.top);
285 assertEquals('auto', popup.style.right);
286 assertEquals('50px', popup.style.bottom);
288 cr.ui.positionPopupAtPoint(150, 150, popup);
290 assertEquals('auto', popup.style.left);
291 assertEquals('auto', popup.style.top);
292 assertEquals('50px', popup.style.right);
293 assertEquals('50px', popup.style.bottom);
296 </script>
298 </body>
299 </html>