Bug 1406505 - Fix element.isInView to use table cells instead of rows. draft
authorHenrik Skupin <mail@hskupin.info>
Wed, 01 Nov 2017 16:33:08 +0100
changeset 690245 d0e5bea2dfbb514c685c8502bf51a298caebc827
parent 690107 2d0c817035a6941f2fabd6e05cd34d08685b0adc
child 690246 aa8d1181a419640f99d1f7433b94a3f079d538db
push id87249
push userbmo:hskupin@gmail.com
push dateWed, 01 Nov 2017 19:29:23 +0000
bugs1406505, 1413493
milestone58.0a1
Bug 1406505 - Fix element.isInView to use table cells instead of rows. As long as bug 1413493 has not been fixed the <tr> nodes will not be part of the element tree. To workaround this problem we could use the first found cell of the given row to check for visibility. MozReview-Commit-ID: 57nuvxYrSMg
testing/marionette/element.js
testing/marionette/harness/marionette_harness/tests/unit/test_click.py
--- a/testing/marionette/element.js
+++ b/testing/marionette/element.js
@@ -890,19 +890,27 @@ element.getContainer = function(el) {
  * @param {Element} el
  *     Element to check if is in view.
  *
  * @return {boolean}
  *     True if <var>el</var> is inside the viewport, or false otherwise.
  */
 element.isInView = function(el) {
   let originalPointerEvents = el.style.pointerEvents;
+
   try {
     el.style.pointerEvents = "auto";
     const tree = element.getPointerInteractablePaintTree(el);
+
+    // Bug 1413493 - <tr> is not part of the returned paint tree yet. As
+    // workaround check the visibility based on the first contained cell.
+    if (el.localName === "tr" && el.cells && el.cells.length > 0) {
+      return tree.includes(el.cells[0]);
+    }
+
     return tree.includes(el);
   } finally {
     el.style.pointerEvents = originalPointerEvents;
   }
 };
 
 /**
  * This function throws the visibility of the element error if the element is
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_click.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_click.py
@@ -249,16 +249,27 @@ class TestClick(TestLegacyClick):
         self.marionette.navigate(inline("""
             <select style="margin-top: 100vh">
               <option>foo</option>
             </select>"""))
         option = self.marionette.find_element(By.TAG_NAME, "option")
         option.click()
         self.assertTrue(option.get_property("selected"))
 
+    def test_table_tr(self):
+        self.marionette.navigate(inline("""
+          <table>
+            <tr><td onclick="window.clicked = true;">
+              foo
+            </td></tr>
+          </table>"""))
+        tr = self.marionette.find_element(By.TAG_NAME, "tr")
+        tr.click()
+        self.assertTrue(self.marionette.execute_script("return window.clicked", sandbox=None))
+
     def test_obscured_element(self):
         self.marionette.navigate(obscured_overlay)
         overlay = self.marionette.find_element(By.ID, "overlay")
         obscured = self.marionette.find_element(By.ID, "obscured")
 
         overlay.click()
         with self.assertRaises(errors.ElementClickInterceptedException):
             obscured.click()