bug 901781: Correct viewport algorithm for marionette and enable visibility tests; r=mdas
authorDavid Burns <dburns@mozilla.com>
Wed, 07 Aug 2013 16:19:59 -0700
changeset 156126 342c800534ab2486f28b110d585da44f2bb26df5
parent 156125 f620fcca5ff17cade1d7c1cab286b2701f0450e6
child 156127 a3788b3195665d35f224b4a297bfa6bc9c9f6e89
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas
bugs901781
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 901781: Correct viewport algorithm for marionette and enable visibility tests; r=mdas
testing/marionette/client/marionette/tests/unit/test_visibility.py
testing/marionette/client/marionette/tests/unit/unit-tests.ini
testing/marionette/client/marionette/www/element_bottom.html
testing/marionette/client/marionette/www/element_left.html
testing/marionette/client/marionette/www/element_right.html
testing/marionette/client/marionette/www/element_top.html
testing/marionette/marionette-listener.js
--- a/testing/marionette/client/marionette/tests/unit/test_visibility.py
+++ b/testing/marionette/client/marionette/tests/unit/test_visibility.py
@@ -75,8 +75,28 @@ class TestVisibility(MarionetteTestCase)
         negative_percent__tranform = self.marionette.find_element("id", 'negative-percentage-transformY')
         self.assertTrue(negative_percent__tranform.is_displayed())
 
     def testShouldSayElementIsInvisibleWhenOverflowXIsHiddenAndOutOfViewport(self):
         test_html = self.marionette.absolute_url("bug814037.html")
         self.marionette.navigate(test_html)
         overflow_x = self.marionette.find_element("id", "assertMe2")
         self.assertFalse(overflow_x.is_displayed())
+
+    def testShouldClickOnELementPartiallyOffLeft(self):
+        test_html = self.marionette.absolute_url("element_left.html")
+        self.marionette.navigate(test_html)
+        self.marionette.find_element('css selector', '.element').click()
+
+    def testShouldClickOnELementPartiallyOffRight(self):
+        test_html = self.marionette.absolute_url("element_right.html")
+        self.marionette.navigate(test_html)
+        self.marionette.find_element('css selector', '.element').click()
+
+    def testShouldClickOnELementPartiallyOffTop(self):
+        test_html = self.marionette.absolute_url("element_top.html")
+        self.marionette.navigate(test_html)
+        self.marionette.find_element('css selector', '.element').click()
+
+    def testShouldClickOnELementPartiallyOffBottom(self):
+        test_html = self.marionette.absolute_url("element_bottom.html")
+        self.marionette.navigate(test_html)
+        self.marionette.find_element('css selector', '.element').click()
--- a/testing/marionette/client/marionette/tests/unit/unit-tests.ini
+++ b/testing/marionette/client/marionette/tests/unit/unit-tests.ini
@@ -71,16 +71,17 @@ browser = false
 [test_simpletest_chrome.js]
 [test_simpletest_timeout.js]
 [test_specialpowers.py]
 [test_switch_frame.py]
 [test_switch_frame_chrome.py]
 b2g = false
 
 [test_switch_remote_frame.py]
+[test_visibility.py]
 
 [test_window_management.py]
 b2g = false
 
 [test_appcache.py]
 [test_screenshot.py]
 [test_cookies.py]
 b2g = false
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/element_bottom.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<style>
+  .element{
+    position: absolute;
+    bottom: -50px;
+    background-color: red;
+    width: 100px;
+    height: 100px;
+  }
+</style>
+<div class='element'></div>
+
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/element_left.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<style>
+  .element {
+    position: absolute;
+    left: -50px;
+    background-color: red;
+    width: 100px;
+    height: 100px;
+  }
+</style>
+<div class='element'></div>
+
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/element_right.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<style>
+  .element{
+    position: absolute;
+    right: -50px;
+    background-color: red;
+    width: 100px;
+    height: 100px;
+  }
+</style>
+<div class='element'></div>
+
new file mode 100644
--- /dev/null
+++ b/testing/marionette/client/marionette/www/element_top.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<style>
+  .element{
+    position: absolute;
+    top: -50px;
+    background-color: red;
+    width: 100px;
+    height: 100px;
+  }
+</style>
+<div class='element'></div>
+
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -656,46 +656,28 @@ function coordinates(target, x, y) {
   }
   let coords = {};
   coords.x = box.left + x;
   coords.y = box.top + y;
   return coords;
 }
 
 /**
- * This function returns if the element is in viewport 
+ * This function returns if the element is in viewport
  */
 function elementInViewport(el) {
   let rect = el.getBoundingClientRect();
-  return  (/* Top left corner is in view */
-           (rect.top >= curFrame.pageYOffset &&
-            rect.top <= (curFrame.pageYOffset + curFrame.innerHeight) &&
-            rect.left >= curFrame.pageXOffset &&
-            rect.left <= (curFrame.pageXOffset + curFrame.innerWidth)) ||
-           /* Top right corner is in view */ 
-           (rect.top >= curFrame.pageYOffset &&
-            rect.top <= (curFrame.pageYOffset + curFrame.innerHeight) &&
-            rect.right >= curFrame.pageXOffset &&
-            rect.right <= (curFrame.pageXOffset + curFrame.innerWidth)) ||
-           /* Bottom right corner is in view */
-           (rect.bottom >= curFrame.pageYOffset &&
-            rect.bottom <= (curFrame.pageYOffset + curFrame.innerHeight)  &&
-            rect.right >= curFrame.pageXOffset &&
-            rect.right <= (curFrame.pageXOffset + curFrame.innerWidth)) ||
-           /* Bottom left corner is in view */
-           (rect.bottom >= curFrame.pageYOffset &&
-            rect.bottom <= (curFrame.pageYOffset + curFrame.innerHeight)  &&
-            rect.left >= curFrame.pageXOffset &&
-            rect.left <= (curFrame.pageXOffset + curFrame.innerWidth)) ||
-           /* Center of the element is in view if element larger than viewport */
-           ((rect.top + (rect.height/2)) <= curFrame.pageYOffset &&
-            (rect.top + (rect.height/2)) >= (curFrame.pageYOffset + curFrame.innerHeight) &&
-            (rect.left + (rect.width/2)) <= curFrame.pageXOffset &&
-            (rect.left + (rect.width/2)) >= (curFrame.pageXOffset + curFrame.innerWidth))
-         );
+  let viewPort = {top: curFrame.pageYOffset,
+                  left: curFrame.pageXOffset,
+                  bottom: (curFrame.pageYOffset + curFrame.innerHeight),
+                  right:(curFrame.pageXOffset + curFrame.innerWidth)};
+  return (viewPort.left <= rect.right + curFrame.pageXOffset &&
+          rect.left + curFrame.pageXOffset <= viewPort.right &&
+          viewPort.top <= rect.bottom + curFrame.pageYOffset &&
+          rect.top + curFrame.pageYOffset <= viewPort.bottom);
 }
 
 /**
  * This function throws the visibility of the element error
  */
 function checkVisible(el) {
   //check if the element is visible
   let visible = utils.isElementDisplayed(el);