bug 901781: Correct viewport algorithm for marionette and enable visibility tests; r=mdas

This commit is contained in:
David Burns 2013-08-07 16:19:59 -07:00
parent 31a96200a5
commit ae1425f9d3
7 changed files with 78 additions and 27 deletions

View File

@ -80,3 +80,23 @@ class TestVisibility(MarionetteTestCase):
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()

View File

@ -76,6 +76,7 @@ browser = false
b2g = false
[test_switch_remote_frame.py]
[test_visibility.py]
[test_window_management.py]
b2g = false

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<style>
.element{
position: absolute;
bottom: -50px;
background-color: red;
width: 100px;
height: 100px;
}
</style>
<div class='element'></div>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<style>
.element {
position: absolute;
left: -50px;
background-color: red;
width: 100px;
height: 100px;
}
</style>
<div class='element'></div>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<style>
.element{
position: absolute;
right: -50px;
background-color: red;
width: 100px;
height: 100px;
}
</style>
<div class='element'></div>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<style>
.element{
position: absolute;
top: -50px;
background-color: red;
width: 100px;
height: 100px;
}
</style>
<div class='element'></div>

View File

@ -661,36 +661,18 @@ function coordinates(target, x, y) {
}
/**
* 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);
}
/**