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 margin: 16px; | |
31 } | |
32 | |
33 .positioned { | |
34 top: 0; | |
35 left: 0; | |
36 } | |
37 </style> | |
38 </head> | |
39 <body unresolved> | |
40 | |
41 <core-overlay class="sized" id="basic"> | |
42 Sized Overlay | |
43 </core-overlay> | |
44 | |
45 <core-overlay class="sized positioned" id="overlay"> | |
46 Positioned Overlay | |
47 </core-overlay> | |
48 | |
49 <template> | |
50 <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> | |
51 </template> | |
52 | |
53 <script> | |
54 document.addEventListener('polymer-ready', function() { | |
55 // setup | |
56 var basic = document.querySelector('#basic'); | |
57 var overlay = document.querySelector('#overlay'); | |
58 var template = document.querySelector('template'); | |
59 | |
60 function testWhenOpen(element, test, next) { | |
61 var l1 = function() { | |
62 test(); | |
63 element.async(function() { | |
64 element.opened = false; | |
65 }, 1); | |
66 }; | |
67 var l2 = function() { | |
68 element.removeEventListener('core-overlay-open-completed', l1); | |
69 element.removeEventListener('core-overlay-close-completed', l2); | |
70 next(); | |
71 }; | |
72 element.addEventListener('core-overlay-open-completed', l1); | |
73 element.addEventListener('core-overlay-close-completed', l2); | |
74 element.opened = true; | |
75 } | |
76 | |
77 asyncSeries([ | |
78 // centered overlay | |
79 function(next) { | |
80 testWhenOpen(basic, function() { | |
81 var rect = basic.getBoundingClientRect(); | |
82 chai.assert.ok(Math.abs(rect.left - (window.innerWidth - rect.right))
< 5, 'overlay centered horizontally'); | |
83 chai.assert.ok(Math.abs(rect.top - (window.innerHeight - rect.bottom))
< 5, 'overlay centered vertically'); | |
84 }, next); | |
85 }, | |
86 // css positioned overlay | |
87 function(next) { | |
88 testWhenOpen(overlay, function() { | |
89 var rect = overlay.getBoundingClientRect(); | |
90 chai.assert.equal(rect.left, 16, 'positions via css'); | |
91 chai.assert.equal(rect.top, 16, 'positions via css'); | |
92 }, next); | |
93 }, | |
94 // manual positioned overlay | |
95 function(next) { | |
96 overlay.style.left = overlay.style.top = 'auto'; | |
97 overlay.style.right = '0px'; | |
98 testWhenOpen(overlay, function() { | |
99 var rect = overlay.getBoundingClientRect(); | |
100 chai.assert.equal(rect.right, window.innerWidth - 16, 'positioned manu
ally'); | |
101 chai.assert.ok(Math.abs(rect.top - (window.innerHeight - rect.bottom))
<= 16, 'overlay centered vertically'); | |
102 }, next); | |
103 }, | |
104 // overflow, position top, left | |
105 function(next) { | |
106 overlay.style.left = overlay.style.top = '0px'; | |
107 overlay.style.right = 'auto'; | |
108 overlay.style.width = overlay.style.height = 'auto'; | |
109 for (var i=0; i<20; i++) { | |
110 overlay.appendChild(template.content.cloneNode(true)); | |
111 } | |
112 testWhenOpen(overlay, function() { | |
113 var rect = overlay.getBoundingClientRect(); | |
114 chai.assert.ok(window.innerWidth >= rect.right, 'overlay constrained t
o window size'); | |
115 chai.assert.ok(window.innerHeight >= rect.bottom, 'overlay constrained
to window size'); | |
116 }, next); | |
117 }, | |
118 // overflow, position, bottom, right | |
119 function(next) { | |
120 overlay.style.right = overlay.style.bottom = '0px'; | |
121 overlay.style.left = overlay.style.top = 'auto'; | |
122 testWhenOpen(overlay, function() { | |
123 var rect = overlay.getBoundingClientRect(); | |
124 chai.assert.ok(window.innerWidth >= rect.right, 'overlay constrained t
o window size'); | |
125 chai.assert.ok(window.innerHeight >= rect.bottom, 'overlay constrained
to window size'); | |
126 }, next); | |
127 }, | |
128 // overflow, unpositioned | |
129 function(next) { | |
130 overlay.style.right = overlay.style.bottom = 'auto'; | |
131 overlay.style.left = overlay.style.top = 'auto'; | |
132 testWhenOpen(overlay, function() { | |
133 var rect = overlay.getBoundingClientRect(); | |
134 chai.assert.ok(window.innerWidth >= rect.right, 'overlay constrained t
o window size'); | |
135 chai.assert.ok(window.innerHeight >= rect.bottom, 'overlay constrained
to window size'); | |
136 }, next); | |
137 }, | |
138 // overflow, unpositioned, layered | |
139 function(next) { | |
140 overlay.layered = true; | |
141 testWhenOpen(overlay, function() { | |
142 var rect = overlay.getBoundingClientRect(); | |
143 chai.assert.ok(window.innerWidth >= rect.right, 'overlay constrained t
o window size'); | |
144 chai.assert.ok(window.innerHeight >= rect.bottom, 'overlay constrained
to window size'); | |
145 }, next); | |
146 }, | |
147 ], done); | |
148 }); | |
149 | |
150 </script> | |
151 | |
152 </body> | |
153 </html> | |
OLD | NEW |