OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <!-- | |
3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
7 Code distributed by Google as part of the polymer project is also | |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
9 --> | |
10 <html> | |
11 <head> | |
12 <title>core-overlay</title> | |
13 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> | |
14 <script src="../../../platform/platform.js"></script> | |
15 <script src="../../../polymer-test-tools/chai/chai.js"></script> | |
16 <script src="../../../polymer-test-tools/htmltest.js"></script> | |
17 <link rel="import" href="../../../core-transition/core-transition-css.html"> | |
18 <link rel="import" href="../../core-overlay.html"> | |
19 <style> | |
20 body { | |
21 margin: 0; | |
22 height: 100%; | |
23 } | |
24 | |
25 .sized { | |
26 height: 200px; | |
27 width: 300px; | |
28 border: 1px solid black; | |
29 padding: 10px; | |
30 } | |
31 | |
32 .positioned { | |
33 top: 0; | |
34 left: 0; | |
35 } | |
36 </style> | |
37 </head> | |
38 <body unresolved> | |
39 | |
40 <core-overlay class="sized" id="basic"> | |
41 Sized Overlay | |
42 </core-overlay> | |
43 | |
44 <core-overlay class="sized positioned" id="overlay"> | |
45 Positioned Overlay | |
46 </core-overlay> | |
47 | |
48 <template> | |
49 <div>"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusanti
um doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore v
eritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam
voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntu
r magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam
est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed qui
a non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quae
rat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corp
oris suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem
vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae c
onsequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"</div> | |
50 </template> | |
51 | |
52 <script> | |
53 document.addEventListener('polymer-ready', function() { | |
54 // setup | |
55 var basic = document.querySelector('#basic'); | |
56 var overlay = document.querySelector('#overlay'); | |
57 var template = document.querySelector('template'); | |
58 | |
59 function testWhenOpen(element, test, next) { | |
60 var l1 = function() { | |
61 test(); | |
62 element.async(function() { | |
63 element.opened = false; | |
64 }, 1); | |
65 }; | |
66 var l2 = function() { | |
67 element.removeEventListener('core-overlay-open-completed', l1); | |
68 element.removeEventListener('core-overlay-close-completed', l2); | |
69 next(); | |
70 }; | |
71 element.addEventListener('core-overlay-open-completed', l1); | |
72 element.addEventListener('core-overlay-close-completed', l2); | |
73 element.opened = true; | |
74 } | |
75 | |
76 asyncSeries([ | |
77 // centered overlay | |
78 function(next) { | |
79 testWhenOpen(basic, function() { | |
80 var rect = basic.getBoundingClientRect(); | |
81 chai.assert.ok(Math.abs(rect.left - (window.innerWidth - rect.right))
< 5, 'overlay centered horizontally'); | |
82 chai.assert.ok(Math.abs(rect.top - (window.innerHeight - rect.bottom))
< 5, 'overlay centered vertically'); | |
83 }, next); | |
84 }, | |
85 // css positioned overlay | |
86 function(next) { | |
87 testWhenOpen(overlay, function() { | |
88 var rect = overlay.getBoundingClientRect(); | |
89 chai.assert.equal(rect.left, 0, 'positions via css'); | |
90 chai.assert.equal(rect.top, 0, 'positions via css'); | |
91 }, next); | |
92 }, | |
93 // manual positioned overlay | |
94 function(next) { | |
95 overlay.style.left = overlay.style.top = 'auto'; | |
96 overlay.style.right = '0px'; | |
97 testWhenOpen(overlay, function() { | |
98 var rect = overlay.getBoundingClientRect(); | |
99 chai.assert.equal(rect.right, window.innerWidth, 'positioned manually'
); | |
100 chai.assert.ok(Math.abs(rect.top - (window.innerHeight - rect.bottom))
< 5, 'overlay centered vertically'); | |
101 }, next); | |
102 }, | |
103 // overflow, position top, left | |
104 function(next) { | |
105 overlay.style.left = overlay.style.top = '0px'; | |
106 overlay.style.right = 'auto'; | |
107 overlay.style.width = overlay.style.height = 'auto'; | |
108 for (var i=0; i<20; i++) { | |
109 overlay.appendChild(template.content.cloneNode(true)); | |
110 } | |
111 testWhenOpen(overlay, function() { | |
112 var rect = overlay.getBoundingClientRect(); | |
113 chai.assert.ok(window.innerWidth >= rect.right, 'overlay constrained t
o window size'); | |
114 chai.assert.ok(window.innerHeight >= rect.bottom, 'overlay constrained
to window size'); | |
115 }, next); | |
116 }, | |
117 // overflow, position, bottom, right | |
118 function(next) { | |
119 overlay.style.right = overlay.style.bottom = '0px'; | |
120 overlay.style.left = overlay.style.top = 'auto'; | |
121 testWhenOpen(overlay, function() { | |
122 var rect = overlay.getBoundingClientRect(); | |
123 chai.assert.ok(window.innerWidth >= rect.right, 'overlay constrained t
o window size'); | |
124 chai.assert.ok(window.innerHeight >= rect.bottom, 'overlay constrained
to window size'); | |
125 }, next); | |
126 }, | |
127 // overflow, unpositioned | |
128 function(next) { | |
129 overlay.style.right = overlay.style.bottom = 'auto'; | |
130 overlay.style.left = overlay.style.top = 'auto'; | |
131 testWhenOpen(overlay, function() { | |
132 var rect = overlay.getBoundingClientRect(); | |
133 chai.assert.ok(window.innerWidth >= rect.right, 'overlay constrained t
o window size'); | |
134 chai.assert.ok(window.innerHeight >= rect.bottom, 'overlay constrained
to window size'); | |
135 }, next); | |
136 }, | |
137 // overflow, unpositioned, layered | |
138 function(next) { | |
139 overlay.layered = true; | |
140 testWhenOpen(overlay, function() { | |
141 var rect = overlay.getBoundingClientRect(); | |
142 chai.assert.ok(window.innerWidth >= rect.right, 'overlay constrained t
o window size'); | |
143 chai.assert.ok(window.innerHeight >= rect.bottom, 'overlay constrained
to window size'); | |
144 }, next); | |
145 }, | |
146 ], done); | |
147 }); | |
148 | |
149 </script> | |
150 | |
151 </body> | |
152 </html> | |
OLD | NEW |