Bug 1317386 - Add test for overlay element after scroll; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 14 Nov 2016 21:12:00 +0000
changeset 441074 8295d047bb0f52027d782e37575c98669f751e33
parent 441073 c879557542fcd0f010fa1c3fc76eece3f33328f0
child 441075 0f3532aaa8ea5cb977ab4f6c76188353937f94d8
push id36351
push userbmo:ato@mozilla.com
push dateFri, 18 Nov 2016 10:30:51 +0000
reviewersautomatedtester
bugs1317386
milestone53.0a1
Bug 1317386 - Add test for overlay element after scroll; r?automatedtester Add a test that checks that `scrollIntoView({block: "end", inline: "nearest"})` works by placing the element at the bottom of the viewport, where the overlay does not cover it. MozReview-Commit-ID: Gzv9n17240G
testing/marionette/harness/marionette/tests/unit/test_click.py
--- a/testing/marionette/harness/marionette/tests/unit/test_click.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_click.py
@@ -1,20 +1,58 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+import urllib
 from unittest import skip
 
 from marionette_driver.by import By
 from marionette_driver.errors import NoSuchElementException, ElementNotVisibleException
 from marionette_driver.wait import Wait
 from marionette import MarionetteTestCase
 
 
+def inline(doc):
+    return "data:text/html;charset=utf-8,{}".format(urllib.quote(doc))
+
+
+# The <a> element in the following HTML is not interactable because it
+# is hidden by an overlay when scrolled into the top of the viewport.
+# It should be interactable when scrolled in at the bottom of the
+# viewport.
+fixed_overlay = inline("""
+<style>
+* { margin: 0; padding: 0; }
+body { height: 300vh }
+div, a { display: block }
+div {
+  background-color: pink;
+  position: fixed;
+  width: 100%;
+  height: 40px;
+  top: 0;
+}
+a {
+  margin-top: 1000px;
+}
+</style>
+
+<div>overlay</div>
+<a href=#>link</a>
+
+<script>
+window.clicked = false;
+
+let link = document.querySelector("a");
+link.addEventListener("click", () => window.clicked = true);
+</script>
+""")
+
+
 class TestLegacyClick(MarionetteTestCase):
     """Uses legacy Selenium element displayedness checks."""
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.delete_session()
         self.marionette.start_session()
 
@@ -41,16 +79,22 @@ class TestLegacyClick(MarionetteTestCase
             self.marionette.find_element(By.ID, 'child').click()
 
     def test_clicking_on_a_multiline_link(self):
         test_html = self.marionette.absolute_url("clicks.html")
         self.marionette.navigate(test_html)
         self.marionette.find_element(By.ID, "overflowLink").click()
         self.wait_for_condition(lambda mn: self.marionette.title == "XHTML Test Page")
 
+    def test_scroll_into_view_near_end(self):
+        self.marionette.navigate(fixed_overlay)
+        link = self.marionette.find_element(By.TAG_NAME, "a")
+        link.click()
+        self.assertTrue(self.marionette.execute_script("return window.clicked", sandbox=None))
+
 
 class TestClick(TestLegacyClick):
     """Uses WebDriver specification compatible element interactability
     checks.
     """
 
     def setUp(self):
         TestLegacyClick.setUp(self)