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.github.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/CONTRIBUTORS.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/PATENTS.txt
12 <meta charset=
"UTF-8">
13 <title>core-dropdown basic tests
</title>
14 <meta name=
"viewport" content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0">
16 <script src=
"../../webcomponentsjs/webcomponents.js"></script>
17 <script src=
"../../web-component-tester/browser.js"></script>
19 <link href=
"../core-dropdown.html" rel=
"import">
31 <div relative
id=
"trigger1">
33 <core-dropdown id=
"dropdown1">Hello World!
</core-dropdown>
36 <div relative
id=
"trigger2">
38 <core-dropdown id=
"dropdown2" valign=
"bottom">Hello World!
</core-dropdown>
41 <div relative
id=
"trigger3">
43 <core-dropdown id=
"dropdown3" halign=
"right">Hello World!
</core-dropdown>
46 <div relative
id=
"trigger4">
48 <core-dropdown id=
"dropdown4" layered
>Hello World!
</core-dropdown>
51 <div relative
id=
"trigger5">
53 <core-dropdown id=
"dropdown5" layered
valign=
"bottom">Hello World!
</core-dropdown>
56 <div relative
id=
"trigger6">
58 <core-dropdown id=
"dropdown6" layered
halign=
"right">Hello World!
</core-dropdown>
63 function approxEqual(a
, b
) {
64 return assert
.equal(Math
.round(a
), Math
.round(b
));
67 function assertPosition(dropdown
, trigger
) {
68 var dr
= dropdown
.getBoundingClientRect();
69 var tr
= trigger
.getBoundingClientRect();
71 if (dropdown
.halign
=== 'left') {
72 approxEqual(dr
.left
, tr
.left
);
74 approxEqual(dr
.right
, tr
.right
);
77 if (dropdown
.valign
=== 'top') {
78 approxEqual(dr
.top
, tr
.top
);
80 approxEqual(dr
.bottom
, tr
.bottom
);
84 function flushLayoutAndRender(callback
) {
86 document
.body
.offsetTop
;
87 requestAnimationFrame(function() {
93 var d1
= document
.getElementById('dropdown1');
94 var t1
= document
.getElementById('trigger1');
96 var d2
= document
.getElementById('dropdown2');
97 var t2
= document
.getElementById('trigger2');
99 var d3
= document
.getElementById('dropdown3');
100 var t3
= document
.getElementById('trigger3');
102 var d4
= document
.getElementById('dropdown4');
103 var t4
= document
.getElementById('trigger4');
105 var d5
= document
.getElementById('dropdown5');
106 var t5
= document
.getElementById('trigger5');
108 var d6
= document
.getElementById('dropdown6');
109 var t6
= document
.getElementById('trigger6');
111 test('default', function(done
) {
113 flushLayoutAndRender(function() {
114 assertPosition(d1
, t1
);
119 test('bottom alignment', function(done
) {
121 flushLayoutAndRender(function() {
122 assertPosition(d2
, t2
);
127 test('right alignment', function(done
) {
129 flushLayoutAndRender(function() {
130 assertPosition(d3
, t3
);
135 test('layered', function(done
) {
137 flushLayoutAndRender(function() {
138 assertPosition(d4
, t4
);
143 test('layered, bottom alignment', function(done
) {
145 flushLayoutAndRender(function() {
146 assertPosition(d5
, t5
);
151 test('layered, right alignment', function(done
) {
153 flushLayoutAndRender(function() {
154 assertPosition(d6
, t6
);