UNPKG

sku-pg

Version:

Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!

78 lines (68 loc) 2.43 kB
<!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>