Bug 575808 - Fix broken tests in browser_click_content.js [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Wed, 30 Jun 2010 10:00:34 -0400
changeset 66335 072cd39f0c4d4ad6db83df9c58861df13ddb5066
parent 66334 57099eff2390c77355d30e25d4d5b1a6f707fcea
child 66336 23da913d66fa8ec4fabdd26b90e9704a01539ad9
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs575808
Bug 575808 - Fix broken tests in browser_click_content.js [r=mfinkle]
mobile/chrome/tests/browser_click_content.js
--- a/mobile/chrome/tests/browser_click_content.js
+++ b/mobile/chrome/tests/browser_click_content.js
@@ -47,47 +47,69 @@ function checkClick() {
   ok(isClickFired, "Click handler fired");
   element.removeEventListener("click", clickFired, true);
 
   // Check position
   isClickFired = false;
   element = newTab.browser.contentDocument.documentElement;
   element.addEventListener("click", clickFired, true);
 
-  finish(); // XXX Browser.getBoundingContentRect not available.
-
-  let rect = Browser.getBoundingContentRect(element);
+  let rect = getBoundingContentRect(element);
   EventUtils.synthesizeMouse(element, 1, rect.height + 10, {}, window);
   waitFor(checkPosition, function() { return isClickFired });
 }
 
 function checkPosition() {
   element.removeEventListener("click", clickFired, true);
 
-  let rect = Browser.getBoundingContentRect(element);
+  let rect = getBoundingContentRect(element);
   is(clickPosition.x, 1, "X position is correct");
   is(clickPosition.y, rect.height + 10, "Y position is correct");
 
   checkThickBorder();
 }
 
 function checkThickBorder() {
   let frame = newTab.browser.contentDocument.getElementById("iframe-2");
   let element = frame.contentDocument.getElementsByTagName("input")[0];
 
-  let frameRect = Browser.getBoundingContentRect(frame);
+  let frameRect = getBoundingContentRect(frame);
   let frameLeftBorder = window.getComputedStyle(frame, "").borderLeftWidth;
   let frameTopBorder = window.getComputedStyle(frame, "").borderTopWidth;
 
-  let elementRect = Browser.getBoundingContentRect(element);
+  let elementRect = getBoundingContentRect(element);
   ok((frameRect.left + parseInt(frameLeftBorder)) < elementRect.left, "X position of nested element ok");
   ok((frameRect.top + parseInt(frameTopBorder)) < elementRect.top, "Y position of nested element ok");
 
   close();
 }
 
 function close() {
   // Close the tab
   Browser.closeTab(newTab);
 
   // We must finialize the tests
   finish();
 }
+
+// XXX copied from chrome/content/content.js
+function getBoundingContentRect(aElement) {
+  if (!aElement)
+    return new Rect(0, 0, 0, 0);
+
+  let document = aElement.ownerDocument;
+  while(document.defaultView.frameElement)
+    document = document.defaultView.frameElement.ownerDocument;
+
+  let offset = Util.getScrollOffset(content);
+  let r = aElement.getBoundingClientRect();
+
+  // step out of iframes and frames, offsetting scroll values
+  for (let frame = aElement.ownerDocument.defaultView; frame != content; frame = frame.parent) {
+    // adjust client coordinates' origin to be top left of iframe viewport
+    let rect = frame.frameElement.getBoundingClientRect();
+    let left = frame.getComputedStyle(frame.frameElement, "").borderLeftWidth;
+    let top = frame.getComputedStyle(frame.frameElement, "").borderTopWidth;
+    offset.add(rect.left + parseInt(left), rect.top + parseInt(top));
+  }
+
+  return new Rect(r.left + offset.x, r.top + offset.y, r.width, r.height);
+}