1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<!DOCTYPE HTML>
<!--
-->
<html>
<!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.positioning.AnchoredPosition</title>
<script src="../base.js"></script>
<script>
goog.require('goog.dom');
goog.require('goog.positioning.AnchoredPosition');
goog.require('goog.style');
goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<!-- Use IFRAME to avoid non-deterministic window size problems in Selenium. -->
<iframe id="frame1" style="width:200px; height:200px;"
src="anchoredviewportposition_test_iframe.html">
</iframe>
<script>
var frame, doc, dom, viewportSize, anchor, popup;
var corner = goog.positioning.Corner;
var popupLength = 20;
var anchorLength = 100;
function setUp() {
frame = document.getElementById('frame1');
doc = goog.dom.getFrameContentDocument(frame);
dom = goog.dom.getDomHelper(doc);
viewportSize = dom.getViewportSize();
anchor = dom.getElement('anchor');
popup = dom.getElement('popup');
goog.style.setSize(popup, popupLength, popupLength);
goog.style.setPosition(popup, popupLength, popupLength);
goog.style.setSize(anchor, anchorLength, anchorLength);
}
// No enough space at the bottom and no overflow adjustment.
function testRepositionWithDefaultOverflow() {
var avp = new goog.positioning.AnchoredPosition(
anchor, corner.BOTTOM_LEFT);
var newTop = viewportSize.height - anchorLength;
goog.style.setPosition(anchor, 50, newTop);
var anchorRect = goog.style.getBounds(anchor);
avp.reposition(popup, corner.TOP_LEFT);
var popupRect = goog.style.getBounds(popup);
assertEquals(anchorRect.top + anchorRect.height, popupRect.top);
}
// No enough space at the bottom and ADJUST_Y overflow adjustment.
function testRepositionWithOverflow() {
var avp = new goog.positioning.AnchoredPosition(
anchor, corner.BOTTOM_LEFT,
goog.positioning.Overflow.ADJUST_Y);
var newTop = viewportSize.height - anchorLength;
goog.style.setPosition(anchor, 50, newTop);
var anchorRect = goog.style.getBounds(anchor);
avp.reposition(popup, corner.TOP_LEFT);
var popupRect = goog.style.getBounds(popup);
assertEquals(anchorRect.top + anchorRect.height,
popupRect.top + popupRect.height);
}
</script>
</body>
</html>
|