Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
The Google Closure Library is a collection of JavaScript code
designed for use with the Google Closure JavaScript Compiler.
This non-official distribution was prepared by the ClojureScript
team at http://clojure.org/
// Copyright 2011 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the Licensegg at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Shared unit tests for styles.
*/
goog.provide('goog.style_test');
goog.require('goog.array');
goog.require('goog.color');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.events.BrowserEvent');
goog.require('goog.html.testing');
goog.require('goog.labs.userAgent.util');
goog.require('goog.math.Box');
goog.require('goog.math.Coordinate');
goog.require('goog.math.Rect');
goog.require('goog.math.Size');
goog.require('goog.object');
goog.require('goog.style');
goog.require('goog.testing.ExpectedFailures');
goog.require('goog.testing.MockUserAgent');
goog.require('goog.testing.TestCase');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.userAgent');
goog.require('goog.userAgentTestUtil');
goog.require('goog.userAgentTestUtil.UserAgents');
goog.setTestOnly('goog.style_test');
// IE before version 6 will always be border box in compat mode.
var isBorderBox = goog.dom.isCss1CompatMode() ?
(goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('6')) :
true;
var EPSILON = 2;
var expectedFailures = new goog.testing.ExpectedFailures();
var $ = goog.dom.getElement;
var mockUserAgent;
function setUpPage() {
// TODO(b/25875505): Fix unreported assertions (go/failonunreportedasserts).
goog.testing.TestCase.getActiveTestCase().failOnUnreportedAsserts = false;
var viewportSize = goog.dom.getViewportSize();
// When the window is too short or not wide enough, some tests, especially
// those for off-screen elements, fail. Oddly, the most reliable
// indicator is a width of zero (which is of course erroneous), since
// height sometimes includes a scroll bar. We can make no assumptions on
// window size on the Selenium farm.
if (goog.userAgent.IE && viewportSize.width < 300) {
// Move to origin, since IE won't resize outside the screen.
window.moveTo(0, 0);
window.resizeTo(640, 480);
}
}
function setUp() {
window.scrollTo(0, 0);
goog.userAgentTestUtil.reinitializeUserAgent();
mockUserAgent = new goog.testing.MockUserAgent();
mockUserAgent.install();
}
function tearDown() {
expectedFailures.handleTearDown();
var testVisibleDiv2 = goog.dom.getElement('test-visible2');
testVisibleDiv2.setAttribute('style', '');
goog.dom.removeChildren(testVisibleDiv2);
var testViewport = goog.dom.getElement('test-viewport');
testViewport.setAttribute('style', '');
goog.dom.removeChildren(testViewport);
goog.dispose(mockUserAgent);
// Prevent multiple vendor prefixed mock elements from poisoning the cache.
goog.style.styleNameCache_ = {};
}
function testSetStyle() {
var el = $('span1');
goog.style.setStyle(el, 'textDecoration', 'underline');
assertEquals('Should be underline', 'underline', el.style.textDecoration);
}
function testSetStyleMap() {
var el = $('span6');
var styles =
{'background-color': 'blue', 'font-size': '100px', textAlign: 'center'};
goog.style.setStyle(el, styles);
var answers = {
backgroundColor: 'blue',
fontSize: '100px',
textAlign: 'center'
};
goog.object.forEach(answers, function(value, style) {
assertEquals('Should be ' + value, value, el.style[style]);
});
}
function testSetStyleWithNonCamelizedString() {
var el = $('span5');
goog.style.setStyle(el, 'text-decoration', 'underline');
assertEquals('Should be underline', 'underline', el.style.textDecoration);
}
function testGetStyle() {
var el = goog.dom.getElement('styleTest3');
goog.style.setStyle(el, 'width', '80px');
goog.style.setStyle(el, 'textDecoration', 'underline');
assertEquals('80px', goog.style.getStyle(el, 'width'));
assertEquals('underline', goog.style.getStyle(el, 'textDecoration'));
assertEquals('underline', goog.style.getStyle(el, 'text-decoration'));
// Non set properties are always empty strings.
assertEquals('', goog.style.getStyle(el, 'border'));
}
function testGetStyleMsFilter() {
// Element with -ms-filter style set.
var e = goog.dom.getElement('msFilter');
if (goog.userAgent.IE && goog.userAgent.isDocumentModeOrHigher(8) &&
!goog.userAgent.isDocumentModeOrHigher(10)) {
// Only IE8/9 supports -ms-filter and returns it as value for the "filter"
// property. When in compatibility mode, -ms-filter is not supported
// and IE8 behaves as IE7 so the other case will apply.
assertEquals('alpha(opacity=0)', goog.style.getStyle(e, 'filter'));
} else {
// Any other browser does not support ms-filter so it returns empty string.
assertEquals('', goog.style.getStyle(e, 'filter'));
}
}
function testGetStyleFilter() {
// Element with filter style set.
var e = goog.dom.getElement('filter');
if (goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(10)) {
// Filter supported.
assertEquals('alpha(opacity=0)', goog.style.getStyle(e, 'filter'));
} else {
assertEquals('', goog.style.getStyle(e, 'filter'));
}
}
function testGetComputedStyleMsFilter() {
// Element with -ms-filter style set.
var e = goog.dom.getElement('msFilter');
if (goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(10)) {
if (goog.userAgent.isDocumentModeOrHigher(9)) {
// IE 9 returns the value.
assertEquals(
'alpha(opacity=0)', goog.style.getComputedStyle(e, 'filter'));
} else {
// Older IE always returns empty string for computed styles.
assertEquals('', goog.style.getComputedStyle(e, 'filter'));
}
} else {
// Non IE returns 'none' for filter as it is an SVG property
assertEquals('none', goog.style.getComputedStyle(e, 'filter'));
}
}
function testGetComputedStyleFilter() {
// Element with filter style set.
var e = goog.dom.getElement('filter');
if (goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(10)) {
if (goog.userAgent.isDocumentModeOrHigher(9)) {
// IE 9 returns the value.
assertEquals(
'alpha(opacity=0)', goog.style.getComputedStyle(e, 'filter'));
} else {
// Older IE always returns empty string for computed styles.
assertEquals('', goog.style.getComputedStyle(e, 'filter'));
}
} else {
// Non IE returns 'none' for filter as it is an SVG property
assertEquals('none', goog.style.getComputedStyle(e, 'filter'));
}
}
function testGetComputedBoxSizing() {
if (!goog.userAgent.IE || goog.userAgent.isVersionOrHigher(8)) {
var defaultBoxSizing =
goog.dom.isCss1CompatMode() ? 'content-box' : 'border-box';
var el = goog.dom.getElement('box-sizing-unset');
assertEquals(defaultBoxSizing, goog.style.getComputedBoxSizing(el));
el = goog.dom.getElement('box-sizing-border-box');
assertEquals('border-box', goog.style.getComputedBoxSizing(el));
} else {
// IE7 and below don't support box-sizing.
assertNull(
goog.style.getComputedBoxSizing(
goog.dom.getElement('box-sizing-border-box')));
}
}
function testGetComputedPosition() {
assertEquals(
'position not set', 'static',
goog.style.getComputedPosition($('position-unset')));
assertEquals(
'position:relative in style attribute', 'relative',
goog.style.getComputedPosition($('style-position-relative')));
if (goog.userAgent.IE && !goog.dom.isCss1CompatMode() &&
!goog.userAgent.isVersionOrHigher(10)) {
assertEquals(
'position:fixed in style attribute', 'static',
goog.style.getComputedPosition($('style-position-fixed')));
} else {
assertEquals(
'position:fixed in style attribute', 'fixed',
goog.style.getComputedPosition($('style-position-fixed')));
}
assertEquals(
'position:absolute in css', 'absolute',
goog.style.getComputedPosition($('css-position-absolute')));
}
function testGetComputedOverflowXAndY() {
assertEquals(
'overflow-x:scroll in style attribute', 'scroll',
goog.style.getComputedOverflowX($('style-overflow-scroll')));
assertEquals(
'overflow-y:scroll in style attribute', 'scroll',
goog.style.getComputedOverflowY($('style-overflow-scroll')));
assertEquals(
'overflow-x:hidden in css', 'hidden',
goog.style.getComputedOverflowX($('css-overflow-hidden')));
assertEquals(
'overflow-y:hidden in css', 'hidden',
goog.style.getComputedOverflowY($('css-overflow-hidden')));
}
function testGetComputedZIndex() {
assertEquals(
'z-index:200 in style attribute', '200',
'' + goog.style.getComputedZIndex($('style-z-index-200')));
assertEquals(
'z-index:200 in css', '200',
'' + goog.style.getComputedZIndex($('css-z-index-200')));
}
function testGetComputedTextAlign() {
assertEquals(
'text-align:right in style attribute', 'right',
goog.style.getComputedTextAlign($('style-text-align-right')));
assertEquals(
'text-align:right inherited from parent', 'right',
goog.style.getComputedTextAlign($('style-text-align-right-inner')));
assertEquals(
'text-align:center in css', 'center',
goog.style.getComputedTextAlign($('css-text-align-center')));
}
function testGetComputedCursor() {
assertEquals(
'cursor:move in style attribute', 'move',
goog.style.getComputedCursor($('style-cursor-move')));
assertEquals(
'cursor:move inherited from parent', 'move',
goog.style.getComputedCursor($('style-cursor-move-inner')));
assertEquals(
'cursor:poiner in css', 'pointer',
goog.style.getComputedCursor($('css-cursor-pointer')));
}
function testGetBackgroundColor() {
var dest = $('bgcolorDest');
for (var i = 0; $('bgcolorTest' + i); i++) {
var src = $('bgcolorTest' + i);
var bgColor = goog.style.getBackgroundColor(src);
dest.style.backgroundColor = bgColor;
assertEquals(
'Background colors should be equal', goog.style.getBackgroundColor(src),
goog.style.getBackgroundColor(dest));
try {
// goog.color.parse throws a generic exception if handed input it
// doesn't understand.
var c = goog.color.parse(bgColor);
assertEquals('rgb(255,0,0)', goog.color.hexToRgbStyle(c.hex));
} catch (e) {
// Internet Explorer is unable to parse colors correctly after test 4.
// Other browsers may vary, but all should be able to handle straight
// hex input.
assertFalse('Should be able to parse color "' + bgColor + '"', i < 5);
}
}
}
function testSetPosition() {
var el = $('testEl');
goog.style.setPosition(el, 100, 100);
assertEquals('100px', el.style.left);
assertEquals('100px', el.style.top);
goog.style.setPosition(el, '50px', '25px');
assertEquals('50px', el.style.left);
assertEquals('25px', el.style.top);
goog.style.setPosition(el, '10ex', '25px');
assertEquals('10ex', el.style.left);
assertEquals('25px', el.style.top);
goog.style.setPosition(el, '10%', '25%');
assertEquals('10%', el.style.left);
assertEquals('25%', el.style.top);
// ignores stupid units
goog.style.setPosition(el, 0, 0);
// TODO(user): IE errors if you set these values. Should we make setStyle
// catch these? Or leave it up to the app. Fixing the tests for now.
// goog.style.setPosition(el, '10rainbows', '25rainbows');
assertEquals('0px', el.style.left);
assertEquals('0px', el.style.top);
goog.style.setPosition(el, new goog.math.Coordinate(20, 40));
assertEquals('20px', el.style.left);
assertEquals('40px', el.style.top);
}
function testGetClientPositionAbsPositionElement() {
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '100px';
div.style.top = '200px';
document.body.appendChild(div);
var pos = goog.style.getClientPosition(div);
assertEquals(100, pos.x);
assertEquals(200, pos.y);
}
function testGetClientPositionNestedElements() {
var innerDiv = goog.dom.createDom(goog.dom.TagName.DIV);
innerDiv.style.position = 'relative';
innerDiv.style.left = '-10px';
innerDiv.style.top = '-10px';
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '150px';
div.style.top = '250px';
div.appendChild(innerDiv);
document.body.appendChild(div);
var pos = goog.style.getClientPosition(innerDiv);
assertEquals(140, pos.x);
assertEquals(240, pos.y);
}
function testGetClientPositionOfOffscreenElement() {
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '2000px';
div.style.top = '2000px';
div.style.width = '10px';
div.style.height = '10px';
document.body.appendChild(div);
try {
window.scroll(0, 0);
var pos = goog.style.getClientPosition(div);
assertEquals(2000, pos.x);
assertEquals(2000, pos.y);
// The following tests do not work in Gecko 1.8 and below, due to an
// obscure off-by-one bug in goog.style.getPageOffset. Same for IE.
if (!goog.userAgent.IE &&
!(goog.userAgent.GECKO && !goog.userAgent.isVersionOrHigher('1.9'))) {
window.scroll(1, 1);
var pos = goog.style.getClientPosition(div);
assertEquals(1999, pos.x);
assertRoughlyEquals(1999, pos.y, 0.5);
window.scroll(2, 2);
pos = goog.style.getClientPosition(div);
assertEquals(1998, pos.x);
assertRoughlyEquals(1998, pos.y, 0.5);
window.scroll(100, 100);
pos = goog.style.getClientPosition(div);
assertEquals(1900, pos.x);
assertRoughlyEquals(1900, pos.y, 0.5);
}
} finally {
window.scroll(0, 0);
document.body.removeChild(div);
}
}
function testGetClientPositionOfOrphanElement() {
var orphanElem = document.createElement(goog.dom.TagName.DIV);
var pos = goog.style.getClientPosition(orphanElem);
assertEquals(0, pos.x);
assertEquals(0, pos.y);
}
function testGetClientPositionEvent() {
var mockEvent = {};
mockEvent.clientX = 100;
mockEvent.clientY = 200;
var pos = goog.style.getClientPosition(mockEvent);
assertEquals(100, pos.x);
assertEquals(200, pos.y);
}
function testGetClientPositionTouchEvent() {
var mockTouchEvent = {};
mockTouchEvent.changedTouches = [{}];
mockTouchEvent.changedTouches[0].clientX = 100;
mockTouchEvent.changedTouches[0].clientY = 200;
var pos = goog.style.getClientPosition(mockTouchEvent);
assertEquals(100, pos.x);
assertEquals(200, pos.y);
}
function testGetClientPositionEmptyTouchList() {
var mockTouchEvent = {};
mockTouchEvent.touches = [];
mockTouchEvent.changedTouches = [{}];
mockTouchEvent.changedTouches[0].clientX = 100;
mockTouchEvent.changedTouches[0].clientY = 200;
var pos = goog.style.getClientPosition(mockTouchEvent);
assertEquals(100, pos.x);
assertEquals(200, pos.y);
}
function testGetClientPositionAbstractedTouchEvent() {
var mockTouchEvent = {};
mockTouchEvent.changedTouches = [{}];
mockTouchEvent.changedTouches[0].clientX = 100;
mockTouchEvent.changedTouches[0].clientY = 200;
var e = new goog.events.BrowserEvent(mockTouchEvent);
var pos = goog.style.getClientPosition(e);
assertEquals(100, pos.x);
assertEquals(200, pos.y);
}
function testGetPageOffsetAbsPositionedElement() {
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '100px';
div.style.top = '200px';
document.body.appendChild(div);
var pos = goog.style.getPageOffset(div);
assertEquals(100, pos.x);
assertEquals(200, pos.y);
}
function testGetPageOffsetNestedElements() {
var innerDiv = goog.dom.createDom(goog.dom.TagName.DIV);
innerDiv.style.position = 'relative';
innerDiv.style.left = '-10px';
innerDiv.style.top = '-10px';
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '150px';
div.style.top = '250px';
div.appendChild(innerDiv);
document.body.appendChild(div);
var pos = goog.style.getPageOffset(innerDiv);
assertRoughlyEquals(140, pos.x, 0.1);
assertRoughlyEquals(240, pos.y, 0.1);
}
function testGetPageOffsetWithBodyPadding() {
document.body.style.margin = '40px';
document.body.style.padding = '60px';
document.body.style.borderWidth = '70px';
try {
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '100px';
div.style.top = '200px';
// Margin will affect position, but padding and borders should not.
div.style.margin = '1px';
div.style.padding = '2px';
div.style.borderWidth = '3px';
document.body.appendChild(div);
var pos = goog.style.getPageOffset(div);
assertRoughlyEquals(101, pos.x, 0.1);
assertRoughlyEquals(201, pos.y, 0.1);
} finally {
document.body.removeChild(div);
document.body.style.margin = '';
document.body.style.padding = '';
document.body.style.borderWidth = '';
}
}
function testGetPageOffsetWithDocumentElementPadding() {
document.documentElement.style.margin = '40px';
document.documentElement.style.padding = '60px';
document.documentElement.style.borderWidth = '70px';
try {
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '100px';
div.style.top = '200px';
// Margin will affect position, but padding and borders should not.
div.style.margin = '1px';
div.style.padding = '2px';
div.style.borderWidth = '3px';
document.body.appendChild(div);
var pos = goog.style.getPageOffset(div);
// FF3 (but not beyond) gets confused by document margins.
if (goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9') &&
!goog.userAgent.isVersionOrHigher('1.9.1')) {
assertEquals(141, pos.x);
assertEquals(241, pos.y);
} else {
assertRoughlyEquals(101, pos.x, 0.1);
assertRoughlyEquals(201, pos.y, 0.1);
}
} finally {
document.body.removeChild(div);
document.documentElement.style.margin = '';
document.documentElement.style.padding = '';
document.documentElement.style.borderWidth = '';
}
}
function testGetPageOffsetElementOffscreen() {
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '10000px';
div.style.top = '20000px';
document.body.appendChild(div);
window.scroll(0, 0);
try {
var pos = goog.style.getPageOffset(div);
assertEquals(10000, pos.x);
assertEquals(20000, pos.y);
// The following tests do not work in Gecko 1.8 and below, due to an
// obscure off-by-one bug in goog.style.getPageOffset. Same for IE.
if (!(goog.userAgent.IE) &&
!(goog.userAgent.GECKO && !goog.userAgent.isVersionOrHigher('1.9'))) {
window.scroll(1, 1);
pos = goog.style.getPageOffset(div);
assertEquals(10000, pos.x);
assertRoughlyEquals(20000, pos.y, 0.5);
window.scroll(1000, 2000);
pos = goog.style.getPageOffset(div);
assertEquals(10000, pos.x);
assertRoughlyEquals(20000, pos.y, 1);
window.scroll(10000, 20000);
pos = goog.style.getPageOffset(div);
assertEquals(10000, pos.x);
assertRoughlyEquals(20000, pos.y, 1);
}
}
// Undo changes.
finally {
document.body.removeChild(div);
window.scroll(0, 0);
}
}
function testGetPageOffsetFixedPositionElements() {
// Skip these tests in certain browsers.
// position:fixed is not supported in IE before version 7
if (!goog.userAgent.IE || !goog.userAgent.isVersionOrHigher('6')) {
// Test with a position fixed element
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'fixed';
div.style.top = '10px';
div.style.left = '10px';
document.body.appendChild(div);
var pos = goog.style.getPageOffset(div);
assertEquals(10, pos.x);
assertEquals(10, pos.y);
// Test with a position fixed element as parent
var innerDiv = goog.dom.createDom(goog.dom.TagName.DIV);
div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'fixed';
div.style.top = '10px';
div.style.left = '10px';
div.style.padding = '5px';
div.appendChild(innerDiv);
document.body.appendChild(div);
pos = goog.style.getPageOffset(innerDiv);
assertEquals(15, pos.x);
assertEquals(15, pos.y);
}
}
function testGetPositionTolerantToNoDocumentElementBorder() {
// In IE, removing the border on the document element undoes the normal
// 2-pixel offset. Ensure that we're correctly compensating for both cases.
try {
document.documentElement.style.borderWidth = '0';
var div = goog.dom.createDom(goog.dom.TagName.DIV);
div.style.position = 'absolute';
div.style.left = '100px';
div.style.top = '200px';
document.body.appendChild(div);
// Test all major positioning methods.
// Disabled for IE9 and below - IE8 returns dimensions multiplied by 100.
// IE9 is flaky. See b/22873770.
expectedFailures.expectFailureFor(
goog.userAgent.IE && !goog.userAgent.isVersionOrHigher(10));
try {
// Test all major positioning methods.
var pos = goog.style.getClientPosition(div);
assertEquals(100, pos.x);
assertRoughlyEquals(200, pos.y, .1);
var offset = goog.style.getPageOffset(div);
assertEquals(100, offset.x);
assertRoughlyEquals(200, offset.y, .1);
} catch (e) {
expectedFailures.handleException(e);
}
} finally {
document.documentElement.style.borderWidth = '';
}
}
function testSetSize() {
var el = $('testEl');
goog.style.setSize(el, 100, 100);
assertEquals('100px', el.style.width);
assertEquals('100px', el.style.height);
goog.style.setSize(el, '50px', '25px');
assertEquals('should be "50px"', '50px', el.style.width);
assertEquals('should be "25px"', '25px', el.style.height);
goog.style.setSize(el, '10ex', '25px');
assertEquals('10ex', el.style.width);
assertEquals('25px', el.style.height);
goog.style.setSize(el, '10%', '25%');
assertEquals('10%', el.style.width);
assertEquals('25%', el.style.height);
// ignores stupid units
goog.style.setSize(el, 0, 0);
// TODO(user): IE errors if you set these values. Should we make setStyle
// catch these? Or leave it up to the app. Fixing the tests for now.
// goog.style.setSize(el, '10rainbows', '25rainbows');
assertEquals('0px', el.style.width);
assertEquals('0px', el.style.height);
goog.style.setSize(el, new goog.math.Size(20, 40));
assertEquals('20px', el.style.width);
assertEquals('40px', el.style.height);
}
function testSetWidthAndHeight() {
var el = $('testEl');
// Replicate all of the setSize tests above.
goog.style.setWidth(el, 100);
goog.style.setHeight(el, 100);
assertEquals('100px', el.style.width);
assertEquals('100px', el.style.height);
goog.style.setWidth(el, '50px');
goog.style.setHeight(el, '25px');
assertEquals('should be "50px"', '50px', el.style.width);
assertEquals('should be "25px"', '25px', el.style.height);
goog.style.setWidth(el, '10ex');
goog.style.setHeight(el, '25px');
assertEquals('10ex', el.style.width);
assertEquals('25px', el.style.height);
goog.style.setWidth(el, '10%');
goog.style.setHeight(el, '25%');
assertEquals('10%', el.style.width);
assertEquals('25%', el.style.height);
goog.style.setWidth(el, 0);
goog.style.setHeight(el, 0);
assertEquals('0px', el.style.width);
assertEquals('0px', el.style.height);
goog.style.setWidth(el, 20);
goog.style.setHeight(el, 40);
assertEquals('20px', el.style.width);
assertEquals('40px', el.style.height);
// Additional tests testing each separately.
goog.style.setWidth(el, '');
goog.style.setHeight(el, '');
assertEquals('', el.style.width);
assertEquals('', el.style.height);
goog.style.setHeight(el, 20);
assertEquals('', el.style.width);
assertEquals('20px', el.style.height);
goog.style.setWidth(el, 40);
assertEquals('40px', el.style.width);
assertEquals('20px', el.style.height);
}
function testGetSize() {
var el = $('testEl');
goog.style.setSize(el, 100, 100);
var dims = goog.style.getSize(el);
assertEquals(100, dims.width);
assertEquals(100, dims.height);
goog.style.setStyle(el, 'display', 'none');
dims = goog.style.getSize(el);
assertEquals(100, dims.width);
assertEquals(100, dims.height);
el = $('testEl5');
goog.style.setSize(el, 100, 100);
dims = goog.style.getSize(el);
assertEquals(100, dims.width);
assertEquals(100, dims.height);
el = $('span0');
dims = goog.style.getSize(el);
assertNotEquals(0, dims.width);
assertNotEquals(0, dims.height);
el = $('table1');
dims = goog.style.getSize(el);
assertNotEquals(0, dims.width);
assertNotEquals(0, dims.height);
el = $('td1');
dims = goog.style.getSize(el);
assertNotEquals(0, dims.width);
assertNotEquals(0, dims.height);
el = $('li1');
dims = goog.style.getSize(el);
assertNotEquals(0, dims.width);
assertNotEquals(0, dims.height);
el = goog.dom.getElementsByTagNameAndClass(goog.dom.TagName.HTML)[0];
dims = goog.style.getSize(el);
assertNotEquals(0, dims.width);
assertNotEquals(0, dims.height);
el = goog.dom.getElementsByTagNameAndClass(goog.dom.TagName.BODY)[0];
dims = goog.style.getSize(el);
assertNotEquals(0, dims.width);
assertNotEquals(0, dims.height);
}
function testGetSizeSvgElements() {
var svgEl = document.createElementNS &&
document.createElementNS('http://www.w3.org/2000/svg', 'svg');
if (!svgEl || svgEl.getAttribute('transform') == '' ||
(goog.userAgent.WEBKIT && !goog.userAgent.isVersionOrHigher(534.8))) {
// SVG not supported, or getBoundingClientRect not supported on SVG
// elements.
return;
}
document.body.appendChild(svgEl);
var el = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
el.setAttribute('x', 10);
el.setAttribute('y', 10);
el.setAttribute('width', 32);
el.setAttribute('height', 21);
el.setAttribute('fill', '#000');
svgEl.appendChild(el);
// The bounding size in 1 larger than the SVG element in IE.
var expectedWidth = (goog.userAgent.EDGE_OR_IE) ? 33 : 32;
var expectedHeight = (goog.userAgent.EDGE_OR_IE) ? 22 : 21;
var dims = goog.style.getSize(el);
assertEquals(expectedWidth, dims.width);
assertRoughlyEquals(expectedHeight, dims.height, 0.01);
dims = goog.style.getSize(svgEl);
// The size of the