Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

goog.dom.getDocumentScroll unit test + fix for iOS 4

Contributed by Andrew Mattie.

Revision created by MOE tool push_codebase.

R=arv
DELTA=75  (54 added, 2 deleted, 19 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=672


git-svn-id: http://closure-library.googlecode.com/svn/trunk@724 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
commit a80b72b0af586745ee99f08b675b18f8a8521676 1 parent 1ff21ba
nicksantos@google.com authored
View
1  AUTHORS
@@ -8,5 +8,6 @@ Mohamed Mansour <hello@mohamedmansour.com>
Bjorn Tipling <bjorn.tipling@gmail.com>
SameGoal LLC <help@samegoal.com>
Guido Tapia <guido.tapia@gmail.com>
+Andrew Mattie <amattie@gmail.com>
Ilia Mirkin <ibmirkin@gmail.com>
Ivan Kozik <ivan.kozik@gmail.com>
View
2  closure/goog/deps.js
@@ -191,7 +191,7 @@ goog.addDependency('fx/dom.js', ['goog.fx.dom', 'goog.fx.dom.BgColorTransform',
goog.addDependency('fx/dragdrop.js', ['goog.fx.DragDrop'], ['goog.fx.AbstractDragDrop', 'goog.fx.DragDropItem']);
goog.addDependency('fx/dragdropgroup.js', ['goog.fx.DragDropGroup'], ['goog.dom', 'goog.fx.AbstractDragDrop', 'goog.fx.DragDropItem']);
goog.addDependency('fx/dragger.js', ['goog.fx.DragEvent', 'goog.fx.Dragger', 'goog.fx.Dragger.EventType'], ['goog.dom', 'goog.events', 'goog.events.BrowserEvent.MouseButton', 'goog.events.Event', 'goog.events.EventHandler', 'goog.events.EventTarget', 'goog.events.EventType', 'goog.math.Coordinate', 'goog.math.Rect', 'goog.userAgent']);
-goog.addDependency('fx/draglistgroup.js', ['goog.fx.DragListDirection', 'goog.fx.DragListGroup', 'goog.fx.DragListGroup.EventType', 'goog.fx.DragListGroupEvent'], ['goog.asserts', 'goog.dom', 'goog.dom.NodeType', 'goog.dom.classes', 'goog.events.Event', 'goog.events.EventHandler', 'goog.events.EventTarget', 'goog.events.EventType', 'goog.fx.Dragger', 'goog.fx.Dragger.EventType', 'goog.math.Coordinate', 'goog.style']);
+goog.addDependency('fx/draglistgroup.js', ['goog.fx.DragListDirection', 'goog.fx.DragListGroup', 'goog.fx.DragListGroup.EventType', 'goog.fx.DragListGroupEvent'], ['goog.dom', 'goog.dom.NodeType', 'goog.dom.classes', 'goog.events.Event', 'goog.events.EventHandler', 'goog.events.EventTarget', 'goog.events.EventType', 'goog.fx.Dragger', 'goog.fx.Dragger.EventType', 'goog.math.Coordinate', 'goog.style']);
goog.addDependency('fx/dragscrollsupport.js', ['goog.fx.DragScrollSupport'], ['goog.Disposable', 'goog.Timer', 'goog.dom', 'goog.events.EventHandler', 'goog.events.EventType', 'goog.math.Coordinate', 'goog.style']);
goog.addDependency('fx/easing.js', ['goog.fx.easing'], []);
goog.addDependency('fx/fx.js', ['goog.fx'], ['goog.asserts', 'goog.fx.Animation', 'goog.fx.Animation.EventType', 'goog.fx.Animation.State', 'goog.fx.AnimationEvent', 'goog.fx.easing']);
View
4 closure/goog/dom/dom.js
@@ -562,7 +562,9 @@ goog.dom.getDocumentScroll = function() {
*/
goog.dom.getDocumentScroll_ = function(doc) {
var el = goog.dom.getDocumentScrollElement_(doc);
- return new goog.math.Coordinate(el.scrollLeft, el.scrollTop);
+ var win = goog.dom.getWindow_(doc);
+ return new goog.math.Coordinate(win.pageXOffset || el.scrollLeft,
+ win.pageYOffset || el.scrollTop);
};
View
78 closure/goog/dom/dom_test.js
@@ -27,23 +27,46 @@ goog.require('goog.userAgent');
goog.require('goog.userAgent.product');
goog.require('goog.userAgent.product.isVersion');
+goog.setTestOnly('dom_test');
+
var $ = goog.dom.getElement;
-// Setup for the iframe
-var myIframe = $('myIframe');
-var myIframeDoc = goog.dom.getFrameContentDocument(
- /** @type {HTMLIFrameElement} */ (myIframe));
-
-// Set up document for iframe: total height of elements in document is 65
-// If the elements are not create like below, IE will get a wrong height for
-// the document.
-myIframeDoc.open();
-// Make sure we progate the compat mode
-myIframeDoc.write((goog.dom.isCss1CompatMode() ? '<!DOCTYPE html>' : '') +
- '<style>body{margin:0;padding:0}</style>' +
- '<div style="height:42px;font-size:1px;line-height:0;">hello world</div>' +
- '<div style="height:23px;font-size:1px;line-height:0;">hello world</div>');
-myIframeDoc.close();
+var divForTestingScrolling;
+var myIframe;
+var myIframeDoc;
+
+function setUpPage() {
+ divForTestingScrolling = document.createElement('div');
+ divForTestingScrolling.style.width = '5000px';
+ divForTestingScrolling.style.height = '5000px';
+ document.body.appendChild(divForTestingScrolling);
+
+ // Setup for the iframe
+ myIframe = $('myIframe');
+ myIframeDoc = goog.dom.getFrameContentDocument(
+ /** @type {HTMLIFrameElement} */ (myIframe));
+
+ // Set up document for iframe: total height of elements in document is 65
+ // If the elements are not create like below, IE will get a wrong height for
+ // the document.
+ myIframeDoc.open();
+ // Make sure we progate the compat mode
+ myIframeDoc.write((goog.dom.isCss1CompatMode() ? '<!DOCTYPE html>' : '') +
+ '<style>body{margin:0;padding:0}</style>' +
+ '<div style="height:42px;font-size:1px;line-height:0;">' +
+ 'hello world</div>' +
+ '<div style="height:23px;font-size:1px;line-height:0;">' +
+ 'hello world</div>');
+ myIframeDoc.close();
+}
+
+function tearDownPage() {
+ document.body.removeChild(divForTestingScrolling);
+}
+
+function tearDown() {
+ window.scrollTo(0, 0);
+}
function testDom() {
assert('Dom library exists', typeof goog.dom != 'undefined');
@@ -1137,6 +1160,31 @@ function testAppend4() {
assertFalse(div2.hasChildNodes());
}
+function testGetDocumentScroll() {
+ // setUpPage added divForTestingScrolling to the DOM. It's not init'd here so
+ // it can be shared amonst other tests.
+ window.scrollTo(100, 100);
+
+ assertEquals(100, goog.dom.getDocumentScroll().x);
+ assertEquals(100, goog.dom.getDocumentScroll().y);
+}
+
+function testGetDocumentScrollOfFixedViewport() {
+ // iOS and perhaps other environments don't actually support scrolling.
+ // Instead, you view the document's fixed layout through a screen viewport.
+ // We need getDocumentScroll to handle this case though.
+ var fakeDocumentScrollElement = {scrollLeft: 0, scrollTop: 0};
+ var fakeDocument = {
+ defaultView: {pageXOffset: 100, pageYOffset: 100},
+ documentElement: fakeDocumentScrollElement,
+ body: fakeDocumentScrollElement
+ };
+ var dh = goog.dom.getDomHelper(document);
+ dh.setDocument(fakeDocument);
+ assertEquals(100, dh.getDocumentScroll().x);
+ assertEquals(100, dh.getDocumentScroll().y);
+}
+
/**
* @return {boolean} Returns true if the userAgent is IE8.
View
1  closure/goog/editor/seamlessfield_test.js
@@ -31,6 +31,7 @@ goog.require('goog.testing.MockClock');
goog.require('goog.testing.MockRange');
goog.require('goog.testing.jsunit');
+goog.setTestOnly('seamlessfield_test');
var fieldElem;
var fieldElemClone;
Please sign in to comment.
Something went wrong with that request. Please try again.