12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- goog.provide('goog.styleScrollbarTester');
- goog.require('goog.dom');
- goog.require('goog.dom.TagName');
- goog.require('goog.style');
- goog.require('goog.testing.asserts');
- goog.setTestOnly('goog.styleScrollbarTester');
- function testScrollbarWidth() {
- var width = goog.style.getScrollbarWidth();
- assertTrue(width > 0);
- var outer = goog.dom.getElement('test-scrollbarwidth');
- var inner = goog.dom.getElementsByTagNameAndClass(
- goog.dom.TagName.DIV, null, outer)[0];
- assertTrue('should have a scroll bar', hasVerticalScroll(outer));
- assertTrue('should have a scroll bar', hasHorizontalScroll(outer));
-
- goog.style.setStyle(outer, 'width', '100%');
- assertTrue('should have a scroll bar', hasVerticalScroll(outer));
- assertFalse('should not have a scroll bar', hasHorizontalScroll(outer));
- var innerAbsoluteWidth = inner.offsetWidth;
-
-
- goog.style.setStyle(outer, 'width', (innerAbsoluteWidth + width) + 'px');
- assertTrue('should have a scroll bar', hasVerticalScroll(outer));
- assertFalse('should not have a scroll bar', hasHorizontalScroll(outer));
-
- goog.style.setStyle(outer, 'width', (innerAbsoluteWidth + width - 1) + 'px');
- assertTrue('should have a scroll bar', hasVerticalScroll(outer));
- assertTrue('should have a scroll bar', hasHorizontalScroll(outer));
- }
- function hasVerticalScroll(el) {
- return el.clientWidth != 0 && el.offsetWidth - el.clientWidth > 0;
- }
- function hasHorizontalScroll(el) {
- return el.clientHeight != 0 && el.offsetHeight - el.clientHeight > 0;
- }
|