Debian Codegraph @

closure-library/closure/goog/positioning/anchoredposition_test.js

raw
1 // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.positioning.AnchoredPositionTest');
16 goog.setTestOnly('goog.positioning.AnchoredPositionTest');
17
18 goog.require('goog.dom');
19 goog.require('goog.positioning.AnchoredPosition');
20 goog.require('goog.positioning.Corner');
21 goog.require('goog.positioning.Overflow');
22 goog.require('goog.style');
23 goog.require('goog.testing.jsunit');
24
25 var frame, doc, dom, viewportSize, anchor, popup;
26 var corner = goog.positioning.Corner;
27 var popupLength = 20;
28 var anchorLength = 100;
29
30 function setUp() {
31 frame = document.getElementById('frame1');
32 doc = goog.dom.getFrameContentDocument(frame);
33 dom = goog.dom.getDomHelper(doc);
34 viewportSize = dom.getViewportSize();
35 anchor = dom.getElement('anchor');
36 popup = dom.getElement('popup');
37 goog.style.setSize(popup, popupLength, popupLength);
38 goog.style.setPosition(popup, popupLength, popupLength);
39 goog.style.setSize(anchor, anchorLength, anchorLength);
40 }
41
42 // No enough space at the bottom and no overflow adjustment.
43 function testRepositionWithDefaultOverflow() {
44 var avp = new goog.positioning.AnchoredPosition(anchor, corner.BOTTOM_LEFT);
45 var newTop = viewportSize.height - anchorLength;
46 goog.style.setPosition(anchor, 50, newTop);
47 var anchorRect = goog.style.getBounds(anchor);
48
49 avp.reposition(popup, corner.TOP_LEFT);
50 var popupRect = goog.style.getBounds(popup);
51 assertEquals(anchorRect.top + anchorRect.height, popupRect.top);
52 }
53
54 // No enough space at the bottom and ADJUST_Y overflow adjustment.
55 function testRepositionWithOverflow() {
56 var avp = new goog.positioning.AnchoredPosition(
57 anchor, corner.BOTTOM_LEFT, goog.positioning.Overflow.ADJUST_Y);
58 var newTop = viewportSize.height - anchorLength;
59 goog.style.setPosition(anchor, 50, newTop);
60 var anchorRect = goog.style.getBounds(anchor);
61
62 avp.reposition(popup, corner.TOP_LEFT);
63 var popupRect = goog.style.getBounds(popup);
64 assertEquals(
65 anchorRect.top + anchorRect.height, popupRect.top + popupRect.height);
66 }