summaryrefslogtreecommitdiffstats
path: root/testing/marionette/harness/marionette_harness/tests/unit/test_click_scrolling.py
blob: 437c15e702b0733d02978e72507d9f028cef2bf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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/.

from marionette_driver.by import By
from marionette_driver.errors import MoveTargetOutOfBoundsException

from marionette_harness import MarionetteTestCase, skip, skip_if_mobile


class TestClickScrolling(MarionetteTestCase):


    def test_clicking_on_anchor_scrolls_page(self):
        scrollScript = """
            var pageY;
            if (typeof(window.pageYOffset) == 'number') {
                pageY = window.pageYOffset;
            } else {
                pageY = document.documentElement.scrollTop;
            }
            return pageY;"""

        test_html = self.marionette.absolute_url("macbeth.html")
        self.marionette.navigate(test_html)

        self.marionette.find_element(By.PARTIAL_LINK_TEXT, "last speech").click()
        y_offset = self.marionette.execute_script(scrollScript)

        # Focusing on to click, but not actually following,
        # the link will scroll it in to view, which is a few
        # pixels further than 0

        self.assertTrue(y_offset > 300)

    def test_should_scroll_to_click_on_an_element_hidden_by_overflow(self):
        test_html = self.marionette.absolute_url("click_out_of_bounds_overflow.html")
        self.marionette.navigate(test_html)

        link = self.marionette.find_element(By.ID, "link")
        try:
            link.click()
        except MoveTargetOutOfBoundsException:
            self.fail("Should not be out of bounds")

    @skip("Bug 1200197 - Cannot interact with elements hidden inside overflow:scroll")
    def test_should_be_able_to_click_on_an_element_hidden_by_overflow(self):
        test_html = self.marionette.absolute_url("scroll.html")
        self.marionette.navigate(test_html)

        link = self.marionette.find_element(By.ID, "line8")
        link.click()
        self.assertEqual("line8", self.marionette.find_element(By.ID, "clicked").text)

    def test_should_not_scroll_overflow_elements_which_are_visible(self):
        test_html = self.marionette.absolute_url("scroll2.html")
        self.marionette.navigate(test_html)

        list_el = self.marionette.find_element(By.TAG_NAME, "ul")
        item = list_el.find_element(By.ID, "desired")
        item.click()
        y_offset = self.marionette.execute_script("return arguments[0].scrollTop;", script_args=[list_el])
        self.assertEqual(0, y_offset)

    def test_should_not_scroll_if_already_scrolled_and_element_is_in_view(self):
        test_html = self.marionette.absolute_url("scroll3.html")
        self.marionette.navigate(test_html)

        button1 = self.marionette.find_element(By.ID, "button1")
        button2 = self.marionette.find_element(By.ID, "button2")

        button2.click()
        scroll_top = self.marionette.execute_script("return document.body.scrollTop;")
        button1.click()

        self.assertEqual(scroll_top, self.marionette.execute_script("return document.body.scrollTop;"))

    def test_should_be_able_to_click_radio_button_scrolled_into_view(self):
        test_html = self.marionette.absolute_url("scroll4.html")
        self.marionette.navigate(test_html)

        # If we dont throw we are good
        self.marionette.find_element(By.ID, "radio").click()

    def test_should_scroll_elements_if_click_point_is_out_of_view_but_element_is_in_view(self):
        test_html = self.marionette.absolute_url("element_outside_viewport.html")

        for s in ["top", "bottom"]:
            self.marionette.navigate(test_html)
            scroll_y = self.marionette.execute_script("return window.scrollY;")
            self.marionette.find_element(By.ID, "{}-70".format(s)).click()
            self.assertNotEqual(scroll_y, self.marionette.execute_script("return window.scrollY;"))

        for s in ["left", "right"]:
            self.marionette.navigate(test_html)
            scroll_x = self.marionette.execute_script("return window.scrollX;")
            self.marionette.find_element(By.ID, "{}-70".format(s)).click()
            self.assertNotEqual(scroll_x, self.marionette.execute_script("return window.scrollX;"))

    @skip_if_mobile("Bug 1293855 - Lists differ: [70, 70] != [70, 120]")
    def test_should_not_scroll_elements_if_click_point_is_in_view(self):
        test_html = self.marionette.absolute_url("element_outside_viewport.html")

        for s in ["top", "right", "bottom", "left"]:
            for p in ["50", "30"]:
                self.marionette.navigate(test_html)
                scroll = self.marionette.execute_script("return [window.scrollX, window.scrollY];")
                self.marionette.find_element(By.ID, "{0}-{1}".format(s, p)).click()
                self.assertEqual(scroll, self.marionette.execute_script("return [window.scrollX, window.scrollY];"))

    @skip("Bug 1003687")
    def test_should_scroll_overflow_elements_if_click_point_is_out_of_view_but_element_is_in_view(self):
        test_html = self.marionette.absolute_url("scroll5.html")
        self.marionette.navigate(test_html)

        self.marionette.find_element(By.ID, "inner").click()
        self.assertEqual("clicked", self.marionette.find_element(By.ID, "clicked").text)